void server_create(server_t **svr, poll_mgr_t *mgr) { *svr = (server_t*) malloc(sizeof(server_t)); server_t *s = *svr; rpc_common_create(&s->comm); poll_job_create(&s->pjob); s->pjob->do_read = &handle_server_accept; s->pjob->holder = s; s->pjob->mgr = (mgr != NULL) ? mgr: mgr_; s->is_start = false; mpr_hash_create(&s->ht_conn); apr_thread_pool_create(&s->tp, 10, 10, s->comm->mp); }
void client_create(client_t **cli, poll_mgr_t *mgr) { *cli = (client_t *) malloc(sizeof(client_t)); client_t *c = *cli; rpc_common_create(&c->comm); poll_job_create(&c->pjob); c->pjob->do_read = handle_client_read; c->pjob->do_write = handle_client_write; c->pjob->holder = c; c->pjob->mgr = (mgr != NULL) ? mgr : mgr_; buf_create(&c->buf_recv); buf_create(&c->buf_send); LOG_DEBUG("a new client created."); }
void sconn_create(sconn_t **sconn, server_t *svr) { *sconn = (sconn_t *) malloc(sizeof(sconn_t)); sconn_t *sc = *sconn; sc->tp = svr->tp; rpc_common_create(&sc->comm); sc->comm->ht = svr->comm->ht; // TODO should be copy. poll_job_create(&sc->pjob); sc->pjob->do_read = handle_sconn_read; sc->pjob->do_write = handle_sconn_write; sc->pjob->holder = sc; sc->pjob->mgr = svr->pjob->mgr; buf_create(&sc->buf_recv); buf_create(&sc->buf_send); }