- I created the main loop for the megaphone module.
- I coded up the interface functions for the megaphone module.
- I coded up the get_data function
put_data(State, ConnectionID, Data) ->
NewState = update_table(State, ConnectionID, Data),
case get_waiter_for(ConnectionID, State) of
undefined ->
NewState;
PID ->
notify_waiter(PID, ConnectionID, State)
end.
Here is the code for update_table:
update_table(State, ConnectionID, Data) ->
List = parse_packet(Data),
Table = State#megaphone_main_state.connectionToResults,
Old = dict:fetch(ConnectionID, Table),
NewList = Old ++ List,
NewTable = dict:store(ConnectionID, NewList, Table),
State#megaphone_main_state{connectionToResults = NewTable}.
This function updates the table that maps from connections to data. The table stores a list of results as from erlang:decode_packet. That function expects a different parameter depending on where in the packet one is at. To ensure that the function is always called at the start of an HTTP packet, megaphone_receiver only sends complete packets onto the megaphone process.
Next time, more from the internals of the megaphone module.
Next time, more from the internals of the megaphone module.
No comments:
Post a Comment