41 #include <sys/socket.h> 42 #include <sys/eventfd.h> 52 iSignalEvent_ = eventfd(0,0);
66 reinterpret_cast<void*>(&iOption),
69 makeException<SocketException>(
"setsockopt SO_REUSEADDR: %s",
76 makeException<SocketException>(
"bind: %s",
81 if(listen(iSock_,10) < 0)
83 makeException<SocketException>(
"listen: %s",
87 thread_ = std::thread(&Service::process,
this);
93 eventfd_write(iSignalEvent_,1);
99 void EMANE::ControlPort::Service::process()
101 std::map<int,std::unique_ptr<Session>> sessionMap;
105 int nfds{iSignalEvent_};
110 FD_SET(iSignalEvent_,&rfds);
111 FD_SET(iSock_,&rfds);
113 nfds = std::max(iSock_,nfds);
115 for(
const auto & entry : sessionMap)
117 FD_SET(entry.first,&rfds);
118 nfds = std::max(entry.first,nfds);
121 auto result = select(nfds+1,&rfds,
nullptr,
nullptr,
nullptr);
135 if(FD_ISSET(iSignalEvent_,&rfds))
140 if(FD_ISSET(iSock_,&rfds))
144 if((iNewFd = accept(iSock_,
nullptr,
nullptr)) > 0)
146 sessionMap.insert(std::make_pair(iNewFd,std::unique_ptr<Session>{
new Session{}}));
150 auto iter = sessionMap.begin();
152 while(iter != sessionMap.end())
154 if(FD_ISSET(iter->first,&rfds))
157 if(iter->second->process(iter->first))
159 sessionMap.erase(iter++);
173 for(
const auto & entry : sessionMap)
socklen_t getAddrLength() const
void open(const INETAddr &endpoint)
sockaddr * getSockAddr() const