Ejemplo n.º 1
0
/**
 * @method		: SockServer::remove_client
 * @param		:
 *	> client	: Socket object.
 * @desc		:
 *	remove client object pointed by 'client' from list of clients.
 */
void SockServer::remove_client(Socket* client)
{
	if (! client) {
		return;
	}

	lock_client();

	if (client == _clients) {
		_clients = _clients->_next;
		if (_clients) {
			_clients->_prev	= NULL;
		}
	} else {
		if (client->_prev) {
			client->_prev->_next = client->_next;
		}
		if (client->_next) {
			client->_next->_prev = client->_prev;
		}
	}

	client->_next = NULL;
	client->_prev = NULL;

	unlock_client();
}
Ejemplo n.º 2
0
void remove_client(struct client_struct *client)
{
    int res;

    /* lock client */

    lock_client(client);

    client->status=NOTIFYFS_CLIENTSTATUS_DOWN;

    /* unlock client 
       do not destroy it yet, this is done when the client really disconnects from socket */

    unlock_client(client);

}
Ejemplo n.º 3
0
int main(int argc, char** argv)
{
    // open clients <-> gateway message queue
    mqd_t mq = open_msg_queue(MQ_NAME);
    if (mq == (mqd_t)-1)
        exit(EXIT_FAILURE);
    
    // open gateway <-> servers message queues
    create_server_mqs();
    
    Command cmd;
    int ret = receive_command(mq, &cmd);
    if (ret == -1)
    	exit(EXIT_FAILURE);
    Command *command = &cmd;
    
    int server_id = command->crypt[0];
    
    while(strcmp(command->name, "exit") != 0) {
    	server_id = command->crypt[0] - 1;
    	// if there are no more actions to take
    	if (server_id == -2)
    		unlock_client(command->name);
    	else {
    		// forward command to server
    		send_command(server_mqs[server_id], command);
    	}
    	
    	ret = receive_command(mq, command);
    	if (ret == -1)
    		exit(EXIT_FAILURE);
    }
    // send the exit command to the servers
    int i;
    for (i = 0; i < NUM_SERVERS; i++)
    	send_command(server_mqs[i], command);
    
    close_server_mqs();
    mq_close(mq);
    return 0;
}
Ejemplo n.º 4
0
/**
 * @method		: SockServer::add_client
 * @param		:
 *	> client	: socket object.
 * @desc		: add client object to list of clients.
 */
void SockServer::add_client(Socket* client)
{
	if (!client) {
		return;
	}

	lock_client();

	if (!_clients) {
		_clients = client;
	} else {
		Socket* p = _clients;

		while (p->_next) {
			p = p->_next;
		}

		p->_next	= client;
		client->_prev	= p;
	}

	unlock_client();
}