On Fri, Apr 25, 2008 at 8:24 AM, Michael Foord
<[EMAIL PROTECTED]> wrote:
> Uhm... just in case our customer subscribes to this list - I consider it
> an entirely *valid* moan. :-O

Presumably, you would have said "whine" otherwise.  Or "whinge", if
they're in one of *those* parts of the world. :P

I've attached a patch against 1.1.1 that (I think) fixes this.  It
works for my test case, anyway.

--
Curt Hagenlocher
[EMAIL PROTECTED]
---  
+++  
@@ -166,21 +166,25 @@
             [Documentation("close() -> None\n\nClose the socket. It cannot be 
used after being closed.")]
             [PythonName("close")]
             public void Close() {
+                RemoveHandleSocketMapping(this);
+            }
+
+            internal static void RemoveHandleSocketMapping(SocketObj socket) {
                 lock (handleToSocket) {
                     List<Socket> sockets;
-                    if (handleToSocket.TryGetValue((IntPtr)socket.Handle, out 
sockets)) {
-                        if (sockets.Contains(socket)) {
-                            sockets.Remove(socket);
+                    if 
(handleToSocket.TryGetValue((IntPtr)socket.socket.Handle, out sockets)) {
+                        if (sockets.Contains(socket.socket)) {
+                            sockets.Remove(socket.socket);
                         }
                         if (sockets.Count == 0) {
-                            handleToSocket.Remove(socket.Handle);
+                            handleToSocket.Remove(socket.socket.Handle);
+                            try {
+                                socket.socket.Close();
+                            } catch (Exception e) {
+                                throw MakeException(e);
+                            }
                         }
                     }
-                }
-                try {
-                    socket.Close();
-                } catch (Exception e) {
-                    throw MakeException(e);
                 }
             }
 
@@ -323,6 +327,7 @@
                 + "and bufsize arguments are as for the built-in open() 
function.")]
             [PythonName("makefile")]
             public PythonFile MakeFile(ICallerContext context, 
[DefaultParameterValue("r")]string mode, [DefaultParameterValue(8192)]int 
bufSize) {
+                AddHandleMapping(this);
                 return new FileObject(context, this, mode, bufSize);
             }
 
@@ -660,13 +665,15 @@
                 } else {
                     SetTimeout((double)DefaultTimeout / MillisecondsPerSecond);
                 }
+                AddHandleMapping(this);
+            }
+
+            private static void AddHandleMapping(SocketObj socket) {
                 lock (handleToSocket) {
-                    if (!handleToSocket.ContainsKey(socket.Handle)) {
-                        handleToSocket[socket.Handle] = new List<Socket>(1);
+                    if (!handleToSocket.ContainsKey(socket.socket.Handle)) {
+                        handleToSocket[socket.socket.Handle] = new 
List<Socket>(1);
                     }
-                    if (!handleToSocket[socket.Handle].Contains(socket)) {
-                        handleToSocket[socket.Handle].Add(socket);
-                    }
+                    handleToSocket[socket.socket.Handle].Add(socket.socket);
                 }
             }
 
@@ -1638,6 +1645,13 @@
                     return _userSocket;
                 }
             }
+
+            protected override void Dispose(bool disposing) {
+                SocketObj sock = _userSocket as SocketObj;
+                if (sock != null) {
+                    SocketObj.RemoveHandleSocketMapping(sock);
+                }
+            }
         }
 
         [PythonType("_fileobject")]
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to