[Python-checkins] cpython: Issue #10141: Don't use hardcoded frame size in example, use struct.calcsize()

victor.stinner python-checkins at python.org
Thu Oct 6 20:28:01 CEST 2011


http://hg.python.org/cpython/rev/a4af684bb54e
changeset:   72759:a4af684bb54e
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Thu Oct 06 20:27:20 2011 +0200
summary:
  Issue #10141: Don't use hardcoded frame size in example, use struct.calcsize()

files:
  Doc/library/socket.rst |  3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)


diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -1270,6 +1270,7 @@
    # CAN frame packing/unpacking (see `struct can_frame` in <linux/can.h>)
 
    can_frame_fmt = "=IB3x8s"
+   can_frame_size = struct.calcsize(can_frame_fmt)
 
    def build_can_frame(can_id, data):
        can_dlc = len(data)
@@ -1286,7 +1287,7 @@
    s.bind(('vcan0',))
 
    while True:
-       cf, addr = s.recvfrom(16)
+       cf, addr = s.recvfrom(can_frame_size)
 
        print('Received: can_id=%x, can_dlc=%x, data=%s' % dissect_can_frame(cf))
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list