@@ -254,17 +254,21 @@ def close(self):
254254 # WORK IN PROGRESS
255255 ####################################################################
256256
257- def setsockopt (self , * opts , ** kwopts ):
258- """Dummy call for compatibility."""
259-
260- def setblocking (self , flag : bool ):
261- """Set the blocking behaviour of this socket.
262- :param bool flag: False means non-blocking, True means block indefinitely.
257+ def accept (self ):
258+ """Accept a connection on a listening socket of type SOCK_STREAM,
259+ creating a new socket of type SOCK_STREAM. Returns a tuple of
260+ (new_socket, remote_address)
263261 """
264- if flag :
265- self .settimeout (None )
266- else :
267- self .settimeout (0 )
262+ client_sock_num = self ._interface .socket_available (self ._socknum )
263+ if client_sock_num != SocketPool .NO_SOCKET_AVAIL :
264+ sock = Socket (self ._socket_pool , socknum = client_sock_num )
265+ # get remote information (addr and port)
266+ remote = self ._interface .get_remote_data (client_sock_num )
267+ ip_address = "{}.{}.{}.{}" .format (* remote ["ip_addr" ])
268+ port = remote ["port" ]
269+ client_address = (ip_address , port )
270+ return sock , client_address
271+ raise OSError (errno .ECONNRESET )
268272
269273 def bind (self , address : Tuple [str , int ]):
270274 """Bind a socket to an address"""
@@ -279,18 +283,14 @@ def listen(self, backlog: int): # pylint: disable=unused-argument
279283 port = self ._bound [1 ]
280284 self ._interface .start_server (port , self ._socknum )
281285
282- def accept (self ):
283- """Accept a connection on a listening socket of type SOCK_STREAM,
284- creating a new socket of type SOCK_STREAM. Returns a tuple of
285- (new_socket, remote_address)
286+ def setblocking (self , flag : bool ):
287+ """Set the blocking behaviour of this socket.
288+ :param bool flag: False means non-blocking, True means block indefinitely.
286289 """
287- client_sock_num = self ._interface .socket_available (self ._socknum )
288- if client_sock_num != SocketPool .NO_SOCKET_AVAIL :
289- sock = Socket (self ._socket_pool , socknum = client_sock_num )
290- # get remote information (addr and port)
291- remote = self ._interface .get_remote_data (client_sock_num )
292- ip_address = "{}.{}.{}.{}" .format (* remote ["ip_addr" ])
293- port = remote ["port" ]
294- client_address = (ip_address , port )
295- return sock , client_address
296- raise OSError (errno .ECONNRESET )
290+ if flag :
291+ self .settimeout (None )
292+ else :
293+ self .settimeout (0 )
294+
295+ def setsockopt (self , * opts , ** kwopts ):
296+ """Dummy call for compatibility."""
0 commit comments