示例#1
0
文件: service.c 项目: vanrein/tlspool
/* Pickup on activity and process it.  Processing may mean a number of things:
 *  - to try an accept() on a server socket (ignoring it upon EAGAIN)
 *  - to trigger a thread that is hoping writing after EAGAIN
 *  - to read a message and further process it
 */
void process_activity (int sox, int soxidx, struct soxinfo *soxi, short int revents) {
	if (revents & POLLOUT) {
		//TODO// signal waiting thread that it may continue
		tlog (TLOG_UNIXSOCK, LOG_CRIT, "Eekk!!  Could send a packet?!?  Unregistering client");
		unregister_client_socket_byindex (soxidx);
		close (sox);
	}
	if (revents & POLLIN) {
		if (soxi->flags & SOF_SERVER) {
			struct sockaddr sa;
			socklen_t salen = sizeof (sa);
			int newsox = accept (sox, &sa, &salen);
			if (newsox != -1) {
				tlog (TLOG_UNIXSOCK, LOG_NOTICE, "Received incoming connection.  Registering it");
				register_client_socket (newsox);
			}
		}
		if (soxi->flags & SOF_CLIENT) {
			struct command *cmd = allocate_command_for_clientfd (sox);
			if (receive_command (sox, cmd)) {
				process_command (cmd);
			} else {
				tlog (TLOG_UNIXSOCK, LOG_ERR, "Failed to receive command request");
			}
		}
	}
}
示例#2
0
void accept_client(int listen_socket) {
	struct sockaddr client;
	socklen_t client_size = sizeof(struct sockaddr);

	int client_socket = accept(listen_socket, & client, & client_size);

	if(-1 != client_socket)
		register_client_socket(client_socket);
}