Re: problems for TCP/IP read

New Message Reply Date view Thread view Subject view Author view

Paul Sherman (paul++at++bham-ht.bioc.uab.edu)
Mon, 11 Aug 1997 09:30:25 -0500 (CDT)


> thought this is a communicatin problem, I think lots of simulation
> progrmmers already have this question and may know how to solve it.
>
> I try to do the inter-Chassis communication and use the
> socket communication codes from examples - "accept and
> connect" under directory "/usr/people/4Dgifts/examples/network"
> but the "read" command not always read the size which I specify
> in "read(sock, data, size)". Is there any way I can ask "read" always
> to read size of data?

Sam,

One way to solve this is to read from the socket until you have the correct
size of a packet read in (it sounds like you always know that you have 6
floats) and then translate that packet. If you have the socket read do its
read into a buffer and then translate the buffer after you are certain that
you have a complete packet, then you can avoid the attempted translation of
partial packets. In other words, do something like:

while(simNotDone)
{
   while (packetNotComplete)
   {
      while ((cnt = read(into_a_buffer...) > 0);
      check for a complete packet;
   }
   translate the packet;
   perform bookkeeping on the possible partial packet left in the buffer;
}

Of course there is alot more bookkeeping involved in this, since depending on
your code, it is possible to read packet fragments and these need to be kept
track of...

However, one approach which we have been using recently which appears to be
faster and more robust than sockets is to use fifos (or named pipes). This
approach avoids the whole network layer inherant in sockets. So far, the code
is a little unstable on MP machines during startup (deadlock conditions in
opens), but once running, the code works perfectly (tested on a 2 Proc IR and
a 4 proc Onyx 2). For details, check out "Unix Network Programming" by
W. Richard Stevens (Prentice Hall), Chapter 3.

Hope this helps, and email me with any questions (see below).

                Paul Sherman
                psherman++at++acm.org

===========================================================================
Please note that the email to reply to is: psherman++at++acm.org. The email
addresses paul++at++ht.com and paul++at++bham-ht.bioc.uab.edu will not be valid past
Thursday August 14, 1997. I am changing jobs and will not know my new email
until after September 1. I will be able to read email sent to
psherman++at++acm.org. My email responses during the last two weeks of August may
be slow due to my travelling across the country.
===========================================================================
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:55:43 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.