Seeking some design advice

Post your example source code and application notes to share with others
Post Reply
Posts: 22
Joined: Tue Dec 01, 2009 2:12 pm

Seeking some design advice

Post by ellisonsoftware » Sun Jun 13, 2010 10:27 am

Hi folks,

I am looking for some advice relative to a software application currently in design to run on NetBurner modules under uc/OS.

Essentially the applications calls for the equivalent of a central event loop that handles input/output over SSH, Telnet, Local Serial Port and will relay this input/output to another local serial port. The central event loop will also handle the instrumentation calls from the SNMP agent.

My questions focus upon the following aspect:
- is it simpler to create a separate OSTask for each input output/port as well as the SNMP agent, use fifo queues to exchange messages between tasks and rely upon the OSFifoPend() call?
- is it simpler to use a primary/central OSTask for all input/output ports, plus use a localhost port to connect the SNMP agent task to the primary task and rely upon the select() call?

Either approach will in all likelihood work just fine- but if one approach is considerably less complex and easier to code and test, then that would be preferred.
I appreciate all suggestions and comments!

- Mark

User avatar
Posts: 761
Joined: Thu Apr 24, 2008 3:58 pm

Re: Seeking some design advice

Post by pbreed » Mon Jun 14, 2010 8:37 am

I would probably go for the select call.
Rather than using the local host port, I'd create a custom file descriptor to wake up the select.

Basic rought outline of how this would work:

#include <iointernal.h>

Then create functions to read,write,close data

/* Expanded I/I functions for use when allocating extra file descriptors */
IoExpandStruct NullFuncs;

int NULL_read( int fd, char* buf, int len )
return 0;

int NULL_write( int fd, const char* buf, int len )
return 0;

int NULL_close( int fd )
return 0;

//The in initialization..

/* Setup FD */ = NULL_read;
NullFuncs.write = NULL_write;
NullFuncs.close = NULL_close;
FD_communicate= GetExtraFD( NULL, &NullFuncs );

Then put the FD_communicate in your select.
To manipulate the state monitored inside select:
void SetDataAvail( int fd );
void ClrDataAvail( int fd );

void SetWriteAvail( int fd );
void ClrWriteAvail( int fd );

void SetHaveError( int fd );
void ClrHaveError( int fd );

SetDataAvail(FD_communicate); will release a select waiting for data on this FD
Make sure to ClrDataAvail(FD_communicate) when you pop out of the select.

This is the bare bones FD communication scheme. You can obviously populate the read,write,close functions to actually allow you to send receive data like a local pipe or something.
If you do this you need to know about a few more things.

In the GetExtraFD call the first parameter is a void * that is used to identify this particular FD.
Then when you read, or write function gets called you call

void *GetExtraData( int fd );

To get the void * data associated with this FD.
Note on this platform void * is a 32 bit "Thing" so you can cast pointers, int, DWORD etc... to or from void *
(you can not cast double or long long because they are 64 bit items)

Lastly to be 100% complete some notes:

If you finish using the extra FD and want to close it, void FreeExtraFd( int fd ), usually called in the close function.
Also the IoExpandStruct can be shared with multiple extra FD's so one could write a class where
you malloc or new a data structure passed in the void * and then could have a bunch of instances of it.

When reading requests for help its some times hard to judge the skill level of the person asking the question,
so its also sometimes hard to judge if the solution presented matches the skill level of the questioner.
So if you need more info please ask.

Writing an example "pipe" using this functionality has been on my todo list for awhile.


Posts: 56
Joined: Thu Apr 24, 2008 4:23 pm
Location: Boston

Re: Seeking some design advice

Post by fanat9 » Fri Feb 24, 2012 12:21 pm

Hey Paul,

Looks like we still don't have that "pipe" example finished =)

I was thinking about exact trick to wake up select() by using custom descriptor. I start to search on stackoverflow first and then here and found this post. Apparently its a known trick.

I found detailed description in NNDKProgMan.pdf :)

Post Reply