MCPcopy
hub / github.com/benoitc/gunicorn / read_message

Method read_message

gunicorn/dirty/protocol.py:520–557  ·  view source on GitHub ↗

Read a complete message from socket (sync). Args: sock: Socket to read from Returns: dict: Message dict with 'type', 'id', and payload fields Raises: DirtyProtocolError: If read fails or message is malformed

(sock: socket.socket)

Source from the content-addressed store, hash-verified

518
519 @staticmethod
520 def read_message(sock: socket.socket) -> dict:
521 """
522 Read a complete message from socket (sync).
523
524 Args:
525 sock: Socket to read from
526
527 Returns:
528 dict: Message dict with 'type', 'id', and payload fields
529
530 Raises:
531 DirtyProtocolError: If read fails or message is malformed
532 """
533 # Read header
534 header = BinaryProtocol._recv_exactly(sock, HEADER_SIZE)
535 msg_type, request_id, length = BinaryProtocol.decode_header(header)
536
537 # Read payload
538 if length > 0:
539 payload_data = BinaryProtocol._recv_exactly(sock, length)
540 try:
541 payload_dict = TLVEncoder.decode_full(payload_data)
542 except DirtyProtocolError:
543 raise
544 except Exception as e:
545 raise DirtyProtocolError(
546 f"Failed to decode TLV payload: {e}",
547 raw_data=payload_data[:50]
548 )
549 else:
550 payload_dict = {}
551
552 # Build response dict
553 msg_type_str = MSG_TYPE_TO_STR[msg_type]
554 result = {"type": msg_type_str, "id": request_id}
555 result.update(payload_dict)
556
557 return result
558
559 @staticmethod
560 def write_message(sock: socket.socket, message: dict) -> None:

Callers 3

_execute_lockedMethod · 0.45
_read_next_chunkMethod · 0.45
_executeMethod · 0.45

Calls 4

DirtyProtocolErrorClass · 0.85
_recv_exactlyMethod · 0.80
decode_headerMethod · 0.80
decode_fullMethod · 0.80

Tested by

no test coverage detected