Date: Fri, 11 Apr 2003 13:44:16 -0600 (MDT) From: "M. Warner Losh" <imp@bsdimp.com> To: standards@freebsd.org Subject: Non-compliant FreeBSD behavior? Message-ID: <20030411.134416.71552075.imp@bsdimp.com>
next in thread | raw e-mail | index | archive | help
A number of places I've seen says that the BUGGY section should be identical to the else part. That is, setting O_NONBLOCK via fcntl should result in the same behavior as setting it using FIONBIO. However, I've observed that for both threaded and unthreaded programs the BUGGY part doesn't work, while the other part does. Is there something subtle I'm missing? What do the standards have to say about this? Warner #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <err.h> #include <fcntl.h> #include <stdio.h> int main(void) { int fd; struct in_addr addr; struct sockaddr_in sa; int flags; fd = socket(PF_INET, SOCK_STREAM, 0); inet_aton("1.2.3.4", &addr); sa.sin_len = sizeof(sa); sa.sin_family = AF_INET; sa.sin_port = htons(1234); memcpy(&sa.sin_addr, &addr, sizeof(addr)); #if BUGGY flags = fcntl(fd, F_GETFL, NULL); flags |= O_NONBLOCK; if (fcntl(fd, F_SETFL, &flags) == -1) err(1, "fcntl"); #else flags = 1; if (ioctl(fd, FIONBIO, &flags)) err(1, "ioctl"); #endif if (connect(fd, (struct sockaddr *) &sa, sizeof(sa))) err(1, "connect"); exit(0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030411.134416.71552075.imp>