This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

connect() returns wrong errno for non-blocking sockets


While porting an application to cygwin I've discovered the following
bug:

When calling connect on a non-blocking socket it returns -1 with errno set
to EAGAIN not EINPROGRESS.  In every UNIX OS I've tried this in 
EINPROGRESS is the correct errno for non-blocking connect() calls.

This is with cygwin 1.1.4.

Is this a known problem or how it was intended to be designed?

A short example is below (note that error checking return codes is being
done, but not shown in the example):

int nonblock = 1;
int s;
struct sockaddr_in saddr;
struct hostent *remotehost;
/* to_ip is a char* with remote host */
/* to_port is a char* with remote port number */

/* create a TCP socket */
s = socket( AF_INET, SOCK_STREAM, 0);

/* setup saddr */
remotehost = gethostbyname(to_ip);
bzero ((char *) &saddr, sizeof (saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(atoi(to_port));
memcpy(&saddr.sin_addr,
    *((struct in_addr **)remotehost->h_addr_list),
    sizeof(struct in_addr));

/* set non-blocking so connect wont block */
ioctl(s, FIONBIO, &nonblock);

connect(s, (struct sockaddr *) &saddr, sizeof(saddr));

/* connect returns -1 and sets errno to EAGAIN */

/* then go onto a select driven loop waiting for s to become
 * writable for either success or failure
 */



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]