- conns_[ch->channo()] = ch;
-}
-
-void tcpsconn::accept_conn() {
- fd_set rfds;
- int max_fd = max((int)pipe_[0], (int)tcp_);
-
- while (1) {
- FD_ZERO(&rfds);
- FD_SET(pipe_[0], &rfds);
- FD_SET(tcp_, &rfds);
-
- int ret = select(max_fd+1, &rfds, NULL, NULL, NULL);
-
- if (ret < 0 && errno == EINTR)
- continue;
- else if (ret < 0) {
- perror("accept_conn select:");
- IF_LEVEL(0) LOG("accept_conn failure errno " << errno);
- VERIFY(0);
- }
-
- if (FD_ISSET(pipe_[0], &rfds))
- return;
-
- if (!FD_ISSET(tcp_, &rfds))
- VERIFY(0);
-
- try {
- process_accept();
- } catch (thread_exit_exception e) {
- break;
- }
- }
-}
-
-shared_ptr<connection> connect_to_dst(const sockaddr_in &dst, chanmgr *mgr, int lossy) {
- int s = socket(AF_INET, SOCK_STREAM, 0);
- int yes = 1;
- setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
- if (connect(s, (sockaddr*)&dst, sizeof(dst)) < 0) {
- IF_LEVEL(1) LOG_NONMEMBER("failed to " << inet_ntoa(dst.sin_addr) << ":" << ntoh(dst.sin_port));
- close(s);
- return nullptr;
- }
- IF_LEVEL(2) LOG_NONMEMBER("connect_to_dst fd=" << s << " to dst " << inet_ntoa(dst.sin_addr) << ":" << ntoh(dst.sin_port));
- return make_shared<connection>(mgr, s, lossy);