forked from EXTERNAL/bareiron
support native windows binary compilation
* add winsock2 to globals.c * add winsocket2 compatibility to main function * add winsocket2 to packets.c * and winsocket2 to procedures.c * add winsocket 2 compatibility to tools.c * add winsocket2 to varnum.c * add mingw64 linker options to build.sh * fix build * style nitpicks * remove old_fd * update compilation instructions for windows --------- Co-authored-by: p2r3 <41925384+p2r3@users.noreply.github.com>
This commit is contained in:
20
src/tools.c
20
src/tools.c
@@ -7,8 +7,13 @@
|
||||
#include "lwip/netdb.h"
|
||||
#include "esp_timer.h"
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#ifndef CLOCK_MONOTONIC
|
||||
@@ -95,7 +100,11 @@ ssize_t send_all (int client_fd, const void *buf, ssize_t len) {
|
||||
|
||||
// Busy-wait (with task yielding) until all data has been sent
|
||||
while (sent < len) {
|
||||
ssize_t n = send(client_fd, p + sent, len - sent, MSG_NOSIGNAL);
|
||||
#ifdef _WIN32
|
||||
ssize_t n = send(client_fd, p + sent, len - sent, 0);
|
||||
#else
|
||||
ssize_t n = send(client_fd, p + sent, len - sent, MSG_NOSIGNAL);
|
||||
#endif
|
||||
if (n > 0) { // some data was sent, log it
|
||||
sent += n;
|
||||
last_update_time = get_program_time();
|
||||
@@ -106,7 +115,12 @@ ssize_t send_all (int client_fd, const void *buf, ssize_t len) {
|
||||
return -1;
|
||||
}
|
||||
// not yet ready to transmit, try again
|
||||
#ifdef _WIN32 //handles windows socket timeout
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK || err == WSAEINTR) {
|
||||
#else
|
||||
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
#endif
|
||||
// handle network timeout
|
||||
if (get_program_time() - last_update_time > NETWORK_TIMEOUT_TIME) {
|
||||
disconnectClient(&client_fd, -2);
|
||||
|
Reference in New Issue
Block a user