Exemple #1
0
Npconn*
np_conn_create(Npsrv *srv, Nptrans *trans)
{
    Npconn *conn;

    conn = malloc(sizeof(*conn));
    if (!conn)
        return NULL;

    //fprintf(stderr, "np_conn_create %p\n", conn);
    pthread_mutex_init(&conn->lock, NULL);
    pthread_cond_init(&conn->resetcond, NULL);
    pthread_cond_init(&conn->resetdonecond, NULL);
    conn->refcount = 0;
    conn->resetting = 0;
    conn->srv = srv;
    conn->msize = srv->msize;
    conn->dotu = srv->dotu;
    conn->shutdown = 0;
    conn->fidpool = np_fidpool_create();
    conn->trans = trans;
    conn->aux = NULL;
    conn->freercnum = 0;
    conn->freerclist = NULL;
    np_srv_add_conn(srv, conn);

    pthread_create(&conn->rthread, NULL, np_conn_read_proc, conn);
    return conn;
}
Exemple #2
0
static void
np_pipesrv_start(Npsrv *srv)
{
    Pipesrv *ps;
    Nptrans *trans;
    Npconn *conn;

    ps = srv->srvaux;
    trans = np_fdtrans_create(ps->fdin, ps->fdout);
    conn = np_conn_create(srv, trans);
    np_srv_add_conn(srv, conn);
}
Exemple #3
0
void
diod_rdma_accept_one (Npsrv *srv, diod_rdma_t rdma)
{
    Npconn *conn;
    Nptrans *trans;
    struct rdma_cm_event *event;
    struct rdma_cm_id *cmid;
    enum rdma_cm_event_type etype;
    int n;

    n = rdma_get_cm_event(rdma->event_channel, &event);
    if (n)
        errn_exit (n, "rdma_get_cm_event");

    cmid = (struct rdma_cm_id *)event->id;
    etype = event->event;
    rdma_ack_cm_event(event);

    switch (etype) {
        case RDMA_CM_EVENT_CONNECT_REQUEST:
            msg ("rdma: connection request");
            trans = np_rdmatrans_create(cmid, rdma_qdepth, rdma_maxmsize);
            if (trans) {
                conn = np_conn_create(srv, trans, "rdma", 0);
                cmid->context = conn;
                np_srv_add_conn(srv, conn);
            } else
                errn (np_rerror (), "np_rdmatrns_create failed");
            break;

        case RDMA_CM_EVENT_ESTABLISHED:
            msg ("rdma: connection established");
            break;

        case RDMA_CM_EVENT_DISCONNECTED:
            msg ("rdma: connection shutting down");
            conn = cmid->context;
            //np_conn_shutdown(conn);
            /* FIXME: clean up properly */
            break;

        default:
            msg ("rdma: event %d received waiting for a connect request\n",
                 etype);
    }
}
Exemple #4
0
Npconn*
np_conn_create(Npsrv *srv, Nptrans *trans, char *client_id)
{
	Npconn *conn;
	int err;

	if (!(conn = malloc(sizeof(*conn)))) {
		errno = ENOMEM;
		return NULL;
	}
	pthread_mutex_init(&conn->lock, NULL);
	pthread_mutex_init(&conn->wlock, NULL);
	pthread_cond_init(&conn->resetcond, NULL);

	conn->refcount = 0;
	conn->resetting = 0;
	conn->srv = srv;
	conn->msize = srv->msize;
	conn->shutdown = 0;
	conn->reqs_in = 0;
	conn->reqs_out = 0;
	if (!(conn->fidpool = np_fidpool_create())) {
		free (conn);
		errno = ENOMEM;
		return NULL;
	}
	snprintf(conn->client_id, sizeof(conn->client_id), "%s", client_id);
	conn->authuser = P9_NONUNAME;

	conn->trans = trans;
	conn->aux = NULL;
	np_srv_add_conn(srv, conn);

	err = pthread_create(&conn->rthread, NULL, np_conn_read_proc, conn);
	if (err != 0) {
		np_srv_remove_conn (srv, conn);
		np_fidpool_destroy(conn->fidpool);
		free (conn);
		errno = err;
		return NULL;
	}

	return conn;
}