public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
From: Marco Cova <marco.cova@studio.unibo.it>
To: Stephen Samuel <samuel@bcgreen.com>
Cc: Lee Chin <leechin@mail.com>,
	linux-newbie@vger.kernel.org, linux-net@vger.kernel.org
Subject: Re: sending data on a socket followed by a close
Date: Fri, 29 Aug 2003 00:44:30 -0500	[thread overview]
Message-ID: <20030829054429.GA1453@smith.cs.ucsb.edu> (raw)
In-Reply-To: <3F4EDE92.8020002@bcgreen.com>

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

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

      reply	other threads:[~2003-08-29  5:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-28  0:35 sending data on a socket followed by a close Lee Chin
2003-08-28  6:01 ` David S. Miller
2003-08-27 19:14   ` Nagendra Singh Tomar
2003-08-29  5:03 ` Stephen Samuel
2003-08-29  5:44   ` Marco Cova [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030829054429.GA1453@smith.cs.ucsb.edu \
    --to=marco.cova@studio.unibo.it \
    --cc=leechin@mail.com \
    --cc=linux-net@vger.kernel.org \
    --cc=linux-newbie@vger.kernel.org \
    --cc=samuel@bcgreen.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox