jython: cb7e31929f49 (original) (raw)

--- a/Lib/socket.py +++ b/Lib/socket.py @@ -413,13 +413,16 @@ class _client_socket_impl(_nio_impl): (IPPROTO_TCP, TCP_NODELAY): 'TcpNoDelay', }

def bind(self, jsockaddr, reuse_addr): self.jsocket.setReuseAddress(reuse_addr) @@ -485,6 +488,7 @@ class _server_socket_impl(_nio_impl): } def init(self, jsockaddr, backlog, reuse_addr):

@@ -495,13 +499,13 @@ class _server_socket_impl(_nio_impl): if self.mode in (MODE_BLOCKING, MODE_NONBLOCKING): new_cli_chan = self.jchannel.accept() if new_cli_chan is not None:

def shutdown(self, how): # This is no-op on java, for server sockets. @@ -510,6 +514,24 @@ class _server_socket_impl(_nio_impl): # later cause the user explicit close() call to fail pass

+

+ def getsockname(self): return (self.jsocket.getInetAddress().getHostAddress(), self.jsocket.getLocalPort())

--- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -727,8 +727,9 @@ class TestSocketOptions(unittest.TestCas self._testSetAndGetOption(sock, level, option, values) # now bind the socket i.e. cause the implementation socket to be created sock.bind( (HOST, PORT) )

@@ -738,6 +739,7 @@ class TestSocketOptions(unittest.TestCas try: # First listen on a server socket, so that the connection won't be refused. server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

@@ -747,35 +749,66 @@ class TestSocketOptions(unittest.TestCas # First bind, so that the SO_REUSEADDR setting propagates sock.bind( (HOST, PORT+1) ) sock.connect( (HOST, PORT) )

+ def _testTCPServerOption(self, level, option, values): try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

@@ -783,8 +816,8 @@ class TestSocketOptions(unittest.TestCas def _testOption(self, level, option, values): for flag, func in [ (self.test_udp, self._testUDPOption),

@@ -798,6 +831,12 @@ class TestSocketOptions(unittest.TestCas else: self.fail("Setting unsupported option should have raised an exception")

+ class TestSupportedOptions(TestSocketOptions): def testSO_BROADCAST(self): @@ -806,44 +845,58 @@ class TestSupportedOptions(TestSocketOpt def testSO_KEEPALIVE(self): self.test_tcp_client = 1

def testSO_LINGER(self): self.test_tcp_client = 1

def testSO_OOBINLINE(self): self.test_tcp_client = 1

def testSO_RCVBUF(self):

def testSO_REUSEADDR(self):

def testSO_SNDBUF(self):

def testSO_TIMEOUT(self):

def testTCP_NODELAY(self): self.test_tcp_client = 1

class TestUnsupportedOptions(TestSocketOptions):