[PATCH] ada/35953: Guard against empty buffers and end-of-connection

Samuel Tardieu sam@rfc1149.net
Thu Apr 17 12:47:00 GMT 2008


On 17/04, Thomas Quinot wrote:

| * Samuel Tardieu, 2008-04-17 :
| 
| > Right, it will contain First - 1, I had read too fast, not Item'First - 1.
| 
| OK so do you agree that this doesn't require fixing?

Yup.

| > | This optimization looks unnecessary to me. Could you clarify the
| > | rationale here ?
| > 
| > Reading or writing 0 bytes on a socket will cost a system call. If we
| > are using datagrams, it will consume or send an IP packet.
| 
| Well if it is the user's intent to send out a UDP datagram with a zero
| length payload we certainly should permit that. We want to provide a
| reasonably straightforward binding to the sockets API people are used
| to.

We're not talking about the low-level Send/Receive sockets API here,
we're talking about a Ada.Streams oriented API which, here, uses
sockets. Calling Read/Write on other streams is a no-op, here it causes
a system call and maybe a packet exchange.

Note that if it were my choice only I would do the following two things:
  - optimize the TCP case to remove the useless Send/Receive in case of
    an empty buffer
  - forbid taking a stream in the UDP case, as this is most probably an
    error, and if it is not, there is a 99% change that the user is
    clueless and doesn't know he is going something which makes no sense :)

| > As you say, this is an optimization. Why do more job when we can do
| > less?
| 
| I think we should let that optimization up to the user rather than
| forcing it on every use.

If you don't like it, I won't defend it.

| > | > The reason for an unsuccessful Write is also given: either "connection
| > | > closed by peer" or "packet too large for datagram".
| > | 
| > | There is a non-compatible change in behaviour here, with your proposed change
| > | an exception is raised where previously a zero result (which could be
| > | tested by the caller) was returned, so this change is not acceptable.
| > 
| > How would one test for a "zero result" in a Write, when there are no "out"
| > parameter (except the stream which is "in out")? What do you mean?
| 
| Right, sorry, I was confused on that one.

I'll submit a reduced updated patch.



More information about the Gcc-patches mailing list