示例#1
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);
}
示例#2
0
static void *
np_socksrv_listenproc(void *a)
{
	int csock;
	Npsrv *srv;
	Socksrv *ss;
	struct sockaddr_in caddr;
	socklen_t caddrlen;
	Npconn *conn;
	Nptrans *trans;

	char buf[64];
	unsigned char *ip;


	srv = a;
	ss = srv->srvaux;


	if (listen(ss->sock, 1) < 0)
		return NULL;

	while (!ss->shutdown) {
		caddrlen = sizeof(caddr);
		csock = accept(ss->sock, (struct sockaddr *) &caddr, &caddrlen);
		if (csock<0) {
			if (!ss->shutdown)
				continue;

			close(ss->sock);
			if (np_socksrv_connect(ss) < 0) {
				fprintf(stderr, "error while reconnecting: %d\n", errno);
				sleep(5);
			}
			continue;
		}

		trans = np_fdtrans_create_tcp(csock, csock);
		conn = np_conn_create(srv, trans);

		ip = (char *) &caddr.sin_addr;
		snprintf(buf, sizeof(buf), "%u.%u.%u.%u!%d", ip[0], ip[1], ip[2], ip[3], ntohs(caddr.sin_port));
		conn->address = strdup(buf);
	}

	return NULL;
}
示例#3
0
文件: tnpsrv.c 项目: carriercomm/diod
int
main (int argc, char *argv[])
{
    Npsrv *srv;
    Npconn *conn;
    Nptrans *trans;
    int flags = SRV_FLAGS_DEBUG_9PTRACE | SRV_FLAGS_DEBUG_USER;

    diod_log_init (argv[0]);
    diod_conf_init ();

    if (!(srv = np_srv_create (16, flags)))
        errn_exit (np_rerror (), "out of memory");
    srv->logmsg = diod_log_msg;

    srv->attach = myattach;
    srv->clunk = myclunk;

    /* create one connection */
    if (!(trans = ttrans_create ()))
        err_exit ("ttrans_create");
    if (!(conn = np_conn_create (srv, trans, "loopback")))
        msg_exit  ("np_conn_create failure");

    _send_tversion (trans);
    _send_tauth (trans);
    _send_tattach (trans, 0, 0);
    _send_tattach (trans, 0, 1);
    _send_tattach (trans, 1, 2);
    _send_tattach (trans, 1, 3);
    _send_tattach (trans, 0, 4);
    _send_tclunk (trans, 4);
    _send_tclunk (trans, 3);
    _send_tclunk (trans, 2);
    _send_tclunk (trans, 1);
    _send_tclunk (trans, 0);
    ttrans_rpc (trans, NULL, NULL); /* signifies EOF to reader */

    /* wait for exactly one connect/disconnect */
    np_srv_wait_conncount (srv, 1);
    sleep(1); /* racy here - conn reader needs time to process EOF */
    np_srv_destroy (srv);

    diod_conf_fini ();
    diod_log_fini ();
    exit (0);
}
示例#4
0
文件: diod_rdma.c 项目: 8l/diod
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);
    }
}
示例#5
0
void
diod_sock_startfd (Npsrv *srv, int fdin, int fdout, char *client_id)
{
    Npconn *conn;
    Nptrans *trans;

    trans = np_fdtrans_create (fdin, fdout);
    if (!trans) {
        errn (np_rerror (), "error creating transport for %s", client_id);
        (void)close (fdin);
        if (fdin != fdout)
            (void)close (fdout);
        return;
    }
                 
    conn = np_conn_create (srv, trans, client_id);
    if (!conn) {
        errn (np_rerror (), "error creating connection for %s", client_id);
	/* trans is destroyed in np_conn_create on failure */
        return;
    }
}
示例#6
0
static void *
np_socksrv_listenproc(void *a)
{
	int csock;
	Npsrv *srv;
	Socksrv *ss;
	struct sockaddr_in caddr;
	socklen_t caddrlen;
	Npconn *conn;
	Nptrans *trans;

	srv = a;
	ss = srv->srvaux;


	if (listen(ss->sock, 1) < 0)
		return NULL;

	while (!ss->shutdown) {
		caddrlen = sizeof(caddr);
		csock = accept(ss->sock, (struct sockaddr *) &caddr, &caddrlen);
		if (csock<0) {
			if (!ss->shutdown)
				continue;

			close(ss->sock);
			if (np_socksrv_connect(ss) < 0) {
				fprintf(stderr, "error while reconnecting: %d\n", errno);
				sleep(5);
			}
			continue;
		}

		trans = np_fdtrans_create(csock, csock);
		conn = np_conn_create(srv, trans);
	}

	return NULL;
}