Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 7 | #include <sys/socket.h> |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 8 | #include <sys/select.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 9 | #include <netinet/in.h> |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 10 | #include <netinet/tcp.h> |
Mark Slee | 6d56eb9 | 2007-07-06 22:28:15 +0000 | [diff] [blame^] | 11 | #include <netdb.h> |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 12 | #include <fcntl.h> |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 13 | #include <errno.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 14 | |
Marc Slemko | d42a2c2 | 2006-08-10 03:30:18 +0000 | [diff] [blame] | 15 | #include "TSocket.h" |
| 16 | #include "TServerSocket.h" |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 17 | #include <boost/shared_ptr.hpp> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 18 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 19 | namespace facebook { namespace thrift { namespace transport { |
| 20 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 21 | using namespace boost; |
| 22 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 23 | TServerSocket::TServerSocket(int port) : |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 24 | port_(port), |
Martin Kraemer | ee341cb | 2007-02-05 21:40:38 +0000 | [diff] [blame] | 25 | serverSocket_(-1), |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 26 | acceptBacklog_(1024), |
| 27 | sendTimeout_(0), |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 28 | recvTimeout_(0), |
boz | 1ea81ce | 2007-05-14 23:04:33 +0000 | [diff] [blame] | 29 | retryLimit_(0), |
| 30 | retryDelay_(0), |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 31 | intSock1_(-1), |
| 32 | intSock2_(-1) {} |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 33 | |
| 34 | TServerSocket::TServerSocket(int port, int sendTimeout, int recvTimeout) : |
| 35 | port_(port), |
Martin Kraemer | ee341cb | 2007-02-05 21:40:38 +0000 | [diff] [blame] | 36 | serverSocket_(-1), |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 37 | acceptBacklog_(1024), |
| 38 | sendTimeout_(sendTimeout), |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 39 | recvTimeout_(recvTimeout), |
boz | 1ea81ce | 2007-05-14 23:04:33 +0000 | [diff] [blame] | 40 | retryLimit_(0), |
| 41 | retryDelay_(0), |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 42 | intSock1_(-1), |
| 43 | intSock2_(-1) {} |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 44 | |
| 45 | TServerSocket::~TServerSocket() { |
| 46 | close(); |
| 47 | } |
| 48 | |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 49 | void TServerSocket::setSendTimeout(int sendTimeout) { |
| 50 | sendTimeout_ = sendTimeout; |
| 51 | } |
| 52 | |
| 53 | void TServerSocket::setRecvTimeout(int recvTimeout) { |
| 54 | recvTimeout_ = recvTimeout; |
| 55 | } |
| 56 | |
boz | 1ea81ce | 2007-05-14 23:04:33 +0000 | [diff] [blame] | 57 | void TServerSocket::setRetryLimit(int retryLimit) { |
| 58 | retryLimit_ = retryLimit; |
| 59 | } |
| 60 | |
| 61 | void TServerSocket::setRetryDelay(int retryDelay) { |
| 62 | retryDelay_ = retryDelay; |
| 63 | } |
| 64 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 65 | void TServerSocket::listen() { |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 66 | int sv[2]; |
| 67 | if (-1 == socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 68 | GlobalOutput("TServerSocket::init()"); |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 69 | intSock1_ = -1; |
| 70 | intSock2_ = -1; |
| 71 | } else { |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 72 | intSock1_ = sv[1]; |
| 73 | intSock2_ = sv[0]; |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Mark Slee | 6d56eb9 | 2007-07-06 22:28:15 +0000 | [diff] [blame^] | 76 | struct addrinfo hints, *res, *res0; |
| 77 | int error; |
| 78 | char port[sizeof("65536") + 1]; |
| 79 | memset(&hints, 0, sizeof(hints)); |
| 80 | hints.ai_family = PF_UNSPEC; |
| 81 | hints.ai_socktype = SOCK_STREAM; |
| 82 | hints.ai_flags = AI_PASSIVE; |
| 83 | sprintf(port, "%d", port_); |
| 84 | |
| 85 | // Wildcard address |
| 86 | error = getaddrinfo(NULL, port, &hints, &res0); |
| 87 | if (error) { |
| 88 | fprintf(stderr, "getaddrinfo %d: %s\n", error, gai_strerror(error)); |
| 89 | close(); |
| 90 | throw TTransportException(TTransportException::NOT_OPEN, "Could not resolve host for server socket."); |
| 91 | } |
| 92 | |
| 93 | // Pick the ipv6 address first since ipv4 addresses can be mapped |
| 94 | // into ipv6 space. |
| 95 | for (res = res0; res; res = res->ai_next) { |
| 96 | if (res->ai_family == AF_INET6 || res->ai_next == NULL) |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | serverSocket_ = socket(res->ai_family, res->ai_socktype, res->ai_protocol); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 101 | if (serverSocket_ == -1) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 102 | GlobalOutput("TServerSocket::listen() socket"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 103 | close(); |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 104 | throw TTransportException(TTransportException::NOT_OPEN, "Could not create server socket."); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | // Set reusaddress to prevent 2MSL delay on accept |
| 108 | int one = 1; |
| 109 | if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_REUSEADDR, |
| 110 | &one, sizeof(one))) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 111 | GlobalOutput("TServerSocket::listen() SO_REUSEADDR"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 112 | close(); |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 113 | throw TTransportException(TTransportException::NOT_OPEN, "Could not set SO_REUSEADDR"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 116 | // Defer accept |
| 117 | #ifdef TCP_DEFER_ACCEPT |
| 118 | if (-1 == setsockopt(serverSocket_, SOL_SOCKET, TCP_DEFER_ACCEPT, |
| 119 | &one, sizeof(one))) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 120 | GlobalOutput("TServerSocket::listen() TCP_DEFER_ACCEPT"); |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 121 | close(); |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 122 | throw TTransportException(TTransportException::NOT_OPEN, "Could not set TCP_DEFER_ACCEPT"); |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 123 | } |
| 124 | #endif // #ifdef TCP_DEFER_ACCEPT |
| 125 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 126 | // Turn linger off, don't want to block on calls to close |
| 127 | struct linger ling = {0, 0}; |
| 128 | if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_LINGER, |
| 129 | &ling, sizeof(ling))) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 130 | close(); |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 131 | GlobalOutput("TServerSocket::listen() SO_LINGER"); |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 132 | throw TTransportException(TTransportException::NOT_OPEN, "Could not set SO_LINGER"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 135 | // TCP Nodelay, speed over bandwidth |
| 136 | if (-1 == setsockopt(serverSocket_, IPPROTO_TCP, TCP_NODELAY, |
| 137 | &one, sizeof(one))) { |
| 138 | close(); |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 139 | GlobalOutput("setsockopt TCP_NODELAY"); |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 140 | throw TTransportException(TTransportException::NOT_OPEN, "Could not set TCP_NODELAY"); |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 143 | // Set NONBLOCK on the accept socket |
| 144 | int flags = fcntl(serverSocket_, F_GETFL, 0); |
| 145 | if (flags == -1) { |
| 146 | throw TTransportException(TTransportException::NOT_OPEN, "fcntl() failed"); |
| 147 | } |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 148 | |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 149 | if (-1 == fcntl(serverSocket_, F_SETFL, flags | O_NONBLOCK)) { |
| 150 | throw TTransportException(TTransportException::NOT_OPEN, "fcntl() failed"); |
| 151 | } |
| 152 | |
boz | 1ea81ce | 2007-05-14 23:04:33 +0000 | [diff] [blame] | 153 | // prepare the port information |
boz | 1ea81ce | 2007-05-14 23:04:33 +0000 | [diff] [blame] | 154 | // we may want to try to bind more than once, since SO_REUSEADDR doesn't |
| 155 | // always seem to work. The client can configure the retry variables. |
| 156 | int retries = 0; |
| 157 | do { |
Mark Slee | 6d56eb9 | 2007-07-06 22:28:15 +0000 | [diff] [blame^] | 158 | if (0 == bind(serverSocket_, res->ai_addr, res->ai_addrlen)) { |
boz | 1ea81ce | 2007-05-14 23:04:33 +0000 | [diff] [blame] | 159 | break; |
| 160 | } |
| 161 | |
| 162 | // use short circuit evaluation here to only sleep if we need to |
| 163 | } while ((retries++ < retryLimit_) && (sleep(retryDelay_) == 0)); |
| 164 | |
Mark Slee | 6d56eb9 | 2007-07-06 22:28:15 +0000 | [diff] [blame^] | 165 | // free addrinfo |
| 166 | freeaddrinfo(res0); |
| 167 | |
boz | 1ea81ce | 2007-05-14 23:04:33 +0000 | [diff] [blame] | 168 | // throw an error if we failed to bind properly |
| 169 | if (retries > retryLimit_) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 170 | char errbuf[1024]; |
| 171 | sprintf(errbuf, "TServerSocket::listen() BIND %d", port_); |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 172 | GlobalOutput(errbuf); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 173 | close(); |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 174 | throw TTransportException(TTransportException::NOT_OPEN, "Could not bind"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | // Call listen |
| 178 | if (-1 == ::listen(serverSocket_, acceptBacklog_)) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 179 | GlobalOutput("TServerSocket::listen() LISTEN"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 180 | close(); |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 181 | throw TTransportException(TTransportException::NOT_OPEN, "Could not listen"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // The socket is now listening! |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 187 | shared_ptr<TTransport> TServerSocket::acceptImpl() { |
Martin Kraemer | 10640d8 | 2007-02-03 01:59:12 +0000 | [diff] [blame] | 188 | if (serverSocket_ < 0) { |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 189 | throw TTransportException(TTransportException::NOT_OPEN, "TServerSocket not listening"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 192 | fd_set fds; |
| 193 | |
Aditya Agarwal | 7859a57 | 2007-05-31 01:33:07 +0000 | [diff] [blame] | 194 | int maxEintrs = 5; |
| 195 | int numEintrs = 0; |
| 196 | |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 197 | while (true) { |
| 198 | FD_ZERO(&fds); |
| 199 | FD_SET(serverSocket_, &fds); |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 200 | if (intSock2_ >= 0) { |
| 201 | FD_SET(intSock2_, &fds); |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 202 | } |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 203 | int ret = select(serverSocket_+1, &fds, NULL, NULL, NULL); |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 204 | |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 205 | if (ret < 0) { |
Aditya Agarwal | 7859a57 | 2007-05-31 01:33:07 +0000 | [diff] [blame] | 206 | // error cases |
boz | f83c9db | 2007-05-31 23:38:37 +0000 | [diff] [blame] | 207 | if (errno == EINTR && (numEintrs++ < maxEintrs)) { |
Aditya Agarwal | 7859a57 | 2007-05-31 01:33:07 +0000 | [diff] [blame] | 208 | // EINTR needs to be handled manually and we can tolerate |
| 209 | // a certain number |
| 210 | continue; |
| 211 | } |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 212 | GlobalOutput("TServerSocket::acceptImpl() select -1"); |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 213 | throw TTransportException(TTransportException::UNKNOWN); |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 214 | } else if (ret > 0) { |
| 215 | // Check for an interrupt signal |
| 216 | if (intSock2_ >= 0 && FD_ISSET(intSock2_, &fds)) { |
| 217 | int8_t buf; |
| 218 | if (-1 == recv(intSock2_, &buf, sizeof(int8_t), 0)) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 219 | GlobalOutput("TServerSocket::acceptImpl() interrupt receive"); |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 220 | } |
| 221 | throw TTransportException(TTransportException::INTERRUPTED); |
| 222 | } |
| 223 | // Check for the actual server socket being ready |
| 224 | if (FD_ISSET(serverSocket_, &fds)) { |
| 225 | break; |
| 226 | } |
| 227 | } else { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 228 | GlobalOutput("TServerSocket::acceptImpl() select 0"); |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 229 | throw TTransportException(TTransportException::UNKNOWN); |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
Mark Slee | 6d56eb9 | 2007-07-06 22:28:15 +0000 | [diff] [blame^] | 233 | struct sockaddr_storage clientAddress; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 234 | int size = sizeof(clientAddress); |
| 235 | int clientSocket = ::accept(serverSocket_, |
| 236 | (struct sockaddr *) &clientAddress, |
| 237 | (socklen_t *) &size); |
| 238 | |
Martin Kraemer | ee341cb | 2007-02-05 21:40:38 +0000 | [diff] [blame] | 239 | if (clientSocket < 0) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 240 | GlobalOutput("TServerSocket::accept()"); |
Mark Slee | 6d56eb9 | 2007-07-06 22:28:15 +0000 | [diff] [blame^] | 241 | throw TTransportException(TTransportException::UNKNOWN, std::string("ERROR:") + sys_errlist[errno]); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 242 | } |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 243 | |
| 244 | // Make sure client socket is blocking |
| 245 | int flags = fcntl(clientSocket, F_GETFL, 0); |
| 246 | if (flags == -1) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 247 | GlobalOutput("TServerSocket::select() fcntl GETFL"); |
Mark Slee | 6d56eb9 | 2007-07-06 22:28:15 +0000 | [diff] [blame^] | 248 | throw TTransportException(TTransportException::UNKNOWN, std::string("ERROR:") + sys_errlist[errno]); |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 249 | } |
| 250 | if (-1 == fcntl(clientSocket, F_SETFL, flags & ~O_NONBLOCK)) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 251 | GlobalOutput("TServerSocket::select() fcntl SETFL"); |
Mark Slee | 6d56eb9 | 2007-07-06 22:28:15 +0000 | [diff] [blame^] | 252 | throw TTransportException(TTransportException::UNKNOWN, std::string("ERROR:") + sys_errlist[errno]); |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 253 | } |
Martin Kraemer | 10640d8 | 2007-02-03 01:59:12 +0000 | [diff] [blame] | 254 | |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 255 | shared_ptr<TSocket> client(new TSocket(clientSocket)); |
| 256 | if (sendTimeout_ > 0) { |
| 257 | client->setSendTimeout(sendTimeout_); |
| 258 | } |
| 259 | if (recvTimeout_ > 0) { |
| 260 | client->setRecvTimeout(recvTimeout_); |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 261 | } |
Aditya Agarwal | 7859a57 | 2007-05-31 01:33:07 +0000 | [diff] [blame] | 262 | |
Mark Slee | 2905078 | 2006-09-29 00:12:30 +0000 | [diff] [blame] | 263 | return client; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 266 | void TServerSocket::interrupt() { |
| 267 | if (intSock1_ >= 0) { |
| 268 | int8_t byte = 0; |
| 269 | if (-1 == send(intSock1_, &byte, sizeof(int8_t), 0)) { |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 270 | GlobalOutput("TServerSocket::interrupt()"); |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 275 | void TServerSocket::close() { |
Martin Kraemer | ee341cb | 2007-02-05 21:40:38 +0000 | [diff] [blame] | 276 | if (serverSocket_ >= 0) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 277 | shutdown(serverSocket_, SHUT_RDWR); |
| 278 | ::close(serverSocket_); |
| 279 | } |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 280 | if (intSock1_ >= 0) { |
| 281 | ::close(intSock1_); |
| 282 | } |
| 283 | if (intSock2_ >= 0) { |
| 284 | ::close(intSock2_); |
| 285 | } |
Martin Kraemer | ee341cb | 2007-02-05 21:40:38 +0000 | [diff] [blame] | 286 | serverSocket_ = -1; |
Mark Slee | 561b536 | 2007-03-09 19:26:29 +0000 | [diff] [blame] | 287 | intSock1_ = -1; |
| 288 | intSock2_ = -1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 289 | } |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 290 | |
| 291 | }}} // facebook::thrift::transport |