Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!nsc!voder!blia!ted From: ted@blia.sharebase.com (Ted Marshall) Newsgroups: comp.protocols.tcp-ip Subject: Re: Problems with TCP, read(), and write() Message-ID: <13790@blia.sharebase.com> Date: 4 Apr 91 00:26:58 GMT References: <1991Mar30.174657.28200@wpi.WPI.EDU> Organization: ShareBase Corp, Los Gatos, CA Lines: 26 The problem is that TCP is a pure stream protocol that does not preserve record boundries. Thus, if something delays the processing on some of the bytes from one of your write()s, your read can easily complete with only the beginning of what we written. Since you know that all "records" are 32 bytes, there is a real easy solution: if your read() completes with less than 32 bytes, add that count to your buffer pointer, subtract the count from your buffer size, and repeat the read. Continue this loop until your buffer is full. For example: ptr = &buffer[0]; cnt = sizeof buffer; do { i = read(d, ptr, cnt); if (i <= 0) ptr += i; cnt -= i; } while (cnt > 0); -- Ted Marshall ted@airplane.sharebase.com ShareBase Corp., 14600 Winchester Blvd, Los Gatos, Ca 95030 (408)378-7000 The opinions expressed above are those of the poster and not his employer.