Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com To: "cygwin AT sourceware DOT cygnus DOT com" Subject: non-blocking socket? X-Mailer: Mew version 1.94.1 on Emacs 20.4 / Mule 4.1 (AOI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20000411191156A.tau@entropia.com> Date: Tue, 11 Apr 2000 19:11:56 +0800 (GMT) From: tau AT entropia DOT com X-Dispatcher: imput version 990905(IM130) Lines: 72 Hi, I am wondering there is any way to use a non-blocking receive in cygwin programs. I don't care if it is winsock or unix emulation socket. From what we learned from cygwin faq, I tried the following program but it still appears to block. I appreciate if non-blocking socket is supposed to work and if so, how to use it. Thanks. ------------------ prompt% gcc nb.c -lwsock32 prompt% ./a.exe now try to receive from port 30000 < ... blocking ... > ------------------ #define Win32_Winsock 1 #include #define PORT 30000 main(int argc, char **argv) { int s; int flags; struct sockaddr_in from; #define N 100 char buf[N]; { WORD wVersionRequested = MAKEWORD( 1, 1 ); WSADATA wsaData[1]; if (WSAStartup(wVersionRequested, wsaData) != 0) { printf("WSAStartup failed\n"); } } if ((s = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { printf("socket failed\n"); exit(1); } { /* winsock function to make it non-blocking */ unsigned long a[1]; int e = ioctlsocket(s, FIONBIO, a); if (e == -1) { printf("ioctlsocket failed\n"); exit(1); } } memset(&from, '\0', sizeof(from)); from.sin_family = AF_INET; from.sin_addr.s_addr = htonl(INADDR_ANY); from.sin_port = htons((u_short)PORT); if (bind(s, (struct sockaddr *)&from, sizeof(from)) == -1) { printf("bind failed\n"); exit(1); } { struct sockaddr_in addr; int flen = sizeof(struct sockaddr_in); int _ = printf("now try to receive from port %d\n", PORT); int l = recvfrom(s, buf, N, 0, (struct sockaddr *)&addr, &flen); printf("OK: l = %d\n", l); } } -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com