Guus Sliepen [Sun, 11 Oct 2015 21:39:23 +0000 (23:39 +0200)]
Reset the snd.nxt pointer when starting packet retransmission.
When a packet was lost, and the send buffer contains more than two packets,
this only retransmitted the first packet from the send buffer, then when it
got acked it would continue with the tail of the buffer. Then it would have
to wait for another timeout to send the next packet from the start of the
send buffer. If the application is continuously sending data, then the send
buffer would never become empty and the problem would persist.
Guus Sliepen [Sun, 11 Oct 2015 15:02:37 +0000 (17:02 +0200)]
Handle direction argument of utcp_shutdown().
For TCP, only shutting down the send direction makes sense, however to
be compatible to the BSD sockets API, keep the direction argument, and
when someone tries to shut down the receive direction, just disable the
receive callback.
Note that on most operating systems, SHUT_RD actually doesn't do
anything at all, it won't prevent reads from returning data.
Also be a bit more strict, return EINVAL or ENOTCONN when appropriate.
Guus Sliepen [Sun, 11 Oct 2015 14:31:59 +0000 (16:31 +0200)]
Add a function to check for active connections.
If a connection sends data in one way, then the receiver will have shut
down data in the other way, and when the sender is finished he will also
shut down his direction, so the connection looks closed to the sender,
but the receiver might actually still miss the final packets. So UTCP
should keep running until the receiver has received a FINACK and is in the
TIME_WAIT state.
We consider UTCP to be active when there is at least one connection not in
the CLOSED or TIME_WAIT state.
The test program now uses this condition, which allows a transfer of a file
to complete without missing the last few bytes.
Guus Sliepen [Sun, 11 Oct 2015 11:32:55 +0000 (13:32 +0200)]
Use '== -1' to check for errors from functions.
As made obvious by commit 123f53f, the type of ssize_t cannot be trusted
on Windows to actually be signed, so don't use '< 0', as the compiler
will optimize the test away. POSIX also specifies only that -1 signals
an error condition, not any other negative value.
Luckily, comparing an unsigned int to -1 still works as intended.
Guus Sliepen [Wed, 3 Dec 2014 12:42:27 +0000 (13:42 +0100)]
Don't call abort() in retransmit().
The retransmission timer can sometimes get called when in one of the
closing states. This is not implemented yet, but it's better to just
ignore those cases for now than to abort().
Guus Sliepen [Tue, 2 Dec 2014 16:14:13 +0000 (17:14 +0100)]
Disable callbacks when closing a connection.
When an application calls utcp_close() on a previously established
connection, the utcp_connection is kept around to handle FIN(ACK)
packets. However, the peer could still send some data, which should not
trigger the receive callback.
Guus Sliepen [Tue, 2 Dec 2014 11:26:57 +0000 (12:26 +0100)]
Fix and refactor send buffer code.
Make generic buffer handling functions and use those. A problem was
found when resizing a buffer; if new data to be put into the buffer was
more than twice as large as the current buffer size, the code would not
reallocate the buffer large enough.
Guus Sliepen [Wed, 1 Oct 2014 17:18:40 +0000 (19:18 +0200)]
Add a poll callback to UTCP connections.
The callback is called whenever the send buffer of a connection is more
than half empty when utcp_timeout() is called. An argument is passed to
the callee informing him of the maximum number of bytes that will be
accepted when calling utcp_send().
- Outgoing connections automatically get a port number >= 32768 assigned.
- *connect() and *accept() get a port number as argument.
- Connections are now stored in a sorted array with O(log(N)) lookup time.