XRootD
Loading...
Searching...
No Matches
XrdNetConnect Class Reference

#include <XrdNetConnect.hh>

+ Collaboration diagram for XrdNetConnect:

Static Public Member Functions

static int Connect (int fd, const struct sockaddr *name, int namelen, int tsec=-1)
 

Detailed Description

Definition at line 40 of file XrdNetConnect.hh.

Member Function Documentation

◆ Connect()

int XrdNetConnect::Connect ( int  fd,
const struct sockaddr *  name,
int  namelen,
int  tsec = -1 
)
static

Definition at line 47 of file XrdNetConnect.cc.

51{
52 int old_flags, new_flags, myRC;
53 SOCKLEN_t myRClen = sizeof(myRC);
54
55// If no timeout wanted, do a plain connect() which will timeout after 3
56// minutes on most platforms.
57//
58 if (!tsec)
59 {if (connect(fd, name, namelen)) return errno;
60 return 0;
61 }
62
63// If a timeout is wanted, then we must convert this file descriptor to be
64// non-blocking so that if a connection is not made immediately we can get
65// control back and poll for completion for the specified amount of time.
66// Regardless of outcome we will restore the original fd settings.
67//
68 old_flags = fcntl(fd, F_GETFL, 0);
69 new_flags = old_flags | O_NDELAY | O_NONBLOCK;
70 fcntl(fd, F_SETFL, new_flags);
71 if (!connect(fd, name, namelen)) myRC = 0;
72 else if (EINPROGRESS != net_errno) myRC = net_errno;
73 else {struct pollfd polltab = {fd, POLLOUT|POLLWRNORM, 0};
74 do {myRC = poll(&polltab, 1, tsec*1000);}
75 while(myRC < 0 && errno == EINTR);
76 if (myRC != 1) myRC = ETIMEDOUT;
77 else getsockopt(fd,SOL_SOCKET,SO_ERROR,(Sokdata_t)&myRC,&myRClen);
78 }
79 fcntl(fd, F_SETFD, old_flags);
80 return myRC;
81}
int fcntl(int fd, int cmd,...)
#define net_errno
#define SOCKLEN_t
#define Sokdata_t

References fcntl(), net_errno, SOCKLEN_t, and Sokdata_t.

Referenced by XrdCl::Socket::ConnectToAddress(), and XrdNetSocket::Open().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: