virtual void postFork() override { checkSockets(); // before we drop the caps we can even open our /proc files ! const std::string procName = std::string("/proc/") + std::to_string(getpid()) + std::string("/smaps"); _procSMaps = fopen(procName.c_str(), "r"); if (_procSMaps == NULL) { _failure = "Failed to open process: " + procName; throw std::runtime_error(_failure); } }
/** * Test whether the given socket still has an open connection. * * @return true when the connection is open, false when it's closed or in an * error state, check getSockErr() to find out which. */ static bool connectionIsOpen(Socket* sock) { const SocketSet set = {std::vector<Socket *>(1, sock)}; ASSERT_OR_RETURN((setSockErr(EBADF), false), sock && sock->fd[SOCK_CONNECTION] != INVALID_SOCKET, "Invalid socket"); // Check whether the socket is still connected int ret = checkSockets(&set, 0); if (ret == SOCKET_ERROR) { return false; } else if (ret == (int)set.fds.size() && sock->ready) { /* The next recv(2) call won't block, but we're writing. So * check the read queue to see if the connection is closed. * If there's no data in the queue that means the connection * is closed. */ #if defined(WZ_OS_WIN) unsigned long readQueue; ret = ioctlsocket(sock->fd[SOCK_CONNECTION], FIONREAD, &readQueue); #else int readQueue; ret = ioctl(sock->fd[SOCK_CONNECTION], FIONREAD, &readQueue); #endif if (ret == SOCKET_ERROR) { debug(LOG_NET, "socket error"); return false; } else if (readQueue == 0) { // Disconnected setSockErr(ECONNRESET); debug(LOG_NET, "Read queue empty - failing (ECONNRESET)"); return false; } } return true; }