brtos / brtos-unet

0 stars 3 forks source link

Transport.c unet_recv read error #2

Closed fabricio-godoi closed 7 years ago

fabricio-godoi commented 7 years ago

Greatings,

Using the unet_recv function I notice a possible problem when using it with NO_TIMEOUT. If NO_TIMEOUT is used, and there is no information to be read, the semaphore will return by EXIT_BY_NO_ENTRY_AVAILABLE, which isn't equal to TIMEOUT. This implied in reading wrong information from network to the application.

I propose this small change to ensure to read the information only if it's was OK. And to improve it a little bit, return the semaphore status.

int unet_recv(unet_transport_t server_client, uint8_t buffer, uint16_t timeout){ int ret; if ((ret = OSSemPend(server_client->wake_up,timeout)) == OK) { memcpy(buffer,server_client->packet,server_client->payload_size); } return ret; }

Best regards! Fabricio

barriquello commented 7 years ago

Thanks Fabricio. Fixed.