Skip to contentSkip to conversation

sending data on a socket followed by a close

DISCUSSION Lee Chin 5 participants 5 messages Aug 27, 2003 – Aug 29, 2003

lore
Share & tools
lore

Lee Chin

author
#0 lore raw

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

Thanks
Lee

Signature · 6 lines
__________________________________________________________
Sign-up for your own personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers
#1 lore raw
Quoted 5 lines · On Wed, 27 Aug 2003 19:35:52 -0500 "Lee Chin" <[email protected]> wrote:

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

You cannot close() the socket until you have emptied all
the data bytes on the read side of the socket(), if data remains on the read side when you close() a TCP RST packet
is sent.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#2 lore raw

Receiver (in ur discussion) should be sending the RST not the sender. But ur explaination seems to hint that the sender of data is the one sending RST.

tomar

Quoted 11 lines · David S. Miller
Quoted 3 lines · On Wed, 27 Aug 2003 19:35:52 -0500 "Lee Chin" <[email protected]> wrote:

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.

Quoted 2 lines

What am I doing wrong? I though that the close would actually kill

the socket after all the data has been sent

Quoted 9 lines

You cannot close() the socket until you have emptied all
the data bytes on the read side of the socket(), if data remains on the read side when you close() a TCP RST packet is sent.
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

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

#3 lore raw
In reply to Lee Chin

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

Quoted 15 lines · Lee Chin

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

Thanks
Lee

Signature · 10 lines
Stephen Samuel +1(604)876-0426                [email protected]
		   http://www.bcgreen.com/~samuel/
   Powerful committed communication. Transformation touching
       the jewel within each person and bring it to life.

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

Il giorno Thu, Aug 28, 2003 at 10:03:14PM -0700, pare che Stephen Samuel abbia scritto:

Quoted 11 lines

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.

Quoted 19 lines

man 7 socket
for more info

Quoted 15 lines · Lee Chin

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs