MCPcopy Create free account
hub / github.com/EasyIME/PIME / _create_stream

Method _create_stream

python/python3/tornado/tcpclient.py:293–328  ·  view source on GitHub ↗
(
        self,
        max_buffer_size: int,
        af: socket.AddressFamily,
        addr: Tuple,
        source_ip: Optional[str] = None,
        source_port: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

291 return stream
292
293 def _create_stream(
294 self,
295 max_buffer_size: int,
296 af: socket.AddressFamily,
297 addr: Tuple,
298 source_ip: Optional[str] = None,
299 source_port: Optional[int] = None,
300 ) -> Tuple[IOStream, "Future[IOStream]"]:
301 # Always connect in plaintext; we'll convert to ssl if necessary
302 # after one connection has completed.
303 source_port_bind = source_port if isinstance(source_port, int) else 0
304 source_ip_bind = source_ip
305 if source_port_bind and not source_ip:
306 # User required a specific port, but did not specify
307 # a certain source IP, will bind to the default loopback.
308 source_ip_bind = "::1" if af == socket.AF_INET6 else "127.0.0.1"
309 # Trying to use the same address family as the requested af socket:
310 # - 127.0.0.1 for IPv4
311 # - ::1 for IPv6
312 socket_obj = socket.socket(af)
313 if source_port_bind or source_ip_bind:
314 # If the user requires binding also to a specific IP/port.
315 try:
316 socket_obj.bind((source_ip_bind, source_port_bind))
317 except socket.error:
318 socket_obj.close()
319 # Fail loudly if unable to use the IP/port.
320 raise
321 try:
322 stream = IOStream(socket_obj, max_buffer_size=max_buffer_size)
323 except socket.error as e:
324 fu = Future() # type: Future[IOStream]
325 fu.set_exception(e)
326 return stream, fu
327 else:
328 return stream, stream.connect(addr)

Callers

nothing calls this directly

Calls 4

connectMethod · 0.95
IOStreamClass · 0.90
bindMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected