[En-Nut-Discussion] TCP MSS

Ole Reinhardt ole.reinhardt at embedded-it.de
Wed Sep 30 11:53:28 CEST 2009


Hi Andras,

> But I have a problem on doing the same on a GPRS link. I tried to read  
> the file by 256, 128 or 64 byte chunks,
> but after 2 256 byte read the fread only read 24 byte. The same is  
> true for 128 or 64 byte chunk, so I always read
> 536 byte, which is default TCP_MAXSEG.

I don't know if I understand your problem correctly. But let me try to
explain... The GPRS modem is connected by a serial line, right? Caused
by buffersizes etc. the fread from a serial line is not garanteed to
always return the same number of bytes you asked for...

So fread(buffer, 1, 256, stream); will not necessarily return 256 bytes.
That's independent on the device you read from and depends on the driver
internal buffering and / or the transport media the dataflow is read
from. IP packages might be larger then 256 bytes, so on an ethernte
cable, where the MTU is set to approximately 1500 bytes you may always
receive full IP packages of 256 in just on fread. But on another
transport medium like GPRS you might perhaps just read two times 256
bytes, next 24 as this is what your driver is giving you at the moment.
Eventually even the packet size of grps is somewhat more limited, but
this is far beyond my knowledge..

If you always want to read 256 bytes try a construct like this:

uchar buffer[256];
int   offset;
int   size;

offset = size = 0;

do {
    size = fread(&buffer[offset], 1, 256-offset, stream);
    offset += size;
} while (size > 0) && (offset < 256);

Bye,

Ole


-- 
 _____________________________________________________________
|                                                             |
| Embedded-IT                                                 |
|                                                             |
| Ole Reinhardt        Tel. / Fax:        +49 (0)271  7420433 |
| Luisenstraße 29      Mobil:             +49 (0)177  7420433 |
| 57076 Siegen         eMail:    ole.reinhardt at embedded-it.de |
| Germany              Web:         http://www.embedded-it.de |
|_____________________________________________________________|




More information about the En-Nut-Discussion mailing list