From: <am...@us...> - 2009-07-21 23:06:22
|
Revision: 6557 http://jython.svn.sourceforge.net/jython/?rev=6557&view=rev Author: amak Date: 2009-07-21 23:06:14 +0000 (Tue, 21 Jul 2009) Log Message: ----------- 1. Fixed a bug where send in UDP sockets whereby a send() on a connected UDP socket raised an NPE. 2. Added tests for same for both timeout and non-timeout code paths. 3. Dropped the "finishConnect" method for UDP sockets: DatagramChannels and DatagramSockts don't have finishConnect() methods, since UDP "connections" are not like TCP stateful connections: UDP connections are more akin to address filters, and cannot be "finished". Modified Paths: -------------- trunk/jython/Lib/socket.py trunk/jython/Lib/test/test_socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2009-07-21 21:53:56 UTC (rev 6556) +++ trunk/jython/Lib/socket.py 2009-07-21 23:06:14 UTC (rev 6557) @@ -429,9 +429,6 @@ def connect(self, host, port): self.jchannel.connect(java.net.InetSocketAddress(host, port)) - def finish_connect(self): - return self.jchannel.finishConnect() - def disconnect(self): """ Disconnect the datagram socket. @@ -449,16 +446,19 @@ def _do_send_net(self, byte_array, socket_address, flags): # Need two separate implementations because the java.nio APIs do not support timeouts num_bytes = len(byte_array) - if socket_address: - packet = java.net.DatagramPacket(byte_array, num_bytes, socket_address) - else: + if self.jsocket.isConnected() and socket_address is None: packet = java.net.DatagramPacket(byte_array, num_bytes) + else: + packet = java.net.DatagramPacket(byte_array, num_bytes, socket_address) self.jsocket.send(packet) return num_bytes def _do_send_nio(self, byte_array, socket_address, flags): - byte_buf = java.nio.ByteBuffer.wrap(byte_array) - bytes_sent = self.jchannel.send(byte_buf, socket_address) + byte_buf = java.nio.ByteBuffer.wrap(byte_array) + if self.jchannel.isConnected() and socket_address is None: + bytes_sent = self.jchannel.write(byte_buf) + else: + bytes_sent = self.jchannel.send(byte_buf, socket_address) return bytes_sent def sendto(self, byte_array, host, port, flags): @@ -993,11 +993,7 @@ def connect_ex(self, addr): if not self.sock_impl: self._do_connect(addr) - if self.sock_impl.finish_connect(): - if self.mode == MODE_NONBLOCKING: - return errno.EISCONN - return 0 - return errno.EINPROGRESS + return 0 def sendto(self, data, p1, p2=None): try: Modified: trunk/jython/Lib/test/test_socket.py =================================================================== --- trunk/jython/Lib/test/test_socket.py 2009-07-21 21:53:56 UTC (rev 6556) +++ trunk/jython/Lib/test/test_socket.py 2009-07-21 23:06:14 UTC (rev 6557) @@ -857,6 +857,28 @@ self.cli.settimeout(10) self.cli.sendto(MSG, 0, (self.HOST, self.PORT)) + def testSendAndRecv(self): + # Testing send() and recv() over connect'ed UDP + msg = self.serv.recv(len(MSG)) + self.assertEqual(msg, MSG) + + def _testSendAndRecv(self): + self.cli.connect( (self.HOST, self.PORT) ) + self.cli.send(MSG, 0) + + def testSendAndRecvTimeoutMode(self): + # Need to test again in timeout mode, which follows + # a different code path + self.serv.settimeout(10) + # Testing send() and recv() over connect'ed UDP + msg = self.serv.recv(len(MSG)) + self.assertEqual(msg, MSG) + + def _testSendAndRecvTimeoutMode(self): + self.cli.connect( (self.HOST, self.PORT) ) + self.cli.settimeout(10) + self.cli.send(MSG, 0) + def testRecvFrom(self): # Testing recvfrom() over UDP msg, addr = self.serv.recvfrom(len(MSG)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |