Skip to content

Commit 367cf9b

Browse files
endriftslouken
authored andcommitted
joystick: Always continue processing GIP packets
This loop breakout was originally from an attempt to parse coalesced packets. Breaking out early does more harm than good, and no devices coalesce packets, so this is unnecessary.
1 parent 955a49c commit 367cf9b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/joystick/hidapi/SDL_hidapi_gip.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ static bool GIP_HandleMessage(
21712171
return false;
21722172
}
21732173

2174-
static int GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_bytes)
2174+
static void GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_bytes)
21752175
{
21762176
GIP_Header header;
21772177
int offset = 3;
@@ -2183,7 +2183,7 @@ static int GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_byt
21832183
GIP_Attachment* attachment;
21842184

21852185
if (num_bytes < 5) {
2186-
return -1;
2186+
return;
21872187
}
21882188

21892189
header.message_type = bytes[0];
@@ -2216,21 +2216,21 @@ static int GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_byt
22162216
}
22172217
offset += GIP_DecodeLength(&total_length, &bytes[offset], num_bytes - offset);
22182218
if (total_length > MAX_MESSAGE_LENGTH) {
2219-
return -1;
2219+
return;
22202220
}
22212221
attachment->total_length = (Uint16) total_length;
22222222
attachment->fragment_message = header.message_type;
22232223
if (header.length > num_bytes - offset) {
22242224
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
22252225
"GIP: Received fragment that claims to be %" SDL_PRIu64 " bytes, expected %i",
22262226
header.length, num_bytes - offset);
2227-
return -1;
2227+
return;
22282228
}
22292229
if (header.length > total_length) {
22302230
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
22312231
"GIP: Received too long fragment, %" SDL_PRIu64 " bytes, exceeds %d",
22322232
header.length, attachment->total_length);
2233-
return -1;
2233+
return;
22342234
}
22352235
attachment->fragment_data = SDL_malloc(attachment->total_length);
22362236
SDL_memcpy(attachment->fragment_data, &bytes[offset], (size_t) header.length);
@@ -2243,24 +2243,25 @@ static int GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_byt
22432243
"GIP: Received out of sequence message type %02x, expected %02x",
22442244
header.message_type, attachment->fragment_message);
22452245
GIP_FragmentFailed(attachment, &header);
2246-
return -1;
2246+
return;
22472247
}
22482248

22492249
offset += GIP_DecodeLength(&fragment_offset, &bytes[offset], num_bytes - offset);
22502250
if (fragment_offset != attachment->fragment_offset) {
22512251
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
22522252
"GIP: Received out of sequence fragment, (claimed %" SDL_PRIu64 ", expected %d)",
22532253
fragment_offset, attachment->fragment_offset);
2254-
return GIP_Acknowledge(device,
2254+
GIP_Acknowledge(device,
22552255
&header,
22562256
attachment->fragment_offset,
22572257
(Uint16) (attachment->total_length - attachment->fragment_offset));
2258+
return;
22582259
} else if (fragment_offset + header.length > attachment->total_length) {
22592260
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
22602261
"GIP: Received too long fragment, %" SDL_PRIu64 " exceeds %d",
22612262
fragment_offset + header.length, attachment->total_length);
22622263
GIP_FragmentFailed(attachment, &header);
2263-
return -1;
2264+
return;
22642265
}
22652266

22662267
bytes_remaining = attachment->total_length - (Uint16) (fragment_offset + header.length);
@@ -2282,7 +2283,7 @@ static int GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_byt
22822283
SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
22832284
"GIP: Received message with erroneous length (claimed %" SDL_PRIu64 ", actual %d), discarding",
22842285
header.length + offset, num_bytes);
2285-
return -1;
2286+
return;
22862287
} else {
22872288
num_bytes -= offset;
22882289
bytes += offset;
@@ -2293,7 +2294,6 @@ static int GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_byt
22932294
if (ok && (header.flags & GIP_FLAG_ACME)) {
22942295
GIP_Acknowledge(device, &header, (Uint32) fragment_offset, bytes_remaining);
22952296
}
2296-
return offset + (Uint16) header.length;
22972297
}
22982298

22992299
static void HIDAPI_DriverGIP_RumbleSent(void *userdata)
@@ -2611,10 +2611,7 @@ static bool HIDAPI_DriverGIP_UpdateDevice(SDL_HIDAPI_Device *device)
26112611

26122612
while ((num_bytes = SDL_hid_read_timeout(device->dev, bytes, sizeof(bytes), ctx->timeout)) > 0) {
26132613
ctx->timeout = 0;
2614-
int parsed = GIP_ReceivePacket(ctx, bytes, num_bytes);
2615-
if (parsed <= 0) {
2616-
break;
2617-
}
2614+
GIP_ReceivePacket(ctx, bytes, num_bytes);
26182615
}
26192616

26202617
timestamp = SDL_GetTicks();

0 commit comments

Comments
 (0)