Date: Fri, 5 Jul 2019 08:28:20 +0200 (CEST) From: Wojciech Puchar <wojtek@puchar.net> To: freebsd-hackers@freebsd.org Subject: quite simple network question Message-ID: <alpine.BSF.2.20.1907050823110.9847@puchar.net>
next in thread | raw e-mail | index | archive | help
i wrote a program with client and server part - running under FreeBSD. Client program use socket, then connect to establish TCP connection to server. then it uses select every now and then to check if anything came from server, when select returns nonzero recv is executed. If recv returns negative or zero - connection error is assumed, close is called and disconnect reported to user. This works almost properly: a) reception works fine b) when server disconnects it's detected and reported. But if network fails (for simulating i simply turn ethernet interface off) it doesn't see it for a long time. so between socket and connect i added a=1; setsockopt(serverconnfd,SOL_SOCKET,SO_KEEPALIVE,&a,sizeof(a)); a=5; //KEEPALIVE co 5 sekund setsockopt(serverconnfd,SOL_SOCKET,TCP_KEEPIDLE,&a,sizeof(a)); setsockopt(serverconnfd,SOL_SOCKET,TCP_KEEPINTVL,&a,sizeof(a)); a=2; //2 próby nim uzna że rozłączony setsockopt(serverconnfd,SOL_SOCKET,TCP_KEEPCNT,&a,sizeof(a)); and i assumed it will keepalive every 5 seconds and after 2 failures behave as disconnect. But even after minute of waiting i don't get disconnect. What i am doing wrong? From owner-freebsd-hackers@freebsd.org Fri Jul 5 06:39:58 2019 Return-Path: <owner-freebsd-hackers@freebsd.org> Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CED6715E6987 for <freebsd-hackers@mailman.ysv.freebsd.org>; Fri, 5 Jul 2019 06:39:58 +0000 (UTC) (envelope-from bakul@bitblocks.com) Received: from mail.bitblocks.com (ns1.bitblocks.com [173.228.5.8]) by mx1.freebsd.org (Postfix) with ESMTP id B60D3885A3 for <freebsd-hackers@freebsd.org>; Fri, 5 Jul 2019 06:39:57 +0000 (UTC) (envelope-from bakul@bitblocks.com) Received: from bitblocks.com (localhost [127.0.0.1]) by mail.bitblocks.com (Postfix) with ESMTP id 74E3E156E424; Thu, 4 Jul 2019 23:39:36 -0700 (PDT) To: Wojciech Puchar <wojtek@puchar.net> cc: freebsd-hackers@freebsd.org Subject: Re: quite simple network question In-reply-to: Your message of "Fri, 05 Jul 2019 08:28:20 +0200." <alpine.BSF.2.20.1907050823110.9847@puchar.net> References: <alpine.BSF.2.20.1907050823110.9847@puchar.net> Comments: In-reply-to Wojciech Puchar <wojtek@puchar.net> message dated "Fri, 05 Jul 2019 08:28:20 +0200." From: Bakul Shah <bakul@bitblocks.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22596.1562308776.1@bitblocks.com> Date: Thu, 04 Jul 2019 23:39:36 -0700 Message-Id: <20190705063943.74E3E156E424@mail.bitblocks.com> X-Rspamd-Queue-Id: B60D3885A3 X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; spf=pass (mx1.freebsd.org: domain of bakul@bitblocks.com designates 173.228.5.8 as permitted sender) smtp.mailfrom=bakul@bitblocks.com X-Spamd-Result: default: False [-5.19 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:173.228.5.8/29]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[bitblocks.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MX_GOOD(-0.01)[mail.bitblocks.com]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-0.88)[-0.881,0]; IP_SCORE(-2.10)[ip: (-6.44), ipnet: 173.228.0.0/20(-3.22), asn: 46375(-0.79), country: US(-0.06)]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:46375, ipnet:173.228.0.0/20, country:US]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD <freebsd-hackers.freebsd.org> List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-hackers>, <mailto:freebsd-hackers-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/freebsd-hackers/> List-Post: <mailto:freebsd-hackers@freebsd.org> List-Help: <mailto:freebsd-hackers-request@freebsd.org?subject=help> List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-hackers>, <mailto:freebsd-hackers-request@freebsd.org?subject=subscribe> X-List-Received-Date: Fri, 05 Jul 2019 06:39:59 -0000 On Fri, 05 Jul 2019 08:28:20 +0200 Wojciech Puchar <wojtek@puchar.net> wrote: > i wrote a program with client and server part - running under FreeBSD. > > Client program use socket, then connect to establish TCP connection to = > > server. > > then it uses select every now and then to check if anything came from = > > server, when select returns nonzero recv is executed. > > If recv returns negative or zero - connection error is assumed, close is = > > called and disconnect reported to user. > > > This works almost properly: > > a) reception works fine > b) when server disconnects it's detected and reported. > > > But if network fails (for simulating i simply turn ethernet interface off) > it doesn't see it for a long time. > > so between socket and connect i added > > a=3D1; > setsockopt(serverconnfd,SOL_SOCKET,SO_KEEPALIVE,&a,sizeof(a)); > a=3D5; //KEEPALIVE co 5 sekund > setsockopt(serverconnfd,SOL_SOCKET,TCP_KEEPIDLE,&a,sizeof(a)); > setsockopt(serverconnfd,SOL_SOCKET,TCP_KEEPINTVL,&a,sizeof(a)); > a=3D2; //2 pr=F3by nim uzna =BFe roz=B3=B1czony > setsockopt(serverconnfd,SOL_SOCKET,TCP_KEEPCNT,&a,sizeof(a)); > > and i assumed it will keepalive every 5 seconds and after 2 failures = > > behave as disconnect. > > But even after minute of waiting i don't get disconnect. > > What i am doing wrong? I believe you have to set the exceptfds argument to select() properly.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.20.1907050823110.9847>