As seen i figure 5.1, incoming OLSR data is first handled
by the socket parser. This entity is responsible for listening
for data on a given set of sockets. Sockets and their corresponding
parse functions, are registered with the socket
parser at runtime.
The socket parser uses the familiar select(2) system call
to detect when data is available on any socket in a given set of
sockets. The socket parser functionality is illustrated in figure
6.1.
This modular design allows for multiple entities to listen for multiple types
of data without the need for a program flow, often a thread, of their own.
So whenever an entity wishes to listen for data on a socket, it calls
the function prototyped in socket_parser.h as:
void add_olsr_socket(int, void(*)(int))
Here, the first argument is the socket(file-descriptor) to check for data, and the second argument is the function to call when data is available on the socket. A function is available to remove a registered socket as well:
int remove_olsr_socket(int, void(*)(int))
Sockets can be registered and removed at any time. This makes the socket parser suitable to handle both server- and client-side type connections. If some entity wishes to act as a server for a TCP socket, it would first register its connection listening socket with the socket-parser with a function that handles new connections. Whenever a new connection is initiated, the function will register the new socket with the socket parser. If the connection is lost, the entity removes the socket from the socket parser set.
Andreas 2004-07-29