Skip to content

Commit

Permalink
Fix problems in TCP socket communication (python)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiCostinescu committed Jun 17, 2021
1 parent 9dc542b commit d553b84
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions python/comm/comm_data/ImageEncodeData.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def deserialize(self, buffer: Buffer, start: int, forceCopy: bool, verbose: bool
self.image = cv.imdecode(self.encodedImage, cv.IMREAD_COLOR)
self.imageHeight = self.image.shape[0]
self.imageWidth = self.image.shape[1]
self.imageType = ImageData.imageCVType(self.image)
self.imageDeserialized = True
self.deserializeState = 0
return True
Expand Down
8 changes: 5 additions & 3 deletions python/comm/comm_socket/Socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ def _setSocketTimeouts(sock: socket.socket, sendTimeout: int = -1, recvTimeout:
if os == "Windows":
timeval = sendTimeout
else:
timeval = struct.pack('ll', 0, 1000 * sendTimeout)
timeval = struct.pack('ll', 0, sendTimeout)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDTIMEO, timeval)
print("Socket send timeout:", sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDTIMEO))
if recvTimeout > 0:
if os == "Windows":
timeval = recvTimeout
else:
timeval = struct.pack('ll', 0, 1000 * recvTimeout)
timeval = struct.pack('ll', 0, recvTimeout)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, timeval)
print("Socket recv timeout:", sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO))

Expand Down Expand Up @@ -432,8 +432,10 @@ def performReceive(self, buffer: bytes, expectedHeader: Optional[SerializationHe
while receiveSize > 0:
receiveBuffer = self.socket.recv(receiveSize)
receiveAmount = len(receiveBuffer)
receiveSize -= receiveAmount
self.recvBuffer.buffer = memcpy(self.recvBuffer.buffer, localReceivedBytes, receiveBuffer, 0,
receiveAmount)
localReceivedBytes += receiveAmount
self.recvBuffer.buffer += receiveBuffer
if receiveAmount <= 0:
break
else:
Expand Down
2 changes: 1 addition & 1 deletion src/socket/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ bool Socket::performReceive(char *buffer, int &localReceivedBytes, bool &overwri
localRetries--;
} else {
cout << "BREAK BECAUSE OF (TCP) ERROR: receive amount = " << receiveAmount << "; errorCode: "
<< errorCode << "; " << getLastErrorString(errorCode) << endl;
<< errorCode << "; " << getLastErrorString(errorCode) << endl;
localReceivedBytes = receiveAmount;
return true;
}
Expand Down

0 comments on commit d553b84

Please sign in to comment.