Hi,
I need to analyze a potrential situation and possibly change the strategy
of our application. Here is the critical part of the application which has
to do with sockets (SunOS, TCP sockets, C language and gcc complier).
When a certain test starts, a Supplier starts generating packets and writing
them to a socket. This is done in a loop, where on each iteration a packet is
written (and other, non-related things happen as well). Another part of
the system, a Consumer, reads these packets as they arrive on the socket.
This is done in a totally asyncronous mode, till the end of the test. The
problem is that sometimes the Consumer consumes the packets in a slower pace
than the Supplier generates them. Therefore there is a need to add some
"smart" logic to the Supplier, so that it will be able to detect when there
are packets still waiting to be consumed, and not generate a packet at such
time.
I did not find (or just missed) any ideas in Stevens books, or FAQ.
One direction I have at the moment is to change the write() of the
Supplier to something like (in pseudo-code):
while( not-finished-writing-whole-packet )
{
n = write(osock, packet, size);
if( n == size )
finished-writing-whole-packet;
else
{
decrease size by value of n;
advance some pointer on packet;
}
However, this is just temporary and is probably not sufficient, becauseQuote:}
now the Supplier does not take care of other events in its main loop and is
really busy with the Consumer (and depends on its speed). What I would really
like to have in the main loop of the Supplier is:
while( run-forever-in-this-main-loop )
{
if( no-packets-pending-on-socket ||
just-a-few-packets-pending-on-socket ||
enough-space-on-the-socket-to-write-another-packet )
generate-and-write-another-packet;
/* continue with other events and things to do */
...
I would appreciate any ideas/pointers/suggestions.Quote:}
--
\_\_\_ Without action there is no change. _/_/_/