Return to BSD News archive
Xref: sserve comp.unix.programmer:15457 comp.unix.bsd:13518 Newsgroups: comp.unix.programmer,comp.unix.bsd Path: sserve!newshost.anu.edu.au!munnari.oz.au!ihnp4.ucsd.edu!swrinde!elroy.jpl.nasa.gov!ncar!noao!rstevens From: rstevens@noao.edu (W. Richard Stevens) Subject: Re: Detecting dead client in BSD socket Message-ID: <1994Mar5.142417.28947@noao.edu> Keywords: socket bsd death Sender: news@noao.edu Nntp-Posting-Host: gemini.tuc.noao.edu Organization: National Optical Astronomy Observatories, Tucson, AZ, USA References: <1994Mar3.154852.24090@il.us.swissbank.com> <2l92ia$hrd@u.cc.utah.edu> Date: Sat, 5 Mar 1994 14:24:17 GMT Lines: 39 > > Is there a way to determine, from the server side, whether a client has > > closed its end of the connection in a BSD socket? > > Set SO_KEEPALIVE as an option and notification will be more immediate; be > sure and use select on the socket and check for exceptional conditions. Check for "readability" not an "exception" condition. If the other end dies, or dies and reboots, your socket will become readable after the keepalive probe(s) are sent; issue a read, and the error will probably be ETIMEDOUT or ECONNRESET. Check Chapter 23 of my recent book "TCP/IP Illustrated" for lots of information on keepalives. (This chapter is also reprinted in the Feb. 94 issue of Interop's ConneXions.) If you're going to use keepalives, you need to understand how they're implemented by TCP, regardless whether you use sockets or TLI. > On the other hand, if it's a socket library on top of TLI and your UNIX > obeys the notification protocol, Socket libraries on systems such as SVR4 are *not* built on top of TLI. This is a fundamental misconception that is continually repeated. Sockets are built on top of TPI, the "Transport Provider Interface", a spec you can ftp from ftp.ui.org in pub/osi/tpi.ps. The socket library talks to TPI just like TLI does. Both require a special kernel streams module to help: sockmod and timod. (Rago correctly talks about this in Section 12.3 of his book "UNIX System V Network Programming".) TLI may be "closer" to TPI than sockets (since they're both made to look OSI-ish) but to say that sockets in SVR4 are built on top is TLI is plain wrong. > rewriting directly to TLI will let you > not only run on other protocol stacks (XNS, IPX, OSI, etc.), it will > provide disconnect notification. Ah, but protocol independence does have its price, doesn't it :-) Using sockets I can get or set the SO_KEEPALIVE option with 3 lines of code (assignment, function call, error handling). Please show the equivalent TLI code. I am especially interested in your implementation of getsockopt() using TLI (not XTI). Rich Stevens (rstevens@noao.edu)