lost socket

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

lost socket

Aidan Gauland
Hello,

  I've been playing around with the Socket class, and the code I was running
in an EToys script crashed a few times (I did try it in a workspace first, it
was the code I wrote to talk to other players that crashed), and the temporary
sockets it created never got destroyed.  Is this going to cause problems for
me later?

Thanks,
Aidan
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: lost socket

Yoshiki Ohshima-2
At Wed, 24 Sep 2008 17:42:08 +1200,
Aidan Gauland wrote:
>
> Hello,
>
>   I've been playing around with the Socket class, and the code I was running
> in an EToys script crashed a few times (I did try it in a workspace first, it
> was the code I wrote to talk to other players that crashed), and the temporary
> sockets it created never got destroyed.  Is this going to cause problems for
> me later?

  The short answer is: "probably not".

  There is some missing information here:

  - What do you mean by "crashed"?  Did that raise the pink notifiers?
  - What do you mean by "never got destroyed"?  Did you set a break point in the
    #destroy method but didn't reach, or looked at the socketHandle
    instance variables of Socket objects?

And,

  - Do you quit or save and quit the image after it happened a few
    times (or in between of them)?

When a Socket object is created, an accompanying data structure
(actual socket created by socket() system call or its equivalent and
some extra information for interfacing with Squeak) in the VM is
created, and the socketHandle instance variable of the Socket object
is filled with the "handle" to the data structure.  When the #destroy
method is called on the Socket, the internal data structure is also
destroyed and cleaned up.

Also, when the Socket object is no longer referenced from anywhere in
the image and garbage collected, the finalization process is invoked
and does the same cleaning up.  This means that if your program has a
bug and #destroy method somehow didn't get sent to your Socket object,
you can cut the references to the Socket object and make the system
take care of the clean up.  (Or, manually send #close from the
inspector of the Socket object; Try to print-it the following: Socket
allInstances.)

When Squeak quits, the data structure in the VM will be gone as there
is no way to save them, but the Socket object in the image may be
still referenced by some other objects and saved in the .image file.
Next time you launch the image, the Socket object is still there, with
the socketHandle instance variable kept.  However, because there is no
accompanying data structure in the VM at this point, the Socket object
is "invalid" and won't do anything useful (or harmful).  Suppose a
Socket is created and listen on a port, and you save and quit the
image.  Next time you launch the image, the Socket object is there,
but the port is available so you can create a new Socket and start
listening on the port in the new session.

What you can do is to write code so that unused Socket object gets
#close message properly, and make sure the Socket object is
unreferenced when it happens.  And if your code involves the saving
and launching image, make sure that necessary Socket objects are
initialized in the new Squeak session.

-- Yoshiki
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: lost socket

Aidan Gauland
Thanks for the long answer.  From what you said, I shouldn't have any problems.

But to answer your questions:
  - The code raised a pink error window
  - before the #destroy message was sent.
  - I can't be sure when exactly I saved, but it was after I ran it a few times.

Tahnks again,
Aidan

Yoshiki Ohshima wrote:

>   The short answer is: "probably not".
>
>   There is some missing information here:
>
>   - What do you mean by "crashed"?  Did that raise the pink notifiers?
>   - What do you mean by "never got destroyed"?  Did you set a break point in the
>     #destroy method but didn't reach, or looked at the socketHandle
>     instance variables of Socket objects?
>
> And,
>
>   - Do you quit or save and quit the image after it happened a few
>     times (or in between of them)?


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners