Example #1
0
void handle_client_write(void *arg) {
    client_t *cli = (client_t*) arg;
    buf_t *buf = cli->buf_send;
    apr_socket_t *sock = cli->pjob->pfd.desc.s;

    LOG_TRACE("handle client write");

    apr_thread_mutex_lock(cli->comm->mx);
    apr_status_t status = buf_to_sock(buf, sock);

    SAFE_ASSERT(status == APR_SUCCESS || status == APR_EAGAIN);

    if (status == APR_SUCCESS || status == APR_EAGAIN) {
	int mode = (buf_sz_cnt(buf) > 0) ? (APR_POLLIN | APR_POLLOUT) : APR_POLLIN;
	if (buf_sz_cnt(buf) == 0) {
	    poll_mgr_update_job(cli->pjob->mgr, cli->pjob, mode);
	}

	if (status == APR_EAGAIN) {
	    LOG_DEBUG("cli poll on write, socket busy, resource "
		      "temporarily unavailable. mode: %s, size in send buf: %d", 
		      mode == APR_POLLIN ? "only in" : "in and out",
		      buf_sz_cnt(buf));
	} else {
	    LOG_DEBUG("cli write something out.");
	}
    } else if (status == APR_ECONNRESET) {
        LOG_ERROR("connection reset on write, is this a mac os?");
	poll_mgr_remove_job(cli->pjob->mgr, cli->pjob);
        return;
    } else if (status == APR_EAGAIN) {
	SAFE_ASSERT(0);
    } else if (status == APR_EPIPE) {
        LOG_ERROR("on write, broken pipe, epipe error, is this a mac os?");
	poll_mgr_remove_job(cli->pjob->mgr, cli->pjob);
        return;
    } else {
        LOG_ERROR("error code: %d, error message: %s",
		  (int)status, apr_strerror(status, (char*)malloc(100), 100));
        SAFE_ASSERT(status == APR_SUCCESS);
    }

    //    poll_mgr_update_job(cli->pjob->mgr, cli->pjob, mode);
    apr_thread_mutex_unlock(cli->comm->mx);
}
Example #2
0
void handle_sconn_write(void* arg) {
    sconn_t *sconn = arg;

    //   LOG_TRACE("write message on socket %x", pfd->desc.s);

    apr_thread_mutex_lock(sconn->comm->mx);

    buf_t *buf = sconn->buf_send;
    apr_socket_t *sock = sconn->pjob->pfd.desc.s;

    apr_status_t status = APR_SUCCESS;
    status = buf_to_sock(buf, sock);

    if (status == APR_SUCCESS || status == APR_EAGAIN) {
	int mode = (buf_sz_cnt(buf) > 0) ? (APR_POLLIN | APR_POLLOUT) : APR_POLLIN;
	//	if (buf_sz_cnt(buf) == 0) {
	    poll_mgr_update_job(sconn->pjob->mgr, sconn->pjob, mode);	    
	    //}

	if (status == APR_EAGAIN) {
	    LOG_DEBUG("sconn poll on write, socket busy, resource "
		      "temporarily unavailable. mode: %s, size in send buf: %d", 
		      mode == APR_POLLIN ? "only in" : "in and out",
		      buf_sz_cnt(buf));
	} else {
	    LOG_DEBUG("sconn write something out.");
	}
    } else if (status == APR_ECONNRESET) {
        LOG_INFO("connection reset on write, is this a mac os?");
	poll_mgr_remove_job(sconn->pjob->mgr, sconn->pjob);
    } else if (status == APR_EAGAIN) {
	SAFE_ASSERT(0);
    } else if (status == APR_EPIPE) {
        LOG_INFO("on write, broken pipe, epipe error. remove poll job.");
	poll_mgr_remove_job(sconn->pjob->mgr, sconn->pjob);
    } else {
        LOG_ERROR("error code: %d, error message: %s",
		  (int)status, apr_strerror(status, malloc(100), 100));
        SAFE_ASSERT(status == APR_SUCCESS);
    }

    apr_thread_mutex_unlock(sconn->comm->mx);
}