Determining that all outbound packets are sent ...

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Determining that all outbound packets are sent ...

Postby kolban » Fri Nov 11, 2016 3:52 pm

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?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

SpenZerX
Posts: 16
Joined: Sun Dec 13, 2015 9:23 am

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

Postby SpenZerX » Sun Nov 13, 2016 11:49 am

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)
Creator of Smart Connected Devices - for EcSUHA.de Project

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

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

Postby WiFive » Sun Nov 13, 2016 1:25 pm

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?

SpenZerX
Posts: 16
Joined: Sun Dec 13, 2015 9:23 am

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

Postby SpenZerX » Sun Nov 13, 2016 7:21 pm

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.
Creator of Smart Connected Devices - for EcSUHA.de Project

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

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

Postby WiFive » Sun Nov 13, 2016 9:20 pm

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

Who is online

Users browsing this forum: Baidu [Spider] and 286 guests