[Twisted-Python] socket errors

Jp Calderone exarkun at intarweb.us
Mon Jan 20 13:47:11 EST 2003


  Creating a socket can raise an exception in a few circumstances.  Bad
arguments for one (we don't have to worry about this, since we control the
arguments in all circumstances); too many open files for another.  Attached
patch addresses the second circumstance, by catching the raised socket.error
and wrapping it up in a CannotListenError.  It seems unlikely that anyone
has code to handle this error condition (and hence is relying on
socket.error being raised), and CannotListenError seems to be a better thing
to be raising in this case.  Anyone disagree?  Also, the XYZClient classes
might be changed to catch the same socket.error and raise a ConnectError
instead (attached doesn't address this).

  Jp


-- 
Elitism: It's lonely at the top, but it's comforting to look down upon
everyone at the bottom.
--
 12:00am up 35 days, 9:48, 3 users, load average: 0.61, 0.33, 0.22
-------------- next part --------------
Index: tcp.py
===================================================================
RCS file: /cvs/Twisted/twisted/internet/tcp.py,v
retrieving revision 1.99
diff -u -r1.99 tcp.py
--- tcp.py	1 Jan 2003 14:32:27 -0000	1.99
+++ tcp.py	20 Jan 2003 18:36:48 -0000
@@ -451,8 +451,8 @@
             os.chmod(self.port, 0666)
             self.unixsocket = 1
         else:
-            skt = self.createInternetSocket()
             try:
+                skt = self.createInternetSocket()
                 skt.bind((self.interface, self.port))
             except socket.error, le:
                 raise CannotListenError, (self.interface, self.port, le)
Index: udp.py
===================================================================
RCS file: /cvs/Twisted/twisted/internet/udp.py,v
retrieving revision 1.34
diff -u -r1.34 udp.py
--- udp.py	19 Nov 2002 17:48:58 -0000	1.34
+++ udp.py	20 Jan 2003 18:36:48 -0000
@@ -90,8 +90,8 @@
     
     def _bindSocket(self):
         log.msg("%s starting on %s"%(self.protocol.__class__, self.port))
-        skt = self.createInternetSocket()
         try:
+            skt = self.createInternetSocket()
             skt.bind((self.interface, self.port))
         except socket.error, le:
             raise error.CannotListenError, (self.interface, self.port, le)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030120/5339b232/attachment.pgp 


More information about the Twisted-Python mailing list