MCPcopy Create free account
hub / github.com/apache/thrift / openConnection

Method openConnection

lib/cpp/src/thrift/transport/TSocket.cpp:269–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269void TSocket::openConnection(struct addrinfo* res) {
270
271 if (isOpen()) {
272 return;
273 }
274
275 if (isUnixDomainSocket()) {
276 socket_ = socket(PF_UNIX, SOCK_STREAM, IPPROTO_IP);
277 } else {
278 socket_ = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
279 }
280
281 if (socket_ == THRIFT_INVALID_SOCKET) {
282 int errno_copy = THRIFT_GET_SOCKET_ERROR;
283 TOutput::instance().perror("TSocket::open() socket() " + getSocketInfo(), errno_copy);
284 throw TTransportException(TTransportException::NOT_OPEN, "socket()", errno_copy);
285 }
286
287 // Send timeout
288 if (sendTimeout_ > 0) {
289 setSendTimeout(sendTimeout_);
290 }
291
292 // Recv timeout
293 if (recvTimeout_ > 0) {
294 setRecvTimeout(recvTimeout_);
295 }
296
297 if (keepAlive_) {
298 setKeepAlive(keepAlive_);
299 }
300
301 // Linger
302 setLinger(lingerOn_, lingerVal_);
303
304 // No delay
305 setNoDelay(noDelay_);
306
307#ifdef SO_NOSIGPIPE
308 {
309 int one = 1;
310 setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one));
311 }
312#endif
313
314// Uses a low min RTO if asked to.
315#ifdef TCP_LOW_MIN_RTO
316 if (getUseLowMinRto()) {
317 int one = 1;
318 setsockopt(socket_, IPPROTO_TCP, TCP_LOW_MIN_RTO, &one, sizeof(one));
319 }
320#endif
321
322 // Set the socket to be non blocking for connect if a timeout exists
323 int flags = THRIFT_FCNTL(socket_, THRIFT_F_GETFL, 0);
324 if (connTimeout_ > 0) {
325 if (-1 == THRIFT_FCNTL(socket_, THRIFT_F_SETFL, flags | THRIFT_O_NONBLOCK)) {
326 int errno_copy = THRIFT_GET_SOCKET_ERROR;

Callers 1

flushMethod · 0.80

Calls 4

fillUnixSocketAddrFunction · 0.85
TTransportExceptionClass · 0.70
cast_sockoptFunction · 0.70
perrorMethod · 0.45

Tested by

no test coverage detected