Esempio n. 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);
}
Esempio n. 2
0
File: fsys.c Progetto: eugmes/diod
Npcfsys *
npc_create_fsys(int rfd, int wfd, int msize, int flags)
{
	Npcfsys *fs;

	fs = malloc(sizeof(*fs));
	if (!fs) {
		np_uerror(ENOMEM);
		return NULL;
	}

	np_uerror (0);
	pthread_mutex_init(&fs->lock, NULL);
	fs->msize = msize;
	fs->trans = NULL;
	fs->tagpool = NULL;
	fs->fidpool = NULL;
	fs->refcount = 1;
	fs->rpc = npc_rpc;
	fs->incref = npc_incref_fsys;
	fs->decref = npc_decref_fsys;
	fs->disconnect = NULL;
	fs->flags = flags;

	fs->trans = np_fdtrans_create(rfd, wfd);
	if (!fs->trans)
		goto error;
	fs->tagpool = npc_create_pool(P9_NOTAG);
	if (!fs->tagpool)
		goto error;
	fs->fidpool = npc_create_pool(P9_NOFID);
	if (!fs->fidpool)
		goto error;
	return fs;

error:
	npc_decref_fsys(fs); /* will close fds if trans successfully created */
	(void)close (rfd);   /* close here anyway for consistancy */
	if (rfd != wfd)
		(void)close (wfd);
	return NULL;
}
Esempio n. 3
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;
    }
}
Esempio n. 4
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;
}
Esempio n. 5
0
Nptrans *np_fdtrans_create_tcp(int fdin, int fdout) {
	Nptrans * result = np_fdtrans_create(fdin, fdout);
	((Fdtrans*)(result->aux))->is_tcp = 1;
	return result;
}