Skip to content

beginPacket can be used without listening on socket #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions libraries/WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,29 @@ int WiFiUDP::beginMulticastPacket(){
int WiFiUDP::beginPacket(){
if(!remote_port)
return 0;

// allocate tx_buffer if is necessary
if(!tx_buffer){
tx_buffer = new char[1460];
if(!tx_buffer){
log_e("could not create tx buffer: %d", errno);
return 0;
}
}

tx_buffer_len = 0;

// check whereas socket is already open
if (udp_server != -1)
return 1;

if ((udp_server=socket(AF_INET, SOCK_DGRAM, 0)) == -1){
log_e("could not create socket: %d", errno);
return 0;
}

fcntl(udp_server, F_SETFL, O_NONBLOCK);

return 1;
}

Expand Down