Page 1 of 1

Determining that all outbound packets are sent ...

Posted: Fri Nov 11, 2016 3:52 pm
by kolban
Imagine I have an app that wishes to wake up, connect to an access point, send data and then disconnect from the access point. I am planning to use UDP datagram messages for transmission. In my logic I was coding:

Code: Select all

sendto(socket, ...); // Send the data gram packet
close(socket); // Close the socket
esp_wifi_disconnect(); // Disconnect from the access point
My concern here is that it initially "appears" that when I issue esp_wifi_disconnect(), the outbound packets may not be being sent before the network connections are shutdown. If I change my logic to be:

Code: Select all

sendto(socket, ...); // Send the data gram packet
close(socket); // Close the socket
sleep(1); // Sleep for a second
esp_wifi_disconnect(); // Disconnect from the access point
I don't appear to have an issue. Should esp_wifi_disconnect() honor buffered transmissions before disconnecting? Is there some other logic that I should be using such as some kind of blocking flush() type API call?

Re: Determining that all outbound packets are sent ...

Posted: Sun Nov 13, 2016 11:49 am
by SpenZerX
I think, before closing the connection you have to check that it is writeable.

sendto(socket, ...); // Send the data gram packet
check/wait writeability or get write finnished callback
sendto(socket, ...); // Send the data gram packet
check/wait writeability or get write finnished callback
close(socket); // Close the socket

if sendto(socket, ...) = write(FD/SD, Buff, Len)

Re: Determining that all outbound packets are sent ...

Posted: Sun Nov 13, 2016 1:25 pm
by WiFive
SpenZerX wrote:I think, before closing the connection you have to check that it is writeable.

sendto(socket, ...); // Send the data gram packet
check/wait writeability or get write finnished callback
sendto(socket, ...); // Send the data gram packet
check/wait writeability or get write finnished callback
close(socket); // Close the socket

if sendto(socket, ...) = write(FD/SD, Buff, Len)
But what if the data was copied out of the socket buffer to the WiFi tx buffer and still sending at the RF layer?

Re: Determining that all outbound packets are sent ...

Posted: Sun Nov 13, 2016 7:21 pm
by SpenZerX
WiFive wrote:
But what if the data was copied out of the socket buffer to the WiFi tx buffer and still sending at the RF layer?
Iam not 100% sure, but i think the socket is writeable again when the data is transmitted and the receiver confirmed ok.

Re: Determining that all outbound packets are sent ...

Posted: Sun Nov 13, 2016 9:20 pm
by WiFive
SpenZerX wrote:
WiFive wrote:
But what if the data was copied out of the socket buffer to the WiFi tx buffer and still sending at the RF layer?
Iam not 100% sure, but i think the socket is writeable again when the data is transmitted and the receiver confirmed ok.
UDP doesn't have ACK