From owner-freebsd-bugs@freebsd.org Thu Dec 8 12:43:57 2016 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 532A4C6D8B1 for ; Thu, 8 Dec 2016 12:43:57 +0000 (UTC) (envelope-from dimitri.staessens@intec.ugent.be) Received: from smtp2.ugent.be (smtp2.ugent.be [157.193.49.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 13BB9983 for ; Thu, 8 Dec 2016 12:43:56 +0000 (UTC) (envelope-from dimitri.staessens@intec.ugent.be) Received: from localhost (mcheck3.ugent.be [157.193.71.89]) by smtp2.ugent.be (Postfix) with ESMTP id 91675B259C for ; Thu, 8 Dec 2016 13:43:46 +0100 (CET) X-Virus-Scanned: by UGent DICT Received: from smtp2.ugent.be ([157.193.49.126]) by localhost (mcheck3.ugent.be [157.193.43.11]) (amavisd-new, port 10024) with ESMTP id XsaaO1TXH5e9 for ; Thu, 8 Dec 2016 13:43:46 +0100 (CET) Received: from mail2.intec.ugent.be (mail2.intec.ugent.be [157.193.214.245]) by smtp2.ugent.be (Postfix) with ESMTP id 26140B22FF for ; Thu, 8 Dec 2016 13:43:46 +0100 (CET) Received: from [10.10.131.46] (hal.ilabt.iminds.be [193.191.148.129]) (using TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: dstaesse) by mail2.intec.ugent.be (Postfix) with ESMTPSA id 0CE372C for ; Thu, 8 Dec 2016 13:43:46 +0100 (CET) To: freebsd-bugs@freebsd.org From: Dimitri Staessens Subject: Call to accept() does not time out when setting SO_RCVTIMEO on a socket Message-ID: <76cee3a4-18d0-1f8c-eda3-e19c496c39b6@intec.ugent.be> Date: Thu, 8 Dec 2016 13:41:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 X-Miltered: at jchkm3 with ID 58495582.000 by Joe's j-chkmail (http://helpdesk.ugent.be/email/)! X-j-chkmail-Enveloppe: 58495582.000 from mail2.intec.ugent.be/mail2.intec.ugent.be/157.193.214.245/mail2.intec.ugent.be/ X-j-chkmail-Score: MSGID : 58495582.000 on smtp2.ugent.be : j-chkmail score : . : R=. U=. O=. B=0.000 -> S=0.000 X-j-chkmail-Status: Ham Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Dec 2016 12:43:57 -0000 Dear devs, I'm trying to get an accept() call to time out using setsockopt. On Linux, the example below terminates: [dstaesse@phoneutria]$ gcc accept_st.c -o accept_st [dstaesse@phoneutria]$ ./accept_st Timeout is 0:100000. Check is 0:103333. Accept returned: Resource temporarily unavailable. Accept returned: Resource temporarily unavailable. Accept returned: Resource temporarily unavailable. Bye. On FreeBSD 11.0-RELEASE however, it hangs on the accept() forever. Is this a known issue? Thanks for your help, Dimitri --- example source: #define _POSIX_C_SOURCE 200809L #include #include #include #include #include #include #include #include #define TIMEOUT 100 /* ms */ #define RUNNING 0 #define SHUTDOWN 1 #define FN "/tmp/accept_st_socket" int sfd; void main(void) { int count = 0; int cfd; struct timeval tv = {(TIMEOUT / 1000), (TIMEOUT % 1000) * 1000}; struct timeval check; socklen_t len = sizeof(check); struct sockaddr_un serv_addr; printf("Timeout is %lu:%lu.\n", tv.tv_sec, tv.tv_usec); sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd < 0) { printf("Failed to open socket: %s.\n", strerror(errno)); exit(EXIT_FAILURE); } if (access(FN, F_OK) != -1) { /* File exists */ if (unlink(FN)) exit(EXIT_FAILURE); } serv_addr.sun_family = AF_UNIX; sprintf(serv_addr.sun_path, "%s", FN); if (bind(sfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))) { printf("Failed to bind socket: %s.\n", strerror(errno)); close(sfd); exit(EXIT_FAILURE); } if (listen(sfd, 0)) { printf("Failed to listen on socket: %s.\n", strerror(errno)); close(sfd); exit(EXIT_FAILURE); } if (setsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, (void *) &tv, len)) printf("Failed to set timeout on socket: %s.\n", strerror(errno)); getsockopt(sfd, SOL_SOCKET, SO_RCVTIMEO, &check, &len); printf("Check is %lu:%lu.\n", check.tv_sec, check.tv_usec); while (count < 3) { cfd = accept(sfd, 0, 0); printf("Accept returned: %s.\n", strerror(errno)); ++count; } printf("Bye.\n"); exit(EXIT_SUCCESS); } -- Dimitri Staessens Ghent University - imec Dept. of Information Technology (INTEC) Internet Based Communication Networks and Services Technologiepark 15 9052 Zwijnaarde T: +32 9 331 48 70 F: +32 9 331 48 99