Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Can gen_tcp:close() close a socket which is still sending?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Haugeland  
View profile  
 More options Jun 13 2009, 9:08 pm
From: John Haugeland <stonecyp...@gmail.com>
Date: Sat, 13 Jun 2009 19:08:45 -0600
Local: Sat, Jun 13 2009 9:08 pm
Subject: [erlang-questions] Can gen_tcp:close() close a socket which is still sending?
I have a defect that I don't fully understand.  When I dispatch
something by gen_tcp:send(...), I follow through with :close().
However, there's a sporadic pattern of the data getting cut off early.
 If I inject a delay between them, the problem disappears.

This seems to imply that :close() can close a socket which is still
sending data.  That isn't what I would have expected by comparison
from other languages, so I'm not entirely convinced I've understood
this correctly.

Is it safe to call :close() immediately after a large :send()?  If
not, what does one do instead?

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Rogvall  
View profile  
 More options Jun 14 2009, 6:03 am
From: Tony Rogvall <t...@rogvall.se>
Date: Sun, 14 Jun 2009 12:03:52 +0200
Local: Sun, Jun 14 2009 6:03 am
Subject: Re: [erlang-questions] Can gen_tcp:close() close a socket which is still sending?
There are two buffers between you and the wire. First there is the  
Socket/Port buffer and
then there is the operating system socket buffer.

When you send data from Erlang the data that could not be transmitted  
directly is
queued for delivery when more kernel buffer space is available.

After you issue a gen_tcp:close then if the server side is really slow  
and do not process any data for
more than 5 seconds then the socket is closed any way.
My guess is that you send some buffer that is queued in the operating  
system buffer and then
you call close. What happens then is up to the tcp implementation. Are  
you using Windows ?

The "safe" way to terminate a sending socket is to use shutdown(S,  
write) and then wait
for the server side to close the connection.
The shutdown interface will also wait until all data queued in the  
Port/socket is written to the
operating system socket before issuing the low level shutdown.

Hope this will lead you forward.

/Tony

On 14 jun 2009, at 03.08, John Haugeland wrote:

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Haugeland  
View profile  
 More options Jun 14 2009, 1:31 pm
From: John Haugeland <stonecyp...@gmail.com>
Date: Sun, 14 Jun 2009 11:31:05 -0600
Local: Sun, Jun 14 2009 1:31 pm
Subject: Re: [erlang-questions] Can gen_tcp:close() close a socket which is still sending?

> After you issue a gen_tcp:close then if the server side is really slow and
> do not process any data for more than 5 seconds then the socket is closed any way.

It's lightning fast by design.  Having Erlang's excellent mature
timeslicer to work with has made it borderline trivial to make a
webserver that's fast enough to send Marty McFly back in time.

You heard me: my webserver goes 88 miles an hour.

> My guess is that you send some buffer that is queued in the operating system
> buffer and then you call close.

Well right now I'm just testing over localhost.  Same machine for
server and client.

> What happens then is up to the tcp implementation. Are you
> using Windows ?

This happens both under Vista Home Premium 64 and Gentoo 64.

> The "safe" way to terminate a sending socket is to use shutdown(S, write)
> and then wait for the server side to close the connection.

This here may be exactly what I need to know.  To check, first,
though: in context, erlang _is_ the server side.  Does that change
things?  The client is any web browser.  I apologize for having been
unclear.

> The shutdown interface will also wait until all data queued in the
> Port/socket is written to the
> operating system socket before issuing the low level shutdown.

See, that's what I would have expected.  Windows doesn't close sockets
with outbound data on them, when you're writing C/C++.  That right
there is a big part of why I'm worried I haven't yet correctly
diagnosed the problem.

> Hope this will lead you forward.

I suspect it has, but my being unclear about Erlang's role as a server
suggests I need to make sure I didn't actually present a wrong
situation for advice first.

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Rogvall  
View profile  
 More options Jun 14 2009, 6:48 pm
From: Tony Rogvall <t...@rogvall.se>
Date: Mon, 15 Jun 2009 00:48:29 +0200
Local: Sun, Jun 14 2009 6:48 pm
Subject: Re: [erlang-questions] Can gen_tcp:close() close a socket which is still sending?

>> The "safe" way to terminate a sending socket is to use shutdown(S,  
>> write)
>> and then wait for the server side to close the connection.

> This here may be exactly what I need to know.  To check, first,
> though: in context, erlang _is_ the server side.  Does that change
> things?  The client is any web browser.  I apologize for having been
> unclear.

Then perhaps you should check the exit_on_close option in the inet  
module.
If the client uses shutdown you will be able to write data to the  
client and
then close after this is done.

/Tony


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Haugeland  
View profile  
 More options Jun 14 2009, 10:26 pm
From: John Haugeland <stonecyp...@gmail.com>
Date: Sun, 14 Jun 2009 20:26:28 -0600
Local: Sun, Jun 14 2009 10:26 pm
Subject: Re: [erlang-questions] Can gen_tcp:close() close a socket which is still sending?
The client will not shut down.

The issue is that, conceptually, what needs to happen is the server
should provide a response then drop as soon as its response is
completely dispatched.  Erlang is not waiting for the other side to
close.  Erlang is completely in control here.  The desired behavior is
solely guided by when that gen_tcp:send(...) is complete.

It's a webserver.  The client doesn't close the connection.

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Rogvall  
View profile  
 More options Jun 15 2009, 3:52 am
From: Tony Rogvall <t...@rogvall.se>
Date: Mon, 15 Jun 2009 09:52:27 +0200
Local: Mon, Jun 15 2009 3:52 am
Subject: Re: [erlang-questions] Can gen_tcp:close() close a socket which is still sending?
So what happens if you use shutdown write?
Use ethereal or tcpdump to get a trace!

/Tony

On 15 jun 2009, at 04.26, John Haugeland wrote:

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »