File Descriptor RX Buffer Count and TCP Preread

Discussion to talk about software related topics only.
Post Reply
addonray
Posts: 19
Joined: Thu Sep 03, 2015 10:46 am

File Descriptor RX Buffer Count and TCP Preread

Post by addonray »

Does anyone know of an "under the hood" way to determine the incoming count of bytes for a file descriptor? My post a few days ago regarding dataavail() hasn't been answered so I'm wondering if there is a direct buffer count way of doing it. I'm porting a Rabbit project that had some handy methods of knowing the incoming counts (prior to calling a read), and trying not to rewrite all of that. On a similar note, the Rabbit TCP stack has a "preread" type of function that lets you keep the RX buffer intact but peek at any count of data in there. Anything like that hidden in the NB libs?

Thanks,

Ray
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: File Descriptor RX Buffer Count and TCP Preread

Post by pbreed »

#include <tcp.h>


WORD TcpGetRxBufferSpaceUsed( int fd )



Just noted that the comment text in tcp.h is wrong.
Looks like there was a comment copy and paste that was mis edited.

Looked at the underlying code and it does what is requested/expected.

Paul
addonray
Posts: 19
Joined: Thu Sep 03, 2015 10:46 am

Re: File Descriptor RX Buffer Count and TCP Preread

Post by addonray »

Thank you, Paul. Any idea how (or if possible) to do the same thing with the UARTS, using the fifo_buffer_storage SpaceUsed() construct?

Regards,

Ray
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: File Descriptor RX Buffer Count and TCP Preread

Post by pbreed »

You can write a function that uses the similar function from the buffer storage on the serial driver...

At some level this approach bothers me a little, because it implies that you are testing things in a loop

I think in general its probably better to put each group of reads in a task and use select to pend on the reads.
That way a task only wakes up and is busy if it has something to do....


Paul
addonray
Posts: 19
Joined: Thu Sep 03, 2015 10:46 am

Re: File Descriptor RX Buffer Count and TCP Preread

Post by addonray »

Thanks for that advice, Paul. I'll do some experiments with Select. I'm porting from a Round-Robin system so much is sure to change.

Regards,

Ray
Post Reply