1
0
mirror of https://github.com/p2r3/bareiron.git synced 2025-10-02 07:35:08 +02:00

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:
jcfb
2025-09-14 15:11:56 +01:00
committed by GitHub
parent f6333429eb
commit 26f068bc09
8 changed files with 115 additions and 16 deletions

View File

@@ -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);