Пример #1
0
void set_nodename(const char* nodename) {
    size_t sz = 0;
    node_info_t *ninfo = NULL;
    mpr_hash_get(ht_node_info_, nodename, strlen(nodename) + 1, (void**)&ninfo, &sz);
    SAFE_ASSERT(ninfo != NULL);
    local_nid_ = ninfo->nid;
    port_ = ninfo->port;
    nodename_ = malloc(strlen(nodename) + 1);
    strcpy(nodename_, nodename);
}
Пример #2
0
void* APR_THREAD_FUNC msg_call(apr_thread_t *th, void* arg) {
    rpc_state *state = arg;
    // this is where i run it in a new thread or just in the poll thread.
    rpc_state* (**fun)(void*) = NULL;
    size_t sz;
    sconn_t *sconn = state->sconn;
    msgid_t msgid = state->msgid;
    mpr_hash_get(sconn->comm->ht, &msgid, SZ_MSGID, (void**)&fun, &sz);
    SAFE_ASSERT(fun != NULL);
    LOG_TRACE("going to call function %x", *fun);
	   
    (**fun)(state);

    // write back to this connection.	    
    if (state->raw_output) {
	reply_to(state);
	free(state->raw_output);
    }
    free(state->raw_input);
    free(state);
    // the above should be in a seperate function call.
    return NULL;
}
Пример #3
0
void handle_client_read(void *arg) {
    client_t *cli = (client_t*) arg;
    buf_t *buf = cli->buf_recv;
    apr_socket_t *sock = cli->pjob->pfd.desc.s;

    apr_status_t status = buf_from_sock(buf, sock);

    // invoke msg handling.
    size_t sz_c = 0;
    while ((sz_c = buf_sz_content(buf)) > SZ_SZMSG) {
	uint32_t sz_msg = 0;
	buf_peek(buf, (uint8_t*)&sz_msg, sizeof(sz_msg));
	if (sz_c >= sz_msg + SZ_SZMSG + SZ_MSGID) {
	    buf_read(buf, (uint8_t*)&sz_msg, SZ_SZMSG);
	    msgid_t msgid = 0;
	    buf_read(buf, (uint8_t*)&msgid, SZ_MSGID);

	    rpc_state *state = (rpc_state*)malloc(sizeof(rpc_state));
            state->sz_input = sz_msg;
            state->raw_input = (uint8_t *)malloc(sz_msg);
	    //            state->ctx = ctx;

	    buf_read(buf, state->raw_input, sz_msg);
//            state->ctx = ctx;
/*
            apr_thread_pool_push(tp_on_read_, (*(ctx->on_recv)), (void*)state, 0, NULL);
//            mpr_thread_pool_push(tp_read_, (void*)state);
*/
//            apr_atomic_inc32(&n_data_recv_);
            //(*(ctx->on_recv))(NULL, state);
            // FIXME call

            rpc_state* (**fun)(void*) = NULL;
            size_t sz;
            mpr_hash_get(cli->comm->ht, &msgid, SZ_MSGID, (void**)&fun, &sz);
            SAFE_ASSERT(fun != NULL);
            LOG_TRACE("going to call function %x", *fun);
	    //            ctx->n_rpc++;
	    //            ctx->sz_recv += n;
            (**fun)(state);

            free(state->raw_input);
            free(state);
	} else {
	    break;
	}
    }

    if (status == APR_SUCCESS) {
	
    } else if (status == APR_EOF) {
        LOG_DEBUG("cli poll on read, received eof, close socket");
	poll_mgr_remove_job(cli->pjob->mgr, cli->pjob);
    } else if (status == APR_ECONNRESET) {
        LOG_ERROR("cli poll on read. connection reset.");
	poll_mgr_remove_job(cli->pjob->mgr, cli->pjob);
        // TODO [improve] you may retry connect
    } else if (status == APR_EAGAIN) {
        LOG_DEBUG("cli poll on read. read socket busy, resource temporarily unavailable.");
        // do nothing.
    } else {
        LOG_ERROR("unkown error on poll reading. %s\n", 
		  apr_strerror(status, (char*)malloc(100), 100));
        SAFE_ASSERT(0);
    }
}