Spconn* sp_ethconn_create(Spsrv *srv, int fd) { Spconn *conn = sp_conn_create(srv); if (!conn) return NULL; Spethconn *ethconn = sp_malloc(sizeof(*ethconn)); if (!ethconn) goto error; ethconn->fd = fd; ethconn->spfd = spfd_add(fd, sp_ethconn_notify, conn); if (!ethconn->spfd) goto error; conn->caux = ethconn; conn->shutdown = sp_ethconn_shutdown; conn->dataout = sp_ethconn_dataout; sp_srv_add_conn(srv, conn); return conn; error: free(ethconn); sp_conn_destroy(conn); return NULL; }
Spcfd * spcfd_add_fd(int fd, void (notify)(Spcfd *, void *), void *aux) { Spcfd *ret; ret = sp_malloc(sizeof(*ret)); if (!ret) return NULL; ret->spfd = spfd_add(fd, spcfd_notify, ret); ret->fid = NULL; ret->flags = 0; ret->iounit = 0; ret->notify = notify; ret->aux = aux; ret->offset = 0; ret->rbuf = NULL; ret->rpos = 0; ret->wbuf = NULL; ret->wpos = 0; ret->rtc = NULL; ret->wtc = NULL; ret->next = spcfds; spcfds = ret; return ret; }
static void sp_socksrv_start(Spsrv *srv) { Socksrv *ss; ss = srv->srvaux; ss->spfd = spfd_add(ss->sock, sp_socksrv_notify, srv); }
Spcfsys * spc_create_fsys(int fd, int msize) { Spcfsys *fs; fs = sp_malloc(sizeof(*fs)); if (!fs) return NULL; fs->fd = fd; fs->spfd = NULL; fs->dotu = 0; fs->msize = msize; fs->root = NULL; fs->afid = NULL; fs->tagpool = NULL; fs->fidpool = NULL; fs->ifcall = NULL; fs->pend_pos = 0; fs->pend_first = NULL; fs->pend_last = NULL; fs->sent_reqs = NULL; fs->ename = NULL; fs->ecode = 0; fs->in_notify = 0; fs->destroyed = 0; fs->laddr = NULL; fs->raddr = NULL; fs->spfd = spfd_add(fd, spc_notify, fs); if (!fs->spfd) goto error; fs->tagpool = spc_create_pool(NOTAG); if (!fs->tagpool) goto error; fs->fidpool = spc_create_pool(NOFID); if (!fs->fidpool) goto error; return fs; error: spc_disconnect_fsys(fs); return NULL; }
Xfilepipe * pip_create(int direction) { int pip[2]; Xfilepipe *p; p = sp_malloc(sizeof(*p)); if (!p) return NULL; p->err = 0; p->direction = direction; p->bufsize = 1024; p->buf = sp_malloc(p->bufsize); if (!p->buf) { free(p); return NULL; } p->buflen = 0; if (pipe(pip) < 0) { sp_uerror(errno); free(p->buf); free(p); return NULL; } if (direction == Read) { p->lfd = pip[0]; p->rfd = pip[1]; } else { p->lfd = pip[1]; p->rfd = pip[0]; } fcntl(p->lfd, F_SETFD, FD_CLOEXEC); p->reqs = NULL; p->lspfd = spfd_add(p->lfd, pip_notify, p); // fprintf(stderr, "pip_create %p lfd %d rfd %d\n", p, p->lfd, p->rfd); return p; }
void spc_remount(Spcfsys *fs) { fs->spfd = spfd_add(fs->fd, spc_notify, fs); }