MCPcopy Index your code
hub / github.com/python/cpython / Connection

Class Connection

Lib/multiprocessing/connection.py:381–459  ·  view source on GitHub ↗

Connection class based on an arbitrary file descriptor (Unix only), or a socket handle (Windows).

Source from the content-addressed store, hash-verified

379
380
381class Connection(_ConnectionBase):
382 """
383 Connection class based on an arbitrary file descriptor (Unix only), or
384 a socket handle (Windows).
385 """
386
387 if _winapi:
388 def _close(self, _close=_multiprocessing.closesocket):
389 _close(self._handle)
390 _write = _multiprocessing.send
391 _read = _multiprocessing.recv
392 else:
393 def _close(self, _close=os.close):
394 _close(self._handle)
395 _write = os.write
396 _read = os.read
397
398 def _send(self, buf, write=_write):
399 remaining = len(buf)
400 while True:
401 n = write(self._handle, buf)
402 remaining -= n
403 if remaining == 0:
404 break
405 buf = buf[n:]
406
407 def _recv(self, size, read=_read):
408 buf = io.BytesIO()
409 handle = self._handle
410 remaining = size
411 while remaining > 0:
412 to_read = min(BUFSIZE, remaining)
413 chunk = read(handle, to_read)
414 n = len(chunk)
415 if n == 0:
416 if remaining == size:
417 raise EOFError
418 else:
419 raise OSError("got end of file during message")
420 buf.write(chunk)
421 remaining -= n
422 return buf
423
424 def _send_bytes(self, buf):
425 n = len(buf)
426 if n > 0x7fffffff:
427 pre_header = struct.pack("!i", -1)
428 header = struct.pack("!Q", n)
429 self._send(pre_header)
430 self._send(header)
431 self._send(buf)
432 else:
433 # For wire compatibility with 3.7 and lower
434 header = struct.pack("!i", n)
435 if n > 16384:
436 # The payload is large so Nagle's algorithm won't be triggered
437 # and we'd better avoid the cost of concatenation.
438 self._send(header)

Callers 4

PipeFunction · 0.70
acceptMethod · 0.70
SocketClientFunction · 0.70
rebuild_connectionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…