mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +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;
|
||||
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();
|
||||
close(conn);
|
||||
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
|
||||
// though this
|
||||
// check isn't here
|
||||
|
||||
Reference in New Issue
Block a user