Page 1 of 1

File Descriptor RX Buffer Count and TCP Preread

Posted: Mon Apr 24, 2017 1:03 pm
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

Re: File Descriptor RX Buffer Count and TCP Preread

Posted: Mon Apr 24, 2017 2:23 pm
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

Re: File Descriptor RX Buffer Count and TCP Preread

Posted: Mon Apr 24, 2017 4:01 pm
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

Re: File Descriptor RX Buffer Count and TCP Preread

Posted: Mon Apr 24, 2017 6:28 pm
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

Re: File Descriptor RX Buffer Count and TCP Preread

Posted: Tue Apr 25, 2017 5:34 am
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