static void sp_socksrv_notify(Spfd *spfd, void *aux) { int csock; Spsrv *srv; Spconn *conn; Socksrv *ss; struct sockaddr_in caddr; socklen_t caddrlen; char buf[64]; srv = aux; ss = srv->srvaux; if (!spfd_can_read(spfd)) return; spfd_read(spfd, buf, 0); caddrlen = sizeof(caddr); csock = accept(ss->sock, (struct sockaddr *) &caddr, &caddrlen); if (csock<0) { if (!ss->shutdown) return; close(ss->sock); if (sp_socksrv_connect(ss) < 0) fprintf(stderr, "error while reconnecting: %d\n", errno); return; } fcntl(csock, F_SETFD, FD_CLOEXEC); snprintf(buf, sizeof(buf), "%s!%d", inet_ntoa(caddr.sin_addr), ntohs(caddr.sin_port)); if (!(conn = sp_conn_create(srv, strdup(buf), csock, csock))) close(csock); }
int spcfd_can_read(Spcfd *spcfd) { if (spcfd->spfd) return spfd_can_read(spcfd->spfd); return spcfd->rpos>0 || spcfd->flags&Reof; }
static void pip_notify(Spfd *spfd, void *aux) { Xfilepipe *p; p = aux; // fprintf(stderr, "pip_notify %p %d %d %d\n", spfd, spfd_can_read(spfd), spfd_can_write(spfd), spfd_has_error(spfd)); if (p->buflen>0 || (p->direction==Read && spfd_can_read(spfd))) pip_read(p); if (spfd_can_write(spfd)) pip_write(p); if (spfd_has_error(spfd)) { pip_read_eof(p); pip_disconnect(p); } }
static void sp_ethconn_write(Spconn *conn) { int n; Spfcall *rc; Spreq *req; Spsrv *srv = conn->srv; Spethconn *ethconn = conn->caux; if (srv->debuglevel > 0) fprintf(stderr, "sp_ethconn_write: entered\n"); if (!conn->oreqs) return; req = conn->oreqs; rc = req->rcall; if (conn->srv->debuglevel) { fprintf(stderr, ">>> (%p) ", conn); sp_printfcall(stderr, rc, conn->dotu); fprintf(stderr, "\n"); } printf("sending...\n"); n = sendto(ethconn->fd, rc->pkt, rc->size, 0, (struct sockaddr *)ðconn->saddr, sizeof(ethconn->saddr)); if (srv->debuglevel > 0) fprintf(stderr, "sp_ethconn_write: sendto returned %d\n", n); if (n <= 0) return; conn->oreqs = req->next; sp_conn_free_incall(conn, req->tcall); sp_req_free(req); if (rc==srv->rcenomem || rc==srv->rcenomemu) { /* unblock reading and read some messages if we can */ srv->enomem = 0; if (spfd_can_read(ethconn->spfd)) sp_ethconn_read(conn); } else free(rc); }
static void spc_notify(Spfd *spfd, void *aux) { int ecode; char *ename; Spcfsys *fs; fs = aux; fs->in_notify++; sp_rerror(&ename, &ecode); if (ename) ename = strdup(ename); sp_werror(NULL, 0); if (spfd_can_read(spfd)) spc_fd_read(fs); if (fs->destroyed) { free(fs); return; } if (!fs->spfd) goto error; if (spfd_can_write(spfd)) spc_fd_write(fs); if (spfd_has_error(spfd)) spc_disconnect_fsys(fs); error: sp_rerror(&ename, &ecode); if (ecode) { if (spc_chatty) fprintf(stderr, "Error: %s: %d\n", ename, ecode); sp_werror(NULL, 0); } fs->in_notify--; }
static void sp_ethconn_notify(Spfd *spfd, void *aux) { int n = 0; Spconn *conn = aux; // int cr = spfd_can_read(spfd); // int cw = spfd_can_write(spfd); // if (conn->srv->debuglevel > 0) // fprintf(stderr, "sp_ethconn_notify: fd readable %d writable %d\n", cr, cw); // if (spfd_can_write(spfd)) // spfd_write(spfd, 0, 0); // reset polling flags if (spfd_can_read(spfd)) n = sp_ethconn_read(conn); if (n || spfd_has_error(spfd)) { if (conn->srv->debuglevel > 0) fprintf(stderr, "sp_ethconn_notify: error, shutdown conn\n"); sp_conn_shutdown(conn); } }