Sockets.Socket and remote closing the connection

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Sockets.Socket and remote closing the connection

Holger Freyther
Hi all,

I have a server that accept(2)'s a TCP connection and then immediately closes
it again. On the Smalltalk side I want to figure out if the connection is
still alive.

Eval [
        s := Sockets.Socket remote: '127.0.0.1' port: aPort.
        s isOpen -> true
        s isPeerAlive -> true (according to netstat it is already in
                               CLOSE_WAIT)
        s canRead -> true
]

is there anything I can do to find out that the remote has closed the
connection? On POSIX I would sooner or later get a -1 on read.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Sockets.Socket and remote closing the connection

Paolo Bonzini-2
On Sun, Sep 26, 2010 at 23:44, Holger Hans Peter Freyther
<[hidden email]> wrote:

> Hi all,
>
> I have a server that accept(2)'s a TCP connection and then immediately closes
> it again. On the Smalltalk side I want to figure out if the connection is
> still alive.
>
> Eval [
>        s := Sockets.Socket remote: '127.0.0.1' port: aPort.
>        s isOpen -> true
>        s isPeerAlive -> true (according to netstat it is already in
>                               CLOSE_WAIT)
>        s canRead -> true
> ]
>
> is there anything I can do to find out that the remote has closed the
> connection? On POSIX I would sooner or later get a -1 on read.

"Later", after the first read has returned a zero, I think. :)  GST
should behave the same way.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Sockets.Socket and remote closing the connection

Holger Freyther
On 09/27/2010 02:38 PM, Paolo Bonzini wrote:

>> is there anything I can do to find out that the remote has closed the
>> connection? On POSIX I would sooner or later get a -1 on read.
>
> "Later", after the first read has returned a zero, I think. :)  GST
> should behave the same way.

hmm. socket next is retuning nil but isOpen/isPeerAlive is still returning true.


in two different shells I do

1.) b := TCP.ServerSocket port: 6000 bindTo: TCP.IPAddress anyLocalAddress.
1.) b waitForConnection.
2.) s := TCP.Socket remote: TCP.IPAddress anyLocalAddress port: 6000.
1.) b accept.
1.) b close.
2.) s next. -> nil
2.) s isOpen -> true.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Sockets.Socket and remote closing the connection

Paolo Bonzini-2
On 09/27/2010 11:20 AM, Holger Hans Peter Freyther wrote:

> On 09/27/2010 02:38 PM, Paolo Bonzini wrote:
>
>>> is there anything I can do to find out that the remote has closed the
>>> connection? On POSIX I would sooner or later get a -1 on read.
>>
>> "Later", after the first read has returned a zero, I think. :)  GST
>> should behave the same way.
>
> hmm. socket next is retuning nil but isOpen/isPeerAlive is still returning true.
>
> in two different shells I do
>
> 1.) b := TCP.ServerSocket port: 6000 bindTo: TCP.IPAddress anyLocalAddress.
> 1.) b waitForConnection.
> 2.) s := TCP.Socket remote: TCP.IPAddress anyLocalAddress port: 6000.
> 1.) b accept.
> 1.) b close.
> 2.) s next. ->  nil
> 2.) s isOpen ->  true.

Good testcase, thanks.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Sockets.Socket and remote closing the connection

Paolo Bonzini-2
In reply to this post by Holger Freyther
On 09/27/2010 11:20 AM, Holger Hans Peter Freyther wrote:
> in two different shells I do
>
> 1.) b := TCP.ServerSocket port: 6000 bindTo: TCP.IPAddress anyLocalAddress.
> 1.) b waitForConnection.
> 2.) s := TCP.Socket remote: TCP.IPAddress anyLocalAddress port: 6000.
> 1.) b accept.
> 1.) b close.

You mean "s close" here.

> 2.) s next. ->  nil

[s next] on: SystemExceptions.EndOfStream do:
    [ :e | 'end' printNl. e resume ]
->
'end'
nil

I have to check why "e resume: 'end'" doesn't work, but the behavior
seems right overall.

> 2.) s isOpen ->  true.

This is a bug though.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Sockets.Socket and remote closing the connection

Holger Freyther
On 09/27/2010 06:02 PM, Paolo Bonzini wrote:

>
> You mean "s close" here.

sorry.

>
>> 2.) s next. ->  nil
>

> I have to check why "e resume: 'end'" doesn't work, but the behavior seems
> right overall.


hmmm..

>
>> 2.) s isOpen ->  true.
>
> This is a bug though.

well, it is obvious why it returns true. FileDescriptor>>isOpen is only
checking if the fd is > 0 which is the case.

Now there is still the question why isPeerAlive returns true as well.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Sockets.Socket and remote closing the connection

Holger Freyther
On 09/27/2010 06:17 PM, Holger Hans Peter Freyther wrote:

>
> Now there is still the question why isPeerAlive returns true as well.

okay, it is calling isOpen..

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Sockets.Socket and remote closing the connection

Paolo Bonzini-2
On 09/27/2010 12:18 PM, Holger Hans Peter Freyther wrote:
>> >  Now there is still the question why isPeerAlive returns true as well.
> okay, it is calling isOpen..

Nope, it does

         ^self readBuffer notNil and: [ super isPeerAlive ]

it should have called #deleteBuffers after the zero-byte read.
Committing a fix.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk