Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

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

Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo
Status: New
Owner: ----
Labels: Milestone-1.3 Type-Bug

New issue 5180 by [hidden email]: ConnectionQueue>>getConnectionOrNil  
not working
http://code.google.com/p/pharo/issues/detail?id=5180

If you try to use ConnectionQueue in actual Pharo image, for example code:

| queue connection |

   queue := ConnectionQueue
     portNumber: 80
     queueLength: 50.

   [
     [
       connection := queue getConnectionOrNil.
       connection
         ifNotNil: [ "serve connection" ].
       Processor yield
     ] repeat
   ] fork.

and some client connects, Debugger appears with code "DoesNotUnderstood  
True>>isConnected".

Problem is in method ConnectionQueue>>listenLoop, where  
object "newConnection" is set to "True" or "False" by calling  
Socket>>waitForConnectionFor:. I think that there should be called other  
method of class Socket.

It works in squeak image.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo

Comment #1 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

I think, just by reading the code, that the right message to send to the  
server socket is #waitForAcceptFor: but I haven't tested this.

Anyway, this class is not used in 1.3 and 1.4. At least there should be a  
test, maybe you can contribute one.

Sven


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo

Comment #2 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

I tried to use #waitForAcceptFor:, but "primitive failed", when I tried to  
connect to it. Perhaps it's because I am using squeakvm, not Pharo's  
default cogvm (prebuild unix cogvm doesn't work on my Fedora (some problem  
with X11 plugin) and I cannot fetch code from gitorious, because "fatal:  
The remote end hung up unexpectedly"). I will do the further investigation.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo

Comment #3 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

I have the impression that you have lots of problems ;-)

Does the Zinc HTTP Components server work for you ?

ZnServer startDefaultOn: 8080

You might want to try running the Zinc-HTTP unit tests.

Have a look at ZnMultiThreadedServer>>#serveConnectionsOn: method.

Are you sure you are using ConnectionQueue correctly ?

Maybe the author of ConnectionQueue, Adrian, can tell us more...


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo

Comment #4 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

Zinc server works well and it passes all 151 tests. I tried this on Windows  
(with cogvm) and it shows same error. DoesNotUnderstood True>>isConnected  
with original code, Socket(Object)>>primitiveFailed: while Socket>>accept  
with #waitForAcceptFor:. I'm trying to use ConnectionQueue with code from  
this Squeak tutorial (in czech) http://www.root.cz/clanky/squeak-sokety/.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo

Comment #5 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

I can't read CZ ;-)

I just see that you are opening a priviledged port, 80 ! Please try with  
something like 8080. The following:

| queue connection |

   queue := ConnectionQueue
     portNumber: 8080
     queueLength: 50.

   [
     [
       connection := queue getConnectionOrNil.
       connection
         ifNotNil: [ Transcript crShow: 'Got connection'. connection  
sendCommand: 'OK'; close ].
       (Delay forMilliseconds: 250) wait. Processor yield
     ] repeat
   ] fork.

Works for me, in 1.3 using the Pharo VM on Mac OS X, when I connect with  
telnet from a terminal.

You have to change #listenLoop to

        | newConnection |

        socket := Socket newTCP.
        "We'll accept four simultanous connections at the same time"
        socket listenOn: portNumber backlogSize: 4.
        "If the listener is not valid then the we cannot use the
        BSD style accept() mechanism."
        socket isValid ifFalse: [^self oldStyleListenLoop].
        [true] whileTrue: [
                socket isValid ifFalse: [
                        "socket has stopped listening for some reason"
                        socket destroy.
                        (Delay forMilliseconds: 10) wait.
                        ^self listenLoop ].
                [newConnection := socket waitForAcceptFor: 10]
                        on: ConnectionTimedOut
                        do: [:ex | newConnection := nil].
                (newConnection notNil and: [newConnection isConnected])
                        ifTrue: [(accessSema critical: [connections size < maxQueueLength])
                                                ifFalse: [newConnection close. newConnection := nil]]
                        ifFalse: [newConnection := nil].
                (newConnection notNil and: [newConnection isConnected]) ifTrue: [
                        accessSema critical: [connections addLast: newConnection].
                        newConnection := nil.
                        self changed].
                self pruneStaleConnections].

Apart from the #waitForAcceptFor modification, there was an additional  
problem in the code trying to limit the number of connections (according to  
the comment, a modification by gvc).

Be careful, if you are debugging this, the server socket remains open in  
lot's of cases (this isn't very robust code). Call #destroy on the  
ConnectionQueue, or terminate the relevant process(es) by hand, and do

   3 timesRepeat: [ Smalltalk garbageCollect ]

So that open sockets are close by the finalization code. See if all is well  
by doing

   Socket allInstances

HTH,

Sven


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo

Comment #6 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

Thanks, this works (btw, I hadn't really used port 80). So, now what :-)?  
Will somebody correct it in pharo image release? Should I "close" this bug  
somehow?


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo
Updates:
        Status: FixToInclude
        Labels: Milestone-1.4

Comment #7 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

Thanks for testing, I was waiting for you to confirm that it solved your  
problem, apparently it does.

For what is is worth, I include a fix as a fileout of this method. It  
should work in 1.3 and 1.4.

I changed the status to FixToInclude and it will be looked at by an  
integrator later on.

Welcome to Pharo!

Attachments:
        ConnectionQueue-listenLoop.st  2.1 KB


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo
Updates:
        Labels: -Milestone-1.3 Milestone-1.3.1

Comment #8 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

(No comment was entered for this change.)


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo

Comment #9 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

Thanks guys!
You rock.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5180 in pharo: ConnectionQueue>>getConnectionOrNil not working

pharo
Updates:
        Status: Closed
        Labels: -Milestone-1.3.1

Comment #10 on issue 5180 by [hidden email]:  
ConnectionQueue>>getConnectionOrNil not working
http://code.google.com/p/pharo/issues/detail?id=5180

in 14286


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker