void IterativeServer::cleanup(int socket, fd_set &master_fds, fd_set &master_fds2, fd_set &master_fds3, EndPoint *pendpoint) { UseCntPtr<EndPoint> pep(pendpoint); FD_CLR(socket, &master_fds); FD_CLR(socket, &master_fds2); FD_CLR(socket, &master_fds3); unregisterAllHandlers(pep); pep->close(); }
// ========================================================================= Pruning_table_mp_ep:: Pruning_table_mp_ep(Transform_table *tr, Turn_table *tn, int e1): e1(e1) // ------------------------------------------------------------------------- { int n, d, mx = 0; int mp, ep, t; unsigned int sm = 0; Pack_mp pmp(e1); int Nmp = pmp.len(); int Smp = pmp.startlen(); Pack_ep pep(e1); int Nep = pep.len(); int Sep = pep.startlen(); for (mp = 0; mp < Nmp; mp++) for (ep = 0; ep < Nep; ep++) a[mp][ep] = BIG; for (t = 0; t < B_N_TW; t++) if (mx < tn->b_len(t)) mx = tn->b_len(t); fprintf(stderr, "\n - middle edge - updown edge permutations (phase 2, %i x %i):\n", Smp, Sep); for (mp = 0; mp < Smp; mp++) for (ep = 0; ep < Sep; ep++) a[pmp.start(mp)][pep.start(ep)] = 0; d = 0; n = Smp * Sep; while (n) { fprintf(stderr," %2i %8i %10u\n", d, n, sm += n); n = 0; d++; for (mp = 0; mp < Nmp; mp++) { for (ep = 0; ep < Nep; ep++) { if (d <= a[mp][ep] || d > a[mp][ep] + mx) continue; for (t = 0; t < B_N_TW; t++) { if (d == a[mp][ep] + tn->b_len(t)) { int nmp = tr->mp->b_do_tw(t, mp); int nep = tr->ep->b_do_tw(t, ep); if (a[nmp][nep] > d) { a[nmp][nep] = d; n++; } } } } } } }
void IterativeServer::unregisterAllHandlers(EndPoint *pendpoint) { UseCntPtr<EndPoint> pep(pendpoint); int socket = pep->getSocket(); FD_CLR(socket, &master_readfds_); FD_CLR(socket, &master_writefds_); FD_CLR(socket, &master_exceptionfds_); //FD_CLR(socket, &master_signalfds_); endpoints_.erase(socket); readhandlers_.erase(socket); writehandlers_.erase(socket); exceptionhandlers_.erase(socket); signalhandlers_.erase(socket); }
int IterativeServer::registerSignalHandler(EndPoint *pserver_ep, BaseSignalHandler *phandler) { MustBeTrue(ok_); MustBeTrue(pserver_ep != NULL); MustBeTrue(phandler != NULL); UseCntPtr<EndPoint> pep(pserver_ep); endpoints_.insert(std::pair<int, UseCntPtr<EndPoint> >(pep->getSocket(), pep)); // FD_SET(pep->getSocket(), &master_signalfds_); UseCntPtr<BaseSignalHandler> ph(phandler); ph->setServer(this); signalhandlers_.insert(std::pair<int, EPSHPair>(pep->getSocket(), EPSHPair(pep, ph))); return 0; }
// register and unregister end-point handlers int IterativeServer::registerIOHandler(IOHS &handlers, fd_set &masterfds, EndPoint *pserver_ep, BaseIOHandler *phandler) { MustBeTrue(ok_); MustBeTrue(pserver_ep != NULL); MustBeTrue(phandler != NULL); UseCntPtr<EndPoint> pep(pserver_ep); endpoints_.insert(std::pair<int, UseCntPtr<EndPoint> >(pep->getSocket(), pep)); FD_SET(pep->getSocket(), &masterfds); UseCntPtr<BaseIOHandler> ph(phandler); ph->setServer(this); handlers.insert(std::pair<int, EPIOHPair>(pep->getSocket(), EPIOHPair(pep, ph))); return 0; }
int IterativeServer::unregisterSignalHandler(EndPoint *pserver_ep, BaseSignalHandler *phandler) { MustBeTrue(ok_); MustBeTrue(pserver_ep != NULL); MustBeTrue(phandler != NULL); UseCntPtr<EndPoint> pep(pserver_ep); UseCntPtr<BaseSignalHandler> ph(phandler); SHSIter shsit = signalhandlers_.find(pep->getSocket()); if ((shsit != signalhandlers_.end()) && (shsit->second.second == ph)) { // FD_CLR(pep->getSocket(), &master_signalfds_); signalhandlers_.erase(shsit); return 0; } else return -1; }
int IterativeServer::unregisterIOHandler(IOHS &handlers, fd_set &master_fds, EndPoint *pserver_ep, BaseIOHandler *phandler) { MustBeTrue(ok_); MustBeTrue(pserver_ep != NULL); MustBeTrue(phandler != NULL); UseCntPtr<EndPoint> pep(pserver_ep); UseCntPtr<BaseIOHandler> ph(phandler); IOHSIter iohsit = handlers.find(pep->getSocket()); if ((iohsit != handlers.end()) && (iohsit->second.second == ph)) { FD_CLR(pep->getSocket(), &master_fds); handlers.erase(iohsit); return 0; } else return -1; }