Re: sending data on a socket followed by a close

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Il giorno Thu, Aug 28, 2003 at 10:03:14PM -0700, pare che Stephen Samuel abbia scritto:
> Rather than using close, try calling shutdown (2)...
> (dunno if it will work).
> 
> If that doesn't work, then use the socket option  SO_LINGER
> 
> SO_LINGER     When enabled, a close(2) or shutdown(2) will  not  return
>               until all  queued  messages for the socket have been
>               successfully sent or the linger timeout has  been  reached.
>               Otherwise,  the  call returns  immediately  and the closing
>               is done in the background.
> 
> man 7 socket
>   for more info
> 
> Lee Chin wrote:
> >Hi,
> >I am trying to send 500K on a asynchronous socket and after I've written 
> >all my data, I want to close the socket.
> >
> >So I send data in a loop, and between calls to "write" I select on the 
> >filedescriptor till it is writable again and send more data.
> >
> >I continue this untill I have no more data to send.
> >
> >At the end, after sending all my data, I "close" the socket.
> >
> >However, the client sees a TCP RST packet and only receives partial data.
> >
> >What am I doing wrong?  I though that the close would actually kill the 
> >socket after all the data has been sent

RST on close is what you get if you set the SO_LINGER option for the
socket with l_onoff = 1 and l_linger = 0 (and the socket reference
count has dropped to 0).

You can find a complete description of the different choices you have for
closing a connection in Stevens, "UNIX Network Programming", pag
187-191.

HTH,
Marco

-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux