Exemplo n.º 1
0
/** Create interruptable pollset on top of APR pollset */
APT_DECLARE(apt_pollset_t*) apt_pollset_create(apr_uint32_t size, apr_pool_t *pool)
{
	apt_pollset_t *pollset = apr_palloc(pool,sizeof(apt_pollset_t));
	pollset->pool = pool;
	memset(&pollset->wakeup_pfd,0,sizeof(pollset->wakeup_pfd));
	
	/* create pollset with max number of descriptors size+1, 
	where +1 is builtin wakeup descriptor */
	if(apr_pollset_create(&pollset->base,size+1,pool,0) != APR_SUCCESS) {
		return NULL;
	}

	/* create wakeup pipe */
	if(apt_wakeup_pipe_create(pollset) != TRUE) {
		apr_pollset_destroy(pollset->base);
		return NULL;
	}

	/* add wakeup pipe to pollset */
	if(apr_pollset_add(pollset->base,&pollset->wakeup_pfd) != APR_SUCCESS) {
		apt_wakeup_pipe_destroy(pollset);
		apr_pollset_destroy(pollset->base);
		return NULL;
	}
	return pollset;
}
Exemplo n.º 2
0
static apt_bool_t mrcp_client_agent_pollset_create(mrcp_connection_agent_t *agent)
{
	apr_status_t status;
	
	/* create pollset */
	status = apr_pollset_create(&agent->pollset, (apr_uint32_t)agent->max_connection_count + 1, agent->pool, 0);
	if(status != APR_SUCCESS) {
		apt_log(APT_PRIO_WARNING,"Failed to Create Pollset");
		return FALSE;
	}

	/* create control socket */
	if(mrcp_client_agent_control_socket_create(agent) != TRUE) {
		apt_log(APT_PRIO_WARNING,"Failed to Create Control Socket");
		apr_pollset_destroy(agent->pollset);
		return FALSE;
	}
	/* add control socket to pollset */
	agent->control_sock_pfd.desc_type = APR_POLL_SOCKET;
	agent->control_sock_pfd.reqevents = APR_POLLIN;
	agent->control_sock_pfd.desc.s = agent->control_sock;
	agent->control_sock_pfd.client_data = agent->control_sock;
	status = apr_pollset_add(agent->pollset, &agent->control_sock_pfd);
	if(status != APR_SUCCESS) {
		apt_log(APT_PRIO_WARNING,"Failed to Add Control Socket to Pollset");
		mrcp_client_agent_control_socket_destroy(agent);
		apr_pollset_destroy(agent->pollset);
		return FALSE;
	}

	return TRUE;
}
Exemplo n.º 3
0
apr_status_t file_cleanup_model(int fd)
{
    apr_status_t rv = APR_SUCCESS;

    (*set_errno)(errno);
    if ((*fs_close)(fd) == 0) {
        int flags = 0;                               // TODO
        if (flags & APR_FOPEN_DELONCLOSE) {
            char *fname = "";                        // TODO
            (*fs_unlink)(fname);
        }
        errno = (*get_errno)();
    }
    else {
        /* fs_close() was not successful. */
        errno = (*get_errno)();
        rv = errno;
    }
#ifndef WAITIO_USES_POLL
    int pollset = 0;                                 // TODO? or delete?
    if (pollset != NULL) {
        apr_status_t pollset_rv = apr_pollset_destroy(pollset);
        /* If the file close failed, return its error value,
         * not apr_pollset_destroy()'s.
         */
        if (rv == APR_SUCCESS) {
            rv = pollset_rv;
        }
    }
#endif /* !WAITIO_USES_POLL */
    return rv;
}
Exemplo n.º 4
0
static void mrcp_client_agent_pollset_destroy(mrcp_connection_agent_t *agent)
{
	mrcp_client_agent_control_socket_destroy(agent);
	if(agent->pollset) {
		apr_pollset_destroy(agent->pollset);
		agent->pollset = NULL;
	}
}
Exemplo n.º 5
0
int poll_worker_destroy(
        poll_worker_t *worker) {
    worker->fg_exit = true; 
    poll_worker_stop(worker);    
    apr_pollset_destroy(worker->ps);
    apr_pool_destroy(worker->mp_poll);
    free(worker);
    return 0;
}
Exemplo n.º 6
0
/** Destroy pollset */
APT_DECLARE(apt_bool_t) apt_pollset_destroy(apt_pollset_t *pollset)
{
	/* remove wakeup pipe from pollset */
	apr_pollset_remove(pollset->base,&pollset->wakeup_pfd);
	/* destroy wakeup pipe */
	apt_wakeup_pipe_destroy(pollset);
	/* destroy pollset */
	apr_pollset_destroy(pollset->base);
	return TRUE;
}
Exemplo n.º 7
0
void LLPumpIO::rebuildPollset()
{
	LLMemType m1(LLMemType::MTYPE_IO_PUMP);
//	lldebugs << "LLPumpIO::rebuildPollset()" << llendl;
	if(mPollset)
	{
		//lldebugs << "destroying pollset" << llendl;
		apr_pollset_destroy(mPollset);
		mPollset = NULL;
	}
	U32 size = 0;
	running_chains_t::iterator run_it = mRunningChains.begin();
	running_chains_t::iterator run_end = mRunningChains.end();
	for(; run_it != run_end; ++run_it)
	{
		size += (*run_it).mDescriptors.size();
	}
	//lldebugs << "found " << size << " descriptors." << llendl;
	if(size)
	{
		// Recycle the memory pool
		const S32 POLLSET_POOL_RECYCLE_COUNT = 100;
		if(mCurrentPool
		   && (0 == (++mCurrentPoolReallocCount % POLLSET_POOL_RECYCLE_COUNT)))
		{
			apr_pool_destroy(mCurrentPool);
			mCurrentPool = NULL;
			mCurrentPoolReallocCount = 0;
		}
		if(!mCurrentPool)
		{
			apr_status_t status = apr_pool_create(&mCurrentPool, mPool);
			(void)ll_apr_warn_status(status);
		}

		// add all of the file descriptors
		run_it = mRunningChains.begin();
		LLChainInfo::conditionals_t::iterator fd_it;
		LLChainInfo::conditionals_t::iterator fd_end;
		apr_pollset_create(&mPollset, size, mCurrentPool, 0);
		for(; run_it != run_end; ++run_it)
		{
			fd_it = (*run_it).mDescriptors.begin();
			fd_end = (*run_it).mDescriptors.end();
			for(; fd_it != fd_end; ++fd_it)
			{
				apr_pollset_add(mPollset, &((*fd_it).second));
			}
		}
	}
}
Exemplo n.º 8
0
LLPumpIO::~LLPumpIO()
{
	LLMemType m1(LLMemType::MTYPE_IO_PUMP);
#if LL_THREADS_APR
	if (mChainsMutex) apr_thread_mutex_destroy(mChainsMutex);
	if (mCallbackMutex) apr_thread_mutex_destroy(mCallbackMutex);
#endif
	mChainsMutex = NULL;
	mCallbackMutex = NULL;
	if(mPollset)
	{
//		lldebugs << "cleaning up pollset" << llendl;
		apr_pollset_destroy(mPollset);
		mPollset = NULL;
	}
}
Exemplo n.º 9
0
static apr_status_t file_cleanup(apr_file_t *file, int is_child)
{
    apr_status_t rv = APR_SUCCESS;
    int fd = file->filedes;

    /* Set file descriptor to -1 before close(), so that there is no
     * chance of returning an already closed FD from apr_os_file_get().
     */
    file->filedes = -1;

    if (close(fd) == 0) {
        /* Only the parent process should delete the file! */
        if (!is_child && (file->flags & APR_DELONCLOSE)) {
            unlink(file->fname);
        }
#if APR_HAS_THREADS
        if (file->thlock) {
            rv = apr_thread_mutex_destroy(file->thlock);
        }
#endif
    }
    else {
        /* Restore, close() was not successful. */
        file->filedes = fd;

        /* Are there any error conditions other than EINTR or EBADF? */
        rv = errno;
    }
#ifndef WAITIO_USES_POLL
    if (file->pollset != NULL) {
        apr_status_t pollset_rv = apr_pollset_destroy(file->pollset);
        /* If the file close failed, return its error value,
         * not apr_pollset_destroy()'s.
         */
        if (rv == APR_SUCCESS) {
            rv = pollset_rv;
        }
    }
#endif /* !WAITIO_USES_POLL */
    return rv;
}
Exemplo n.º 10
0
void LLPumpIO::cleanup()
{
#if LL_THREADS_APR
	if(mChainsMutex) apr_thread_mutex_destroy(mChainsMutex);
	if(mCallbackMutex) apr_thread_mutex_destroy(mCallbackMutex);
#endif
	mChainsMutex = NULL;
	mCallbackMutex = NULL;
	if(mPollset)
	{
//		LL_DEBUGS() << "cleaning up pollset" << LL_ENDL;
		apr_pollset_destroy(mPollset);
		mPollset = NULL;
	}
	if(mCurrentPool)
	{
		apr_pool_destroy(mCurrentPool);
		mCurrentPool = NULL;
	}
	mPool = NULL;
}
Exemplo n.º 11
0
int sock_close(net_sock_t *nsock)
{
    network_sock_t *sock = (network_sock_t *)nsock;

    if (sock == NULL) return(0);

//log_printf(15, "sock_close: closing fd=%d\n", sock->fd);

    //**QWERT
    apr_thread_mutex_destroy(sock->lock);
    //**QWERTY


    if (sock->fd != NULL) apr_socket_close(sock->fd);
    if (sock->pollset != NULL) apr_pollset_destroy(sock->pollset);
    apr_pool_destroy(sock->mpool);

    free(sock);

    return(0);
}
void LLPluginProcessParent::updatePollset()
{
    if(!sInstancesMutex)
    {
        // No instances have been created yet.  There's no work to do.
        return;
    }

    LLMutexLock lock(sInstancesMutex);

    if(sPollSet)
    {
        LL_DEBUGS("PluginPoll") << "destroying pollset " << sPollSet << LL_ENDL;
        // delete the existing pollset.
        apr_pollset_destroy(sPollSet);
        sPollSet = NULL;
        sPollSetPool.destroy();
    }

    std::list<LLPluginProcessParent*>::iterator iter;
    int count = 0;

    // Count the number of instances that want to be in the pollset
    for(iter = sInstances.begin(); iter != sInstances.end(); iter++)
    {
        (*iter)->mPolledInput = false;
        if((*iter)->mPollFD.client_data)
        {
            // This instance has a socket that needs to be polled.
            ++count;
        }
    }

    if(sUseReadThread && sReadThread && !sReadThread->isQuitting())
    {
        if(!sPollSet && (count > 0))
        {
#ifdef APR_POLLSET_NOCOPY
            // The pollset doesn't exist yet.  Create it now.
            sPollSetPool.create();
            apr_status_t status = apr_pollset_create(&sPollSet, count, sPollSetPool(), APR_POLLSET_NOCOPY);
            if(status != APR_SUCCESS)
            {
#endif // APR_POLLSET_NOCOPY
                LL_WARNS("PluginPoll") << "Couldn't create pollset.  Falling back to non-pollset mode." << LL_ENDL;
                sPollSet = NULL;
                sPollSetPool.destroy();
#ifdef APR_POLLSET_NOCOPY
            }
            else
            {
                LL_DEBUGS("PluginPoll") << "created pollset " << sPollSet << LL_ENDL;

                // Pollset was created, add all instances to it.
                for(iter = sInstances.begin(); iter != sInstances.end(); iter++)
                {
                    if((*iter)->mPollFD.client_data)
                    {
                        status = apr_pollset_add(sPollSet, &((*iter)->mPollFD));
                        if(status == APR_SUCCESS)
                        {
                            (*iter)->mPolledInput = true;
                        }
                        else
                        {
                            LL_WARNS("PluginPoll") << "apr_pollset_add failed with status " << status << LL_ENDL;
                        }
                    }
                }
            }
#endif // APR_POLLSET_NOCOPY
        }
    }
}
Exemplo n.º 13
0
apr_status_t run_test_server(serv_ctx_t *servctx,
                             apr_short_interval_time_t duration,
                             apr_pool_t *pool)
{
    apr_status_t status;
    apr_pollset_t *pollset;
    apr_int32_t num;
    const apr_pollfd_t *desc;

    /* create a new pollset */
#ifdef BROKEN_WSAPOLL
    status = apr_pollset_create_ex(&pollset, 32, pool, 0,
                                 APR_POLLSET_SELECT);
#else
    status = apr_pollset_create(&pollset, 32, pool, 0);
#endif

    if (status != APR_SUCCESS)
        return status;

    /* Don't accept new connection while processing client connection. At
       least for present time.*/
    if (servctx->client_sock) {
        apr_pollfd_t pfd = { 0 };

        pfd.desc_type = APR_POLL_SOCKET;
        pfd.desc.s = servctx->client_sock;
        pfd.reqevents = APR_POLLIN | APR_POLLOUT;

        status = apr_pollset_add(pollset, &pfd);
        if (status != APR_SUCCESS)
            goto cleanup;

        if (servctx->proxy_client_sock) {
            apr_pollfd_t pfd = { 0 };

            pfd.desc_type = APR_POLL_SOCKET;
            pfd.desc.s = servctx->proxy_client_sock;
            pfd.reqevents = APR_POLLIN | APR_POLLOUT;

            status = apr_pollset_add(pollset, &pfd);
            if (status != APR_SUCCESS)
                goto cleanup;
        }
    }
    else {
        apr_pollfd_t pfd = { 0 };

        pfd.desc_type = APR_POLL_SOCKET;
        pfd.desc.s = servctx->serv_sock;
        pfd.reqevents = APR_POLLIN;

        status = apr_pollset_add(pollset, &pfd);
        if (status != APR_SUCCESS)
            goto cleanup;
    }

    status = apr_pollset_poll(pollset, APR_USEC_PER_SEC >> 1, &num, &desc);
    if (status != APR_SUCCESS)
        goto cleanup;

    while (num--) {
        if (desc->desc.s == servctx->serv_sock) {
            status = apr_socket_accept(&servctx->client_sock, servctx->serv_sock,
                                       servctx->pool);
            if (status != APR_SUCCESS)
                goto cleanup;

            serf__log_skt(TEST_VERBOSE, __FILE__, servctx->client_sock,
                          "server/proxy accepted incoming connection.\n");


            apr_socket_opt_set(servctx->client_sock, APR_SO_NONBLOCK, 1);
            apr_socket_timeout_set(servctx->client_sock, 0);

            status = APR_SUCCESS;
            goto cleanup;
        }

        if (desc->desc.s == servctx->client_sock) {
            if (servctx->handshake) {
                status = servctx->handshake(servctx);
                if (status)
                    goto cleanup;
            }

            /* Replay data to socket. */
            status = replay(servctx, desc->rtnevents, pool);

            if (APR_STATUS_IS_EOF(status)) {
                apr_socket_close(servctx->client_sock);
                servctx->client_sock = NULL;
                if (servctx->reset)
                    servctx->reset(servctx);

                /* If this is a proxy and the client closed the connection, also
                   close the connection to the server. */
                if (servctx->proxy_client_sock) {
                    apr_socket_close(servctx->proxy_client_sock);
                    servctx->proxy_client_sock = NULL;
                    goto cleanup;
                }
            }
            else if (APR_STATUS_IS_EAGAIN(status)) {
                status = APR_SUCCESS;
            }
            else if (status != APR_SUCCESS) {
                /* Real error. */
                goto cleanup;
            }
        }
        if (desc->desc.s == servctx->proxy_client_sock) {
            /* Replay data to proxy socket. */
            status = proxy_replay(servctx, desc->rtnevents, pool);
            if (APR_STATUS_IS_EOF(status)) {
                apr_socket_close(servctx->proxy_client_sock);
                servctx->proxy_client_sock = NULL;
            }
            else if (APR_STATUS_IS_EAGAIN(status)) {
                status = APR_SUCCESS;
            }
            else if (status != APR_SUCCESS) {
                /* Real error. */
                goto cleanup;
            }
        }

        desc++;
    }

cleanup:
    apr_pollset_destroy(pollset);

    return status;
}
Exemplo n.º 14
0
static void justsleep(abts_case *tc, void *data)
{
    apr_int32_t nsds;
    const apr_pollfd_t *hot_files;
    apr_pollset_t *pollset;
    apr_status_t rv;
    apr_time_t t1, t2;
    int i;
    apr_pollset_method_e methods[] = {
        APR_POLLSET_DEFAULT,
        APR_POLLSET_SELECT,
        APR_POLLSET_KQUEUE,
        APR_POLLSET_PORT,
        APR_POLLSET_EPOLL,
        APR_POLLSET_POLL};

    nsds = 1;
    t1 = apr_time_now();
    rv = apr_poll(NULL, 0, &nsds, apr_time_from_msec(200));
    t2 = apr_time_now();
    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
    ABTS_INT_EQUAL(tc, 0, nsds);
    ABTS_ASSERT(tc,
                "apr_poll() didn't sleep",
                (t2 - t1) > apr_time_from_msec(100));

    for (i = 0; i < sizeof methods / sizeof methods[0]; i++) {
        rv = apr_pollset_create_ex(&pollset, 5, p, 0, methods[i]);
        if (rv != APR_ENOTIMPL) {
            ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

            nsds = 1;
            t1 = apr_time_now();
            rv = apr_pollset_poll(pollset, apr_time_from_msec(200), &nsds,
                                  &hot_files);
            t2 = apr_time_now();
            ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
            ABTS_INT_EQUAL(tc, 0, nsds);
            ABTS_ASSERT(tc,
                        "apr_pollset_poll() didn't sleep",
                        (t2 - t1) > apr_time_from_msec(100));

            rv = apr_pollset_destroy(pollset);
            ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
        }

        rv = apr_pollcb_create_ex(&pollcb, 5, p, 0, methods[0]);
        if (rv != APR_ENOTIMPL) {
            ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

            t1 = apr_time_now();
            rv = apr_pollcb_poll(pollcb, apr_time_from_msec(200), NULL, NULL);
            t2 = apr_time_now();
            ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
            ABTS_ASSERT(tc,
                        "apr_pollcb_poll() didn't sleep",
                        (t2 - t1) > apr_time_from_msec(100));

            /* no apr_pollcb_destroy() */
        }
    }
}
Exemplo n.º 15
0
int main(int argc, const char *const *argv, const char *const *env)
{
	const char *db_filename = "last_message.db";
	int dying = 0;
	sqlite3 *sql = NULL;
	lmSQL lmdb = {};

	apr_socket_t *acc = NULL;
	apr_pollset_t *pollset = NULL;

	APR_DO_OR_DIE(apr_app_initialize(&argc, &argv, &env));
	atexit(&apr_terminate);

	apr_pool_t *pool;
	APR_DO_OR_DIE(apr_pool_create(&pool, NULL));

	if (argc > 2) {
		return print_usage();
	}
	if (argc == 2) {
		if (strcmp(argv[1], "--help") == 0) {
			return print_usage();
		}
		db_filename = argv[1];
	}
	int err;
	if ((err = sqlite3_open(db_filename, &sql)) != SQLITE_OK) {
		fprintf(stderr, "Can't open DB (%s): %s.\n", db_filename,
		        sqlite3_errstr(err));
		return 1;
	}

	int rc;
	char *rc_msg;
	const char *CREATE_MESSAGE_TABLES =
	    "CREATE TABLE IF NOT EXISTS messages ("
	    "  msgid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
	    "  name BLOB NOT NULL,"
	    "  left INTEGER NOT NULL,"
	    "  message BLOB NOT NULL"
	    ");";
	rc = sqlite3_exec(sql, CREATE_MESSAGE_TABLES, NULL, NULL, &rc_msg);
	if (rc != SQLITE_OK) {
		FAIL("Can't create 'messages' table: %s.\n", rc_msg);
		sqlite3_close(sql);
		return 1;
	}
	const char *CREATE_MESSAGE_SEEN = "CREATE TABLE IF NOT EXISTS seen ("
	                                  "  name BLOB PRIMARY KEY NOT NULL,"
	                                  "  msgid INTEGER  NOT NULL"
	                                  ");";
	rc = sqlite3_exec(sql, CREATE_MESSAGE_SEEN, NULL, NULL, &rc_msg);
	if (rc != SQLITE_OK) {
		FAIL("Can't create 'seen' table: %s.\n", rc_msg);
		sqlite3_close(sql);
		return 1;
	}

	lmdb.sql = sql;

#define LM_SQLITE_PREP(thing, statement)                                       \
	do {                                                                   \
		int prep =                                                     \
		    sqlite3_prepare_v2(sql, (statement), -1, (thing), NULL);   \
		if (prep != SQLITE_OK) {                                       \
			FAIL("SQL compilation error: (%s) while compiling "    \
			     "(%s).\n",                                        \
			     sqlite3_errmsg(sql), statement);                  \
			goto die;                                              \
		}                                                              \
	} while (0)

	LM_SQLITE_PREP(&lmdb.put, "INSERT INTO messages (name, left, message) "
	                          "VALUES (?, ?, ?);");
	LM_SQLITE_PREP(&lmdb.get, "SELECT msgid, left, message "
	                          "FROM messages "
	                          "WHERE name = ? "
	                          "ORDER BY msgid ASC;");
	LM_SQLITE_PREP(&lmdb.seen_add, "INSERT INTO seen (name, msgid) "
	                               "VALUES (?, ?);");
	LM_SQLITE_PREP(&lmdb.seen_del, "DELETE FROM seen "
	                               "WHERE name = ?;");
	LM_SQLITE_PREP(&lmdb.seen_get, "SELECT msgid FROM seen "
	                               "WHERE name = ?;");
	LM_SQLITE_PREP(&lmdb.drop, "DELETE FROM messages "
	                           "WHERE msgid <= ? "
	                           "  AND name = ?;");

	APR_DO_OR_DIE(apr_socket_create(&acc, APR_INET, SOCK_STREAM, 0, pool));
	APR_DO_OR_DIE(apr_socket_opt_set(acc, APR_SO_REUSEADDR, 1));
	apr_sockaddr_t *l_addr;
	APR_DO_OR_DIE(
	    apr_sockaddr_info_get(&l_addr, NULL, APR_INET, 1066, 0, pool));
	APR_DO_OR_DIE(apr_socket_bind(acc, l_addr));
	APR_DO_OR_DIE(apr_socket_listen(acc, 8));

	apr_pollfd_t apr_accept_desc;
	memset(&apr_accept_desc, 0, sizeof apr_accept_desc);
	apr_accept_desc.p = pool;
	apr_accept_desc.desc_type = APR_POLL_SOCKET;
	apr_accept_desc.desc.s = acc;
	apr_accept_desc.reqevents = APR_POLLIN;
	apr_accept_desc.client_data = NULL;

	APR_DO_OR_DIE(apr_pollset_create(&pollset, 256, pool, 0));
	APR_DO_OR_DIE(apr_pollset_add(pollset, &apr_accept_desc));

	apr_signal(SIGTERM, shutdown_on_signal);
	apr_signal(SIGINT, shutdown_on_signal);

	apr_int32_t signalled_len = 0;
	const apr_pollfd_t *signalled = NULL;
	apr_status_t poll_err = 0;
	for (;;) {
		if (global_shutting_down) {
			goto goodnight;
		}
		if (!APR_STATUS_IS_EINTR(poll_err)) {
			APR_DO_OR_DIE(poll_err);
		}
		for (apr_int32_t i = 0; i < signalled_len; i++) {
			const apr_pollfd_t *s = signalled + i;
			if (s->desc.s == acc) {
				DEBUG("accept\n");
				do_client_accept(acc, pollset, pool, &lmdb);
			} else {
				do_client_state_machine(s, pollset);
			}
		}
		poll_err =
		    apr_pollset_poll(pollset, -1, &signalled_len, &signalled);
	}

	if (0) {
	goodnight:
		fprintf(stderr, "Goodnight!\n");
	}

	if (0) {
	die:
		dying = 1;
	}

	sqlite3_finalize(lmdb.put);
	lmdb.put = 0;
	sqlite3_finalize(lmdb.get);
	lmdb.get = 0;
	sqlite3_finalize(lmdb.seen_add);
	lmdb.seen_add = 0;
	sqlite3_finalize(lmdb.seen_del);
	lmdb.seen_del = 0;
	sqlite3_finalize(lmdb.seen_get);
	lmdb.seen_get = 0;
	sqlite3_finalize(lmdb.drop);
	lmdb.drop = 0;

	if (sqlite3_close(sql) != SQLITE_OK) {
		fprintf(stderr, "Error closing DB (%s): %s.\n", db_filename,
		        sqlite3_errmsg(sql));
		return 1;
	}

	apr_pollset_destroy(pollset);
	apr_socket_close(acc);

	return dying;
}
Exemplo n.º 16
0
apr_status_t test_server_run(test_baton_t *tb,
                             apr_short_interval_time_t duration,
                             apr_pool_t *pool)
{
    apr_status_t status;
    apr_pollset_t *pollset;
    apr_int32_t num;
    const apr_pollfd_t *desc;

    /* create a new pollset */
    status = apr_pollset_create(&pollset, 32, pool, 0);
    if (status != APR_SUCCESS)
        return status;

    /* Don't accept new connection while processing client connection. At
       least for present time.*/
    if (tb->client_sock) {
        apr_pollfd_t pfd = { pool, APR_POLL_SOCKET, APR_POLLIN | APR_POLLOUT, 0,
                             { NULL }, NULL };
        pfd.desc.s = tb->client_sock;
        status = apr_pollset_add(pollset, &pfd);
        if (status != APR_SUCCESS)
            goto cleanup;
    }
    else {
        apr_pollfd_t pfd = { pool, APR_POLL_SOCKET, APR_POLLIN, 0,
                             { NULL }, NULL };
        pfd.desc.s = tb->serv_sock;
        status = apr_pollset_add(pollset, &pfd);
        if (status != APR_SUCCESS)
            goto cleanup;
    }

    status = apr_pollset_poll(pollset, APR_USEC_PER_SEC >> 1, &num, &desc);
    if (status != APR_SUCCESS)
        goto cleanup;

    while (num--) {
        if (desc->desc.s == tb->serv_sock) {
            status = apr_socket_accept(&tb->client_sock, tb->serv_sock,
                                       tb->pool);
            if (status != APR_SUCCESS)
                goto cleanup;

            apr_socket_opt_set(tb->client_sock, APR_SO_NONBLOCK, 1);
            apr_socket_timeout_set(tb->client_sock, 0);

            status = APR_SUCCESS;
            goto cleanup;
        }

        if (desc->desc.s == tb->client_sock) {
            /* Replay data to socket. */
            status = replay(tb, pool);

            if (APR_STATUS_IS_EOF(status)) {
                apr_socket_close(tb->client_sock);
                tb->client_sock = NULL;
            }
            else if (APR_STATUS_IS_EAGAIN(status)) {
                status = APR_SUCCESS;
            }
            else if (status != APR_SUCCESS) {
                /* Real error. */
                goto cleanup;
            }
        }

        desc++;
    }

cleanup:
    apr_pollset_destroy(pollset);

    return status;
}