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.

{
int old_flags, new_flags, myRC;
SOCKLEN_t myRClen = sizeof(myRC);
// If no timeout wanted, do a plain connect() which will timeout after 3
// minutes on most platforms.
//
if (!tsec)
{if (connect(fd, name, namelen)) return errno;
return 0;
}
// If a timeout is wanted, then we must convert this file descriptor to be
// non-blocking so that if a connection is not made immediately we can get
// control back and poll for completion for the specified amount of time.
// Regardless of outcome we will restore the original fd settings.
//
old_flags = fcntl(fd, F_GETFL, 0);
new_flags = old_flags | O_NDELAY | O_NONBLOCK;
fcntl(fd, F_SETFL, new_flags);
if (!connect(fd, name, namelen)) myRC = 0;
else if (EINPROGRESS != net_errno) myRC = net_errno;
else {struct pollfd polltab = {fd, POLLOUT|POLLWRNORM, 0};
do {myRC = poll(&polltab, 1, tsec*1000);}
while(myRC < 0 && errno == EINTR);
if (myRC != 1) myRC = ETIMEDOUT;
else getsockopt(fd,SOL_SOCKET,SO_ERROR,(Sokdata_t)&myRC,&myRClen);
}
fcntl(fd, F_SETFD, old_flags);
return myRC;
}
net_errno
#define net_errno
Definition XrdSysPlatform.hh:293
SOCKLEN_t
#define SOCKLEN_t
Definition XrdSysPlatform.hh:269
Sokdata_t
#define Sokdata_t
Definition XrdSysPlatform.hh:289

References net_errno, SOCKLEN_t, and Sokdata_t.

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

Here is the caller graph for this function:

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

- XrdNetConnect.hh
- XrdNetConnect.cc