Previous: The listener
This application runs on a separate thread for each
connected user. It is responsible for listening on the user
socket on one hand and listening on the ICQ network on the
other. The connection control function is implemented in the
In the connection control module we are introduced to the
structure of ``link environment'' (struct
link_env). This structure includes the ICQLINK
of the connection (which is the session identifiers for the
icqlib library as can be read in the icqlib manual submitted
with this documentation) along with additional information
about the connection. The link environment contains the
- The ICQLINK of the connection.
- An identifier to whether the contact list has been
- The user's contact list. The contact list is
implemented as a linked list and will be described in detail
when we talk about the database.
- An identifier to whether the link is active.
- A pointer that can point to any additional data.
- The socket of the connection to the client.
- An identifier to whether the session has ended or
not. This is required for purposes of flow of control.
The main function of the connection control mechanism is
connector(). This function is called when the
thread is initiated and handles flow of control until the
connection is closed.
The function first initializes the environment and then goes
on a look that is active as long as the identifier in the
environment is set to a true value.
In the loop, we check for information from the ICQ network
and for information from the user.
- If the connection to the ICQ network has been
established (there is an identifier for that in the
environment), the function first checks whether it's time to
send another keepalive message to the ICQ network. If so, it
sends a keepalive message. Then it checks for new messages
from the ICQ network using the icq_Main()
function. This function calls the appropriate callbacks if
necessary (please check the icqlib manual for more
information on the structure of icqlib).
- The function then checks for new information on the
client connection and if there's a new information on that,
it extracts the message and handles it. Extracting the
message is simply a matter of socket programming. Handling
the message is also made simple by our protocol
structure. All we have to do is read the message type and
send the message to the appropriate handler (we will
elaborate on the handlers later).
Before the connection control function returns, it cleans
the environment, releasing all allocated resources.
Previous: The listener