Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #38972

Re: server-side Socket does not recognize broken connection.

From Andreas Leitgeb <avl@logic.at>
Newsgroups comp.lang.java.programmer
Subject Re: server-side Socket does not recognize broken connection.
Date 2019-05-29 14:50 +0000
Organization A noiseless patient Spider
Message-ID <slrnqet716.cfl.avl@logic.at> (permalink)
References <slrnqespnm.cfl.avl@logic.at> <1v9ncmqz4ep4j$.1mdftm8twalol$.dlg@40tude.net>

Show all headers | View raw


Joerg Meier <joergmmeier@arcor.de> wrote:
> On Wed, 29 May 2019 11:03:18 -0000 (UTC), Andreas Leitgeb wrote:
>> PS: The real code does more interesting stuff while no input is available,
>> so it cannot wait blockingly.  The real code also has other exits from the
>> loop (based on input received), but that's not relevant for this SSCCE.
> In addition to Erics excellent answer,

Thanks also to Eric!

> I would like to add that I'm pretty
> certain that you can not write code like that without resorting to
> blocking.

Watching the Java server with strace (on linux), I see that Java calls
the system:
  ioctl(6, FIONREAD, [0])     = 0

Now I'm going to read up on why this syscall wouldn't report a broken socket,
and what other syscall (short of actually reading and risking to block)
would allow me to tell idle from broken.

Calling "lsof" on the Java process' pid shows that the OS does know the
socket is broken:
java    29340  avl    6u  IPv6          113368285       0t0       TCP
   localhost:65432->localhost:58500 (CLOSE_WAIT)

> You may want to look at NIO or higher level frameworks if you can
> not astract the blocking aspect away on your own for some reason.

A separate thread to read blockingly and shovel the results into a 
Queue (as Eric suggested) is plausible, assuming that it works. 
Trying to replace inputStreams by nio is also on my "TO CHECK" list.

Thanks anyway for pointing me in the direction that available() alone
just isn't designed to recognize broken sockets.

I consider my question answered. Thanks!

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

server-side Socket does not recognize broken connection. Andreas Leitgeb <avl@logic.at> - 2019-05-29 11:03 +0000
  Re: server-side Socket does not recognize broken connection. Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-05-29 08:30 -0400
  Re: server-side Socket does not recognize broken connection. Joerg Meier <joergmmeier@arcor.de> - 2019-05-29 14:58 +0200
    Re: server-side Socket does not recognize broken connection. Andreas Leitgeb <avl@logic.at> - 2019-05-29 14:50 +0000
      Re: server-side Socket does not recognize broken connection. Eric Douglas <e.d.programmer@gmail.com> - 2019-05-29 08:22 -0700
        Re: server-side Socket does not recognize broken connection. Andreas Leitgeb <avl@logic.at> - 2020-01-30 15:22 +0000
      Re: server-side Socket does not recognize broken connection. Martin Gregorie <martin@mydomain.invalid> - 2019-05-29 16:06 +0000
  Re: server-side Socket does not recognize broken connection. Eric Douglas <e.d.programmer@gmail.com> - 2019-05-29 07:14 -0700
  Re: server-side Socket does not recognize broken connection. trisha guillot <guillottrisha347@gmail.com> - 2019-05-31 20:13 -0700
  Re: server-side Socket does not recognize broken connection. Marcel Mueller <news.5.maazl@spamgourmet.org> - 2019-06-01 16:08 +0200

csiph-web