Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <3E80F8E1.2000409@linuxforum.net> Date: Wed, 26 Mar 2003 08:48:33 +0800 From: David Huang User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: zh-cn, en-us, ja, en MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Failed non-blocking connect returns incorrect errno on AF_UNIX protocol Content-Type: multipart/mixed; boundary="------------050109010904080507020902" --------------050109010904080507020902 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Failed non-blocking connect returns incorrect errno on AF_UNIX protocol. See attached test program. On cygwin: $ ./afunix EINPROGRESS: Operation now in progress On Linux 2.4 (Debian 2.2) Linux 2.4 (Redhat 7.3) Sun Solaris (8): $ ./afunix ECONNREFUSED: Connection refused When i comment following code: // if (fcntl (fd2, F_SETFL, O_NONBLOCK) < 0) // printf ("Failed to set fd non-blocking"); The result is ECONNREFUSED: Connection refused It seems an old bug. I don't know whether it effect others address/protocol families. Thanks. --------------050109010904080507020902 Content-Type: text/plain; name="afunix.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="afunix.c" #include #include #include #include #include #include #include #include #include #include int main() { char file[] = "/tmp/.afunix"; int fd, fd2; int len; struct sockaddr_un address, address2; int status; int i = 0; status = unlink(file); if (status < 0 && errno != ENOENT) { printf("unlink() failed with %d\n", errno); return 1; } fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { printf("socket() failed with %d\n", errno); return 1; } memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; strcpy(address.sun_path, file); len = sizeof(address); status = bind(fd, (struct sockaddr*) &address, len); if (status < 0) { printf("bind() failed with %d\n", errno); return 1; } close(fd); // fd2 = socket(AF_UNIX, SOCK_STREAM, 0); if (fd2 < 0) { printf("socket() failed with %d\n", errno); return 1; } memset(&address2, 0, sizeof(address2)); address2.sun_family = AF_UNIX; strcpy(address2.sun_path, file); len = sizeof(address2.sun_family) + strlen(address2.sun_path) + 1; // set non-blocking if (fcntl (fd2, F_SETFL, O_NONBLOCK) < 0) printf ("Failed to set fd non-blocking"); do { status = connect (fd2, (struct sockaddr*)&address2, len); } while (status < 0 && errno == EINTR); if (status >= 0) printf("SOCKET_ALIVE\n"); else { switch (errno) { case EINPROGRESS: perror("EINPROGRESS"); break; case ECONNREFUSED: perror("ECONNREFUSED"); break; case EAGAIN: perror("EAGAIN\n"); break; case EBADF: printf("EBADF - Bad bug fd %d\n", fd); break; default: printf("Error '%s' on socket %d", strerror (errno), fd); break; } } return 0; } --------------050109010904080507020902 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --------------050109010904080507020902--