/* following _wt_ functions are called from a worker thread so caution is required
 * to keep its operations thread safe
 */
static int np_wt_accept (void * args) {
    int rc;
    ServerNP * si = (ServerNP *)args;

    si->np_sock = nopoll_conn_accept (si->np_ctx, si->np_listener);
    if (si->np_sock == NULL) {
        /* nopoll library does not always set errno, in this case create 
         * a fake one.
         */
        if (errno == 0) errno = EINVAL;
        return -1;
    }

    (void) nopoll_conn_set_sock_block(nopoll_conn_socket(si->np_sock), nopoll_false);
    rc = channel_np_wait_until_connection_ready(si->np_sock, 1000, si->is_ssl);
    (void) nopoll_conn_set_sock_block(nopoll_conn_socket(si->np_sock), nopoll_true);

    if (rc == 0) {
        errno = EINVAL;
        return -1;
    }
    assert (rc);
    assert(nopoll_conn_is_ready(si->np_sock));
    return (si->np_sock != NULL);
}
Exemplo n.º 2
0
/** 
 * @internal Function used to detected which connections has something
 * interesting to be notified.
 *
 */
nopoll_bool nopoll_loop_process (noPollCtx * ctx, noPollConn * conn, noPollPtr user_data)
{
	int        * conn_changed = (int *) user_data;

	/* check if the connection have something to notify */
	if (ctx->io_engine->isset (ctx, conn->session, ctx->io_engine->io_object)) {

		/* call to notify action according to role */
		switch (conn->role) {
		case NOPOLL_ROLE_CLIENT:
		case NOPOLL_ROLE_LISTENER:
			/* received data, notify */
			nopoll_loop_process_data (ctx, conn);
			break;
		case NOPOLL_ROLE_MAIN_LISTENER:
			/* call to handle */
			nopoll_conn_accept (ctx, conn);
			break;
		default:
			nopoll_log (ctx, NOPOLL_LEVEL_CRITICAL, "Found connection with unknown role, closing and dropping");
			nopoll_conn_shutdown (conn);
			break;
		}
		
		/* reduce connection changed */
		(*conn_changed)--;
	} /* end if */
	
	return (*conn_changed) == 0;
}