From 3caa75b9317157a3cbc85b532ca865695207b145 Mon Sep 17 00:00:00 2001 From: Jacob Bandyk Date: Mon, 25 Mar 2024 16:35:53 -0500 Subject: [PATCH] Swap calls to winsock calls --- include/mav/TCPServer.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/include/mav/TCPServer.h b/include/mav/TCPServer.h index 81d4421..251cd3f 100644 --- a/include/mav/TCPServer.h +++ b/include/mav/TCPServer.h @@ -34,13 +34,13 @@ #ifndef LIBMAVLINK_TCPSERVER_H #define LIBMAVLINK_TCPSERVER_H + /* clang-format off */ -#include #include +#include /* clang-format on */ #include -#include "poll.h" // #include // #include // #include @@ -59,7 +59,7 @@ namespace mav { mutable std::atomic_bool _should_terminate{false}; int _master_socket = -1; mutable std::mutex _client_sockets_mutex; - std::vector _poll_fds; + std::vector _poll_fds; int _current_client_socket = -1; ConnectionPartner _current_client; @@ -69,7 +69,7 @@ namespace mav { void _addFd(int fd, int16_t events) { - struct pollfd pfd = {}; + WSAPOLLFD pfd = {}; pfd.fd = fd; pfd.events = events; _poll_fds.push_back(pfd); @@ -183,7 +183,7 @@ namespace mav { } // check for activity on one of the sockets - auto poll_ret = poll(_poll_fds.data(), _poll_fds.size(), 1000); + auto poll_ret = WSAPoll(_poll_fds.data(), _poll_fds.size(), 1000); if (poll_ret < 0) { if (errno == EINTR) { continue; @@ -225,7 +225,9 @@ namespace mav { // do the actual read if (socket_to_read_from >= 0) { - auto ret = read(socket_to_read_from, destination, size - bytes_received); + char* destination_char = (char*)destination; + auto ret = + recv(socket_to_read_from, destination_char, size - bytes_received, 0); if (ret <= 0) { // client disconnected _handleDisconnect(partner_to_read_from, socket_to_read_from); @@ -246,7 +248,8 @@ namespace mav { void _sendToSingleTarget(const uint8_t *data, uint32_t size, int partner_socket) { uint32_t sent = 0; while (sent < size && !_should_terminate.load()) { - auto ret = write(partner_socket, data, size - sent); + char* data_char = (char*)data; + auto ret = ::send(partner_socket, data_char, size - sent, 0); if (ret < 0) { throw NetworkError("Could not write to socket", errno); }