From: <am...@us...> - 2007-06-17 20:17:49
|
Revision: 3253 http://svn.sourceforge.net/jython/?rev=3253&view=rev Author: amak Date: 2007-06-17 13:17:47 -0700 (Sun, 17 Jun 2007) Log Message: ----------- 1. Added some more exception mapping, so that the exception signature is the same as cpython 2. Added some errno constants, until we establish an errno module. Modified Paths: -------------- trunk/sandbox/kennedya/asynch_sockets/select.py trunk/sandbox/kennedya/asynch_sockets/socket.py Modified: trunk/sandbox/kennedya/asynch_sockets/select.py =================================================================== --- trunk/sandbox/kennedya/asynch_sockets/select.py 2007-06-17 18:33:26 UTC (rev 3252) +++ trunk/sandbox/kennedya/asynch_sockets/select.py 2007-06-17 20:17:47 UTC (rev 3253) @@ -13,12 +13,12 @@ POLLIN = 1 POLLOUT = 2 -POLLPRI = 4 # The following event types are completely ignored on jython # Java does not support them, AFAICT # They are declared only to support code compatibility with cpython +POLLPRI = 4 POLLERR = 8 POLLHUP = 16 POLLNVAL = 32 @@ -126,6 +126,7 @@ timeout = _calcselecttimeoutvalue(timeout) # First create a poll object to do the actual watching. pobj = poll() + already_registered = {} # Check the read list try: # AMAK: Need to remove all this list searching, change to a dictionary? @@ -134,9 +135,10 @@ if fd in write_fd_list: mask |= POLLOUT pobj.register(fd, mask) + already_registered[fd] = 1 # And now the write list for fd in write_fd_list: - if not fd in read_fd_list: # fds in both have already been registered. + if not already_registered.has_key(fd): pobj.register(fd, POLLOUT) results = pobj.poll(timeout) except AttributeError, ax: Modified: trunk/sandbox/kennedya/asynch_sockets/socket.py =================================================================== --- trunk/sandbox/kennedya/asynch_sockets/socket.py 2007-06-17 18:33:26 UTC (rev 3252) +++ trunk/sandbox/kennedya/asynch_sockets/socket.py 2007-06-17 20:17:47 UTC (rev 3253) @@ -29,6 +29,7 @@ import java.lang.Exception import java.lang.String import java.net.BindException +import java.net.ConnectException import java.net.DatagramPacket import java.net.InetAddress import java.net.InetSocketAddress @@ -42,6 +43,13 @@ import javax.net.ssl.SSLSocketFactory import org.python.core.PyFile +# Some errno constants, until we establish a separate errno module. + +ERRNO_EACCESS = 10035 +ERRNO_EWOULDBLOCK = 10035 +ERRNO_EINPROGRESS = 10036 +ERRNO_ECONNREFUSED = 10061 + class error(Exception): pass class herror(error): pass class gaierror(error): pass @@ -53,13 +61,15 @@ # (<javaexception>, <circumstance>) : lambda: <code that raises the python equivalent> -(java.net.BindException, ALL) : lambda exc: error('TODO: find python errno and string'), (java.io.InterruptedIOException, ALL) : lambda exc: timeout('timed out'), +(java.net.BindException, ALL) : lambda exc: error(ERRNO_EACCESS, 'Permission denied'), +(java.net.ConnectException, ALL) : lambda exc: error( (ERRNO_ECONNREFUSED, 'Connection refused') ), (java.net.SocketTimeoutException, ALL) : lambda exc: timeout('timed out'), + } def would_block_error(exc=None): - return error( (10035, 'The socket operation could not complete without blocking') ) + return error( (ERRNO_EWOULDBLOCK, 'The socket operation could not complete without blocking') ) def map_exception(exc, circumstance=ALL): try: @@ -417,7 +427,6 @@ self.sock_impl = _server_socket_impl(host, port, backlog, self.reuse_addr) self._config() except java.lang.Exception, jlx: - raise raise map_exception(jlx) # @@ -447,15 +456,18 @@ return host, port def _do_connect(self, addr): - assert not self.sock_impl - host, port = self._get_host_port(addr) - self.sock_impl = _client_socket_impl() - if self.local_addr: # Has the socket been bound to a local address? - bind_host, bind_port = self.local_addr - self.sock_impl.bind(bind_host, bind_port) - self._config() # Configure timeouts, etc, now that the socket exists - self.sock_impl.connect(host, port) - self._setup(self.sock_impl) + try: + assert not self.sock_impl + host, port = self._get_host_port(addr) + self.sock_impl = _client_socket_impl() + if self.local_addr: # Has the socket been bound to a local address? + bind_host, bind_port = self.local_addr + self.sock_impl.bind(bind_host, bind_port) + self._config() # Configure timeouts, etc, now that the socket exists + self.sock_impl.connect(host, port) + self._setup(self.sock_impl) + except java.lang.Exception, jlx: + raise map_exception(jlx) def connect(self, addr): "This signifies a client socket" @@ -468,7 +480,7 @@ if self.sock_impl.finish_connect(): self._setup(self.sock_impl) return 0 - return 1 + return ERRNO_EINPROGRESS def _setup(self, sock): self.sock_impl = sock This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |