Re: TCP/IP Sockets with GNAT.Sockets



On 2 May 2005 13:22:41 -0700, "fabio de francesco" <fmdf@xxxxxxxxxx>
wrote:
<snip>
> TCP is a byte-stream protocol with NO record boundaries. When reading
> from a TCP socket in a C program we have always to code the read() in a
> loop and terminate only when no more characters are read (function

True -- and important: in the typical program-development environment
programs are run in isolation, often slow-stepped, on unloaded
machines in a secluded subnet, and most if not all TCP/IP stacks in
such environments _do_ "accidentally" preserve buffer boundaries, so
that programs depending on this "appear" to work, and only when they
are deployed to the real-world net of long, heterogenous, overloaded,
and varying paths do they fail, and even then "only" occasionally and
unpredictably, except that by Murphy's law some occasions will be when
your most important user(s)/customer(s)/prospect(s)/boss(es) are doing
something particularly important.

Er, -11L I<rant>$ 9L :L I</>$$
(Or, can I combine those as 9:L ? I can't recall.)

> returns value 0 of type "ssize_t" that could be an Integer in Ada I
> suppose).
>
Socket-for-TCP read() or recv() returns 0 only when the peer has
closed or half-closed, i.e., at "end of file". To read less than all
of the data on the connection (but more than 1 octet) you must code to
read repeatedly (usually in a loop) until you get all of the expected
data, usually determined by a known (fixed or prefix) count or a
delimiter; or with no expectation until a nonblocking socket returns
-1 and sets (the value accessed by) errno to EAGAIN or EWOULDBLOCK or
select/poll indicates no data ready for a sufficient time (which most
simply can be any time at all).

ssize_t will certainly be some integer type. On most machines
addresses are the same "word" size as default integers and thus likely
Integer; and even if the usable object size is much smaller than the
address size and hence nominal address space it is usually convenient
to still use the address size for size_t and ssize_t; but neither of
these is required or guaranteed. Whatever binding(s) you use should
certainly provide a suitable type definition of this for you.

- David.Thompson1 at worldnet.att.net
.



Relevant Pages

  • Re: Is it possible to detect TCP session term without reading pending data?
    ... > I have an application which should only read from a TCP socket if ... > detect if the TCP peer closed the connection from his side. ... poll() becomes useless to me because it only ...
    (comp.unix.programmer)
  • Re: TCP takes a long time to send packet
    ... > I am working on a TCP socket and I am facing this very weird problem. ... > send(sock, sendBuf, strlen(sendBuf), 0); ... requires a C-style string, not an arbitrary collection of data bytes. ...
    (comp.unix.programmer)
  • Re: whereis the socket mailing list
    ... As we know,the close behavier under tcp socket is shown as below: ... the server generates a FIN_ACK from the server, ... The nitty gritty TCP sequencing and timing is a little bit ...
    (perl.beginners)
  • TCP sockets: NO_DELAY
    ... I am new to sockets, and I am trying to write a simple TCP socket using ... force sending a packet. ... All my code is doing is sending short strings and on the host side I am ...
    (microsoft.public.win32.programmer.networks)