mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +00:00
Fix C++ CameraServer request handling.
The request is not guaranteed to be in a single packet, so it may be necessary to perform multiple reads to get the complete request. The previous code could unpredictably fail as it only performed a single read. Fixes artf4817. Change-Id: I7734a12e1a2542f5d7ca0889453c387f0bb30538
This commit is contained in:
@@ -189,16 +189,26 @@ void CameraServer::Serve() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Request req;
|
Request req;
|
||||||
if (read(conn, &req, sizeof(req)) == -1) {
|
char reqBuf[sizeof(req)];
|
||||||
|
size_t reqPos = 0;
|
||||||
|
|
||||||
|
while (reqPos < sizeof(req)) {
|
||||||
|
ssize_t sizeRead = read(conn, &reqBuf[reqPos], sizeof(req) - reqPos);
|
||||||
|
if (sizeRead < 0) break;
|
||||||
|
reqPos += sizeRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reqPos < sizeof(req)) {
|
||||||
wpi_setErrnoError();
|
wpi_setErrnoError();
|
||||||
close(conn);
|
close(conn);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
|
||||||
req.fps = ntohl(req.fps);
|
|
||||||
req.compression = ntohl(req.compression);
|
|
||||||
req.size = ntohl(req.size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(&req, reqBuf, sizeof(req));
|
||||||
|
req.fps = ntohl(req.fps);
|
||||||
|
req.compression = ntohl(req.compression);
|
||||||
|
req.size = ntohl(req.size);
|
||||||
|
|
||||||
// TODO: Support the SW Compression. The rest of the code below will work as
|
// TODO: Support the SW Compression. The rest of the code below will work as
|
||||||
// though this
|
// though this
|
||||||
// check isn't here
|
// check isn't here
|
||||||
|
|||||||
Reference in New Issue
Block a user