From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 131014 invoked by alias); 13 Jun 2018 13:49:10 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 130837 invoked by uid 89); 13 Jun 2018 13:49:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=H*F:D*ne.jp, UD:jp, listen, 100000 X-HELO: conssluserg-01.nifty.com Received: from conssluserg-01.nifty.com (HELO conssluserg-01.nifty.com) (210.131.2.80) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Jun 2018 13:48:59 +0000 Received: from Express5800-S70 (ntsitm315127.sitm.nt.ngn.ppp.infoweb.ne.jp [125.3.30.127]) (authenticated) by conssluserg-01.nifty.com with ESMTP id w5DDms6K010117 for ; Wed, 13 Jun 2018 22:48:55 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-01.nifty.com w5DDms6K010117 X-Nifty-SrcIP: [125.3.30.127] Date: Wed, 13 Jun 2018 15:02:00 -0000 From: Takashi Yano To: cygwin@cygwin.com Subject: Problems of AF_INET domain socket regarding out-of-band data. Message-Id: <20180613224858.7822b08abb75d76b72920095@nifty.ne.jp> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Wed__13_Jun_2018_22_48_58_+0900_VUITj9uMjPPjbkfq" X-IsSubscribed: yes X-SW-Source: 2018-06/txt/msg00146.txt.bz2 --Multipart=_Wed__13_Jun_2018_22_48_58_+0900_VUITj9uMjPPjbkfq Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-length: 1594 Hello, I have found a few problems of AF_INET domain socket regarding out-of-band data. 1. recv() with MSG_OOB flag eats normal data if no OOB data is sent yet. 2. Calling recv() with MSG_OOB flag is blocked if no OOB data is sent yet. 3. Calling recv() without MSG_OOB flag after receiving OOB data is blocked even if received data exist in buffer. Regarding problem 1 and 2, POSIX states as follows about recv(). [EINVAL] The MSG_OOB flag is set and no out-of-band data is available. http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html Attached is a sample program to reproduce these problems. Argument to this program specifies the test mode. 0: cause problem 1 2: cause problem 2 3: cause problem 3 Expected results: debian:~/OOB> ./server_client 0 recv(OOB): Invalid argument OOB : (-1) NORMAL: 1234567890 (10) debian:~/OOB> ./server_client 1 OOB : A (1) NORMAL: 1234567890 (10) debian:~/OOB> ./server_client 2 recv(OOB): Invalid argument OOB : (-1) NORMAL: 1234567890 (10) debian:~/OOB> ./server_client 3 OOB : A (1) NORMAL: 1234567890 (10) debian:~/OOB> Result on cygwin: [yano@Express5800-S70 ~/OOB]$ ./server_client 0 OOB : 1234567890 (10) NORMAL: (0) [yano@Express5800-S70 ~/OOB]$ ./server_client 1 OOB : A (1) NORMAL: 1234567890 (10) [yano@Express5800-S70 ~/OOB]$ ./server_client 2 [yano@Express5800-S70 ~/OOB]$ ./server_client 3 OOB : A (1) [yano@Express5800-S70 ~/OOB]$ Only the result of test mode 1 is as expected. I have confirmed this occurs in both latest 32bit and 64 bit cygwin. -- Takashi Yano --Multipart=_Wed__13_Jun_2018_22_48_58_+0900_VUITj9uMjPPjbkfq Content-Type: text/x-csrc; name="server_client.c" Content-Disposition: attachment; filename="server_client.c" Content-Transfer-Encoding: 7bit Content-length: 2632 #include #include #include #include #include #include #include #include #include #include #define PORT 12345 #define HOST "127.0.0.1" int server(int mode) { int sock0, sock1; struct sockaddr_in addr; struct sockaddr_in client; socklen_t len; /* Create a socket */ sock0 = socket(AF_INET, SOCK_STREAM, 0); if (sock0 < 0) { perror("socket"); return -1; } /* Bind */ addr.sin_family = AF_INET; addr.sin_port = htons(PORT); addr.sin_addr.s_addr = INADDR_ANY; if (bind(sock0, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("bind"); return -1; } /* Wait for connection from client */ if (listen(sock0, 1) < 0) { perror("listen"); return -1; } /* Accept connection */ len = sizeof(client); sock1 = accept(sock0, (struct sockaddr *)&client, &len); if (sock1 < 0) { perror("accept"); return -1; } /* Send normal data */ if (send(sock1, "1234567890", 10, 0) < 0) { perror("send"); return -1; } if (mode & 1) { /* Send out-of-band data */ if (send(sock1, "A", 1, MSG_OOB) < 0) { perror("send(OOB)"); return -1; } } /* Wait for receiving all data at client side */ usleep(200000); if (mode & 2) { return -1; /* return -1 to kill client */ } /* Close client socket */ close(sock1); /* Close socket for listen */ close(sock0); return 0; } int client() { struct sockaddr_in server; int sock; char buf[256]; int n; /* Create a socket */ sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { perror("sock"); return -1; } /* Setting for connection */ server.sin_family = AF_INET; server.sin_port = htons(PORT); server.sin_addr.s_addr = inet_addr(HOST); /* Connect to server */ if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0) { perror("connect"); return -1; } /* Wait for sending all data at server side */ usleep(100000); /* Receive out-of-band data from server */ memset(buf, 0, sizeof(buf)); n = recv(sock, buf, sizeof(buf), MSG_OOB); if (n<0) { perror("recv(OOB)"); } printf("OOB : %s (%d)\n", buf, n); /* Receive normal data from server */ memset(buf, 0, sizeof(buf)); n = recv(sock, buf, sizeof(buf), 0); if (n<0) { perror("recv"); } printf("NORMAL: %s (%d)\n", buf, n); /* Close socket */ close(sock); return 0; } int main(int argc, char *argv[]) { int mode = 0; pid_t pid; if (argc >= 2) { mode = atoi(argv[1]); } pid = fork(); if (pid) { if (server(mode) < 0) kill(pid, SIGTERM); wait(NULL); } else { return client(); } return 0; } --Multipart=_Wed__13_Jun_2018_22_48_58_+0900_VUITj9uMjPPjbkfq Content-Type: text/plain; charset=us-ascii Content-length: 219 -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple --Multipart=_Wed__13_Jun_2018_22_48_58_+0900_VUITj9uMjPPjbkfq--