From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: How to notice abrupt tcp connection losses in server/client? Date: Thu, 21 Jun 2018 08:22:36 +0200 Message-ID: <9201c7c2-6a97-f3ce-5b5a-9e1810bca8b9@gmail.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1529562076 16135 195.159.176.226 (21 Jun 2018 06:21:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 21 Jun 2018 06:21:16 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Jun 21 08:21:12 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fVsy0-00045z-7l for guile-user@m.gmane.org; Thu, 21 Jun 2018 08:21:12 +0200 Original-Received: from localhost ([::1]:53229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVt07-00088n-FY for guile-user@m.gmane.org; Thu, 21 Jun 2018 02:23:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVszR-00085q-Ag for guile-user@gnu.org; Thu, 21 Jun 2018 02:22:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVszQ-0007Vs-0Z for guile-user@gnu.org; Thu, 21 Jun 2018 02:22:41 -0400 Original-Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:56249) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fVszP-0007VV-Lz for guile-user@gnu.org; Thu, 21 Jun 2018 02:22:39 -0400 Original-Received: by mail-wm0-x22f.google.com with SMTP id v16-v6so3072282wmh.5 for ; Wed, 20 Jun 2018 23:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=XWJkHygTsRmzG0FIg0o6PwgIwyo7A68374bbbRPp0gI=; b=F4+uebVuAvdr3JVfaifN9D3wUNLINT0ng9L8q/d3luSZVQSGATnyxWoHdYZhVIyUwv Z6oNwS42oAt+8J/IkpRQl5ukjzFyI5oQT4uSu9F2T2wALuzDAhpULJ4lSg9yPurXIebQ t7NEcUEoK9bHFWx/p+7d0Olv2xQTy5nXIQjfZsZbV0Bt/DA1uAFDhwurgoeyhevwehpz fnomHzV8AfYR0tPp9MXLAUaqf9C0aFnjl1j/z46MTAkPvA1ZcIA2SFdt/DGEcICZIxWr HQhhcfX7hSHvk88m8Qk7p2bI9/iAEuehac9UlNuoQo5/Y4xRkugBWdSqHg018KGYtsnL ZAzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=XWJkHygTsRmzG0FIg0o6PwgIwyo7A68374bbbRPp0gI=; b=FMqTMLzJZ5OdeAvYFPVYRq7ZMYyJzqm2w75Nbq6irmXsI6ogkGXKzzx02yAa6fhxpU vHjOu3l6yTPF57eVAZdNeXVU1o3c9ZX9az/WRjRiyl9wQTzwuqOkCST+nCH5Jgk01Axc VB1F/CW378WgN//1T3/22GSmjJ63aEOVIQeqsOoBAMtdAAzU1/ReW7Q3Y1kZtpS7ZnbT wraoyrA8dBenHPQbQ4l7l2rArLzABE645SFJcw/SLBFOQdE9sRamWThO5BBLIEzoN5yL 7XzLuoiSKNtHfT8SZ1sPj1q46zPw9nThBfaHnyyJpAZeOf2cbnBG283DSiaK0JutKnIL kkwg== X-Gm-Message-State: APt69E3lr8lMp4V3kO5tdE7HQrtTyWgTlz+WbdABabbXYyptq4BDvdon FFmWdUy5nmj2uLN8fQAPk+B6KA== X-Google-Smtp-Source: ADUXVKLgC08vyNEkB0OVMJzUP8P5JROgC09w29YobcWAv0gk5Fz9UhPQF0wIWpNuHxECcY5v129swg== X-Received: by 2002:a1c:8410:: with SMTP id g16-v6mr3893947wmd.26.1529562158149; Wed, 20 Jun 2018 23:22:38 -0700 (PDT) Original-Received: from ?IPv6:2a02:8109:ad3f:ec78:9cd4:8f89:64eb:adcf? ([2a02:8109:ad3f:ec78:9cd4:8f89:64eb:adcf]) by smtp.googlemail.com with ESMTPSA id e4-v6sm5533892wrq.4.2018.06.20.23.22.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 23:22:37 -0700 (PDT) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22f X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14638 Archived-At: Hello Guile users, I wrote some TCP server and client in Guile which I have uploaded here: https://gitlab.com/zelphir-kaltstahl-projects/guile-scheme-tutorials-and-examples/raw/dev/network-programming/tcp-client.scm and here: https://gitlab.com/zelphir-kaltstahl-projects/guile-scheme-tutorials-and-examples/raw/dev/network-programming/tcp-server.scm or normal GitLab view: https://gitlab.com/zelphir-kaltstahl-projects/guile-scheme-tutorials-and-examples/tree/dev/network-programming (Is it OK to post these as links, or always better to include all relevant source code on the mailing list? On other e-mail lists I have experienced that my message was too long and got truncated, so I posted the code as links to the raw file on GitLab.) The loop for reacting on messages from a client on the server looks like this: (while #t (let* ([bytes-count (recv! in-out-sock receive-buffer)] [message-received (byte-vector->utf8-message receive-buffer bytes-count)]) (message-handler client-connection message-received)))))) But this has a problem: When I run both client and server in two terminals and then exit the client using Ctrl-D, the server somehow gets stuck in the loop always receiving the empty string. Since that is 0 Bytes long, it does not really take anything from the socket (if I understand correctly), but instead can recv! in the next iteration again immediately. The only thing that works then for stopping this loop is to hold down Ctrl-C on the server for a second or so. The same happens for the client receiving message loop, because that one also does not detect me suddenly interrupting or killing the server and then loops on the empty string. At first I thought if I caught eof-object? and then (break) the loop it would solve the problem, but apparently it does not. Basically I would like the server and client to be prepared for non proper shutdown of either. How can I handle / detect abrupt connection losses, so that I can break the message handling loop? On 20.06.2018 18:00, guile-user-request@gnu.org wrote: > Send guile-user mailing list submissions to > guile-user@gnu.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.gnu.org/mailman/listinfo/guile-user > or, via email, send a message with subject or body 'help' to > guile-user-request@gnu.org > > You can reach the person managing the list at > guile-user-owner@gnu.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of guile-user digest..." > > > Today's Topics: > > 1. Re: lat? and atom? not in guile? (Thompson, David) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 20 Jun 2018 10:55:43 -0400 > From: "Thompson, David" > To: John Cowan > Cc: Joshua Branson , Guile User > > Subject: Re: lat? and atom? not in guile? > Message-ID: > > Content-Type: text/plain; charset="UTF-8" > > On Wed, Jun 20, 2018 at 10:40 AM, John Cowan wrote: >> On Wed, Jun 20, 2018 at 10:37 AM, Joshua Branson >> wrote: >> >> >>> Oh hey David! Thanks for the explanation! Maybe I need to take another >>> look at that book then. I found it a little repetitive, but I am >>> probably not quite grasping some of the fundamentals. >>> >> It's meant to be repetitive. It's explicitly compared in the introduction >> to Hanon's finger exercises for the piano: C-E-F-G-A-G-F-E, >> D-F-G-A-B-A-G-F, E-G-A-B-C-B-A-D and so on forever, up the scale and down >> in every key. Boring as hell, but just the thing to get fluency into your >> fingers. > It's repetitive but honestly I found that the comedic writing made the > exercises very entertaining. I was rarely bored. I don't play the > piano, but I do play drums, and the equivalent to Hanon's finger > exercises is an old book called Stick Control, which is definitely in > the boring as hell category! I'm glad that Lisp beginners have > something more fun available. :) > > - Dave > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > guile-user mailing list > guile-user@gnu.org > https://lists.gnu.org/mailman/listinfo/guile-user > > > ------------------------------ > > End of guile-user Digest, Vol 187, Issue 14 > *******************************************