attempt to fix linux function call

This commit is contained in:
Tyler Wilding
2022-04-26 23:58:36 -04:00
parent 0a8bc56b44
commit fd0c64825a
4 changed files with 17 additions and 12 deletions
-3
View File
@@ -139,9 +139,6 @@ add_subdirectory(third-party/imgui)
# build the game code in C++
add_subdirectory(game)
# build asio library
include_directories(third-party/asio/asio/include)
# build the compiler
add_subdirectory(goalc)
+11 -7
View File
@@ -34,8 +34,14 @@ int open_socket(int af, int type, int protocol) {
#endif
}
int accept_socket(int socket, sockaddr* addr, int* addrLen) {
#ifdef __linux
int accept_socket(int socket, sockaddr* addr, socklen_t* addrLen) {
return accept(socket, addr, addrLen);
}
#endif
#ifdef _WIN32
int accept_socket(int socket, sockaddr* addr, int* addrLen) {
WSADATA wsaData = {0};
int iResult = 0;
// Initialize Winsock
@@ -44,9 +50,9 @@ int accept_socket(int socket, sockaddr* addr, int* addrLen) {
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
#endif
return accept(socket, addr, addrLen);
}
#endif
void close_socket(int sock) {
if (sock < 0) {
@@ -93,7 +99,7 @@ int set_socket_timeout(int socket, long microSeconds) {
}
int write_to_socket(int socket, const char* buf, int len) {
int bytes_wrote;
int bytes_wrote = 0;
#ifdef __linux
bytes_wrote = write(socket, buf, len);
#elif _WIN32
@@ -106,13 +112,11 @@ int write_to_socket(int socket, const char* buf, int len) {
}
int read_from_socket(int socket, char* buf, int len) {
int bytes_read;
#ifdef __linux
bytes_read = read(socket, buf, len);
return read(socket, buf, len);
#elif _WIN32
bytes_read = recv(socket, buf, len, 0);
return recv(socket, buf, len, 0);
#endif
return bytes_read;
}
bool socket_timed_out() {
+5 -1
View File
@@ -1,7 +1,7 @@
#pragma once
/*!
* @file xsocket.h
* @file XSocket.h
* Cross platform socket library used for the listener.
*/
@@ -24,7 +24,11 @@ const int TCP_SOCKET_LEVEL = IPPROTO_TCP;
#endif
int open_socket(int af, int type, int protocol);
#ifdef __linux
int accept_socket(int socket, sockaddr* addr, socklen_t* addrLen);
#elif _WIN32
int accept_socket(int socket, sockaddr* addr, int* addrLen);
#endif
void close_socket(int sock);
int set_socket_option(int socket, int level, int optname, const void* optval, int optlen);
int set_socket_timeout(int socket, long microSeconds);
+1 -1
View File
@@ -18,7 +18,7 @@
#undef max
#endif
#include "common/cross_sockets/xsocket.h"
#include "common/cross_sockets/XSocket.h"
#include <stdexcept>
#include <cstring>