Changeset 11565
- Timestamp:
- 10/30/19 20:37:11 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-dvbapi.c
r11564 r11565 6098 6098 static uint16_t dvbapi_get_nbof_missing_header_bytes(uint8_t *mbuf, uint16_t mbuf_len) 6099 6099 { 6100 6101 6100 uint32_t opcode = b2i(4, mbuf); //get the client opcode (4 bytes) 6102 6101 … … 6422 6421 int32_t recv_result; 6423 6422 uint16_t chunksize = 1, data_len = 1; 6424 uint8_t packet_count = 0;6423 uint8_t packet_count = 1; 6425 6424 uint32_t msgid_size = 0; 6426 6425 if(*client_proto_version >= 3) … … 6429 6428 } 6430 6429 6431 uint16_t missing_header_bytes = 0; 6430 do 6431 { 6432 uint16_t missing_header_bytes = 0; 6432 6433 6433 if(unhandled_len < 4 + msgid_size)6434 {6435 missing_header_bytes = (4 + msgid_size) - unhandled_len;6436 }6437 else6438 {6439 missing_header_bytes += dvbapi_get_nbof_missing_header_bytes(mbuf+msgid_size, unhandled_len-msgid_size);6440 missing_header_bytes += msgid_size;6441 }6434 if(unhandled_len < 4 + msgid_size) 6435 { 6436 missing_header_bytes = (4 + msgid_size) - unhandled_len; 6437 } 6438 else 6439 { 6440 missing_header_bytes = dvbapi_get_nbof_missing_header_bytes(mbuf+msgid_size, unhandled_len-msgid_size); 6441 missing_header_bytes += msgid_size; 6442 } 6442 6443 6443 if(missing_header_bytes != 0) 6444 { 6445 // read first few bytes so we know packet type and length 6446 cs_log_dbg(D_TRACE, "%s reading %" PRIu16 " bytes from connection fd %d", 6447 (unhandled_len == 0) ? "Try" : "Continue", missing_header_bytes, connfd); 6448 6449 recv_result = dvbapi_recv(connfd, mbuf + unhandled_len, mbuf_size - unhandled_len); 6450 if(recv_result < 1) 6451 { 6452 (*new_unhandled_len) = unhandled_len; 6453 return (recv_result != -1); 6454 } 6455 else 6456 { 6457 unhandled_len += recv_result; 6458 if(unhandled_len < missing_header_bytes) 6444 if(missing_header_bytes != 0) 6445 { 6446 // read first few bytes so we know packet type and length 6447 cs_log_dbg(D_TRACE, "%s reading %" PRIu16 " bytes from connection fd %d", (unhandled_len == 0) ? "Try" : "Continue", missing_header_bytes, connfd); 6448 6449 recv_result = dvbapi_recv(connfd, mbuf + unhandled_len, mbuf_size - unhandled_len); 6450 if(recv_result < 1) 6459 6451 { 6460 6452 (*new_unhandled_len) = unhandled_len; 6461 return true; 6462 } 6463 } 6464 } 6453 return (recv_result != -1); 6454 } 6455 else 6456 { 6457 unhandled_len += recv_result; 6458 if(unhandled_len < missing_header_bytes) 6459 { 6460 (*new_unhandled_len) = unhandled_len; 6461 return true; 6462 } 6463 } 6464 } 6465 6465 6466 // we got at least the first few bytes, detect packet type and length, then read the missing bytes 6467 do 6468 { 6469 cs_log_dump_dbg(D_DVBAPI, mbuf, unhandled_len, "Got packet a packet (msgid size: %d, clientprotocol: %d)", msgid_size, *client_proto_version); 6466 cs_log_dump_dbg(D_DVBAPI, mbuf, unhandled_len, "Got packetdata (msgid size: %d, clientprotocol: %d)", msgid_size, *client_proto_version); 6470 6467 dvbapi_get_packet_size(mbuf+msgid_size, unhandled_len-msgid_size, &chunksize, &data_len); 6471 6468 … … 6498 6495 } 6499 6496 6500 // we got at least one full packet, handle it, then return6501 6497 dvbapi_handlesockmsg(mbuf, chunksize-msgid_size, data_len, add_to_poll, connfd, client_proto_version); 6502 6498 … … 6506 6502 memmove(mbuf, mbuf + chunksize, unhandled_len); 6507 6503 } 6508 packet_count++; 6509 } while(dvbapi_get_nbof_missing_header_bytes(mbuf+msgid_size, unhandled_len-msgid_size) == 0 && packet_count < 7); 6504 } while(unhandled_len != 0 && packet_count++ < 8); 6505 6506 cs_log_dbg(D_DVBAPI, "Processing socketdata completed after %d packets with %d bytes left unprocessed", packet_count, unhandled_len); 6510 6507 6511 6508 (*new_unhandled_len) = unhandled_len;
Note:
See TracChangeset
for help on using the changeset viewer.