Exemple #1
0
/**
 * Socket associated with client connection has indicated it has data ready
 * to read. We want to determine which client connection and receive the data
 * from it.
 */
void Server::handleServerConnection(int sckt)
{
    //determine connection
    ServerConnection* connection = mConnections->getServerConnection(sckt);
    if (0 != connection)
    {
        Callback* callback = getCallback();
        try
        {
            //receive data
            std::vector<char> result = connection->performReceive();

            if (0 != callback)
            {
                callback->receiveComplete(connection->getIdentifier(), &(result[0]),
                        result.size());
            }

        } catch (std::runtime_error)
        {
            if (0 != callback)
            {
                callback->disconnected(connection->getIdentifier());
            }
            //error retrieving data from client, connection is bad, need to remove it
            mConnections->removeServerConnection(sckt);
        }
    }
}