Skip to content

Workaround for a non-standard vxi11 implementation of the RPC Reply t… #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions vxi11/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,35 @@ def sendrecord(sock, record):
sendfrag(sock, 1, record)

def recvfrag(sock):
header = sock.recv(4)
# constant length readout
# TODO could be variable via argument of recvfrag()-function
LEN = 1024
header = sock.recv(LEN)
if len(header) < 4:
raise EOFError
# reading out the header
x = struct.unpack(">I", header[0:4])[0]
# 32-bit masking of the header (4 * 8 bits) to get the RPC last fragment indicator
last = ((x & 0x80000000) != 0)
# RPC field announcing the length of the payload (via masking)
n = int(x & 0x7fffffff)
frag = bytearray()
# reading out the fragment
frag = bytearray( header[4:] )
# waiting for the remaining fragments
while len(frag) < n:
buf = sock.recv(n - len(frag))
# an empty read breaks the accumulating loop
if not buf: raise EOFError
# accumulating the fragments
frag.extend(buf)

# below hack: some equipment do not set the last fragment bit to 1
# for a RPC Reply to a GET PORT Call, so it is asserted True when
# the length of the received data matches the announced length
# the issue is described in https://groups.google.com/g/python-ivi/c/vxrdshKG43E/m/plOXFbsopUgJ?pli=1
if len(frag)==n and n==28:
last=True

return last, frag

def recvrecord(sock):
Expand Down