36 #include <sys/types.h>
37 #include <sys/socket.h>
48 const struct sockaddr *name,
52 int old_flags, new_flags, myRC;
59 {
if (connect(fd, name, namelen))
return errno;
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;
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);
79 fcntl(fd, F_SETFD, old_flags);
int fcntl(int fd, int cmd,...)
static int Connect(int fd, const struct sockaddr *name, int namelen, int tsec=-1)