GNAT sockets are created blocking, so when you call Streams.Read
it will read from the socket until
- your Buffer is full; or
- there aren’t yet any more bytes to read; or
- the socket has been closed.
In case 2, the Read
call blocks until more data arrives. Only in case 3 will you get back an underfull buffer (in your code, Offset
less than Buffer’Last
).
If you have multiple clients, any of which could be sending data, you can use GNAT.Sockets.Check_Selector
to block until one of the client sockets has data to read, and then read from that socket.
As for reading a complete input message, you can read a byte at a time until you reach a terminator (in the case of an HTTP request, that would be a double CR/LF). Of course, you need to agree with the client side what will constitute a terminator.
The answer from @ajb has covered writing.