Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ elseif(UNIX AND NOT APPLE)
message(STATUS "ON LINUX WASM BUILD")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(STATUS "ON LINUX BUILD")
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
message(STATUS "ON FREEBSD BUILD")
else()
message(FATAL_ERROR "Unsupported operating system. Please create issue or contribute!")
endif()
set(MGCLIENT_ON_LINUX TRUE)
add_definitions(-DMGCLIENT_ON_LINUX)
# Linux and FreeBSD share the same POSIX socket path in src/linux/,
# selected by MGCLIENT_ON_POSIX.
set(MGCLIENT_ON_POSIX TRUE)
add_definitions(-DMGCLIENT_ON_POSIX)
set(MGCLIENT_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
elseif(APPLE)
message(STATUS "ON APPLE BUILD")
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(mgclient_src_files
mgvalue.c)
if(MGCLIENT_ON_APPLE)
list(APPEND mgclient_src_files apple/mgsocket.c)
elseif(MGCLIENT_ON_LINUX)
elseif(MGCLIENT_ON_POSIX)
list(APPEND mgclient_src_files linux/mgsocket.c)
elseif(MGCLIENT_ON_WINDOWS)
list(APPEND mgclient_src_files windows/mgsocket.c)
Expand Down
4 changes: 4 additions & 0 deletions src/linux/mgcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#ifndef MGCLIENT_LINUX_MGCOMMON_H
#define MGCLIENT_LINUX_MGCOMMON_H

#if defined(__FreeBSD__)
#include <sys/endian.h>
#else
#include <endian.h>
#endif

#endif
8 changes: 4 additions & 4 deletions src/linux/mgsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ int mg_socket_options(int sock, mg_session *session) {
int optname;
int optval;
} socket_options[] = {// disable Nagle algorithm for performance reasons
{SOL_TCP, TCP_NODELAY, 1},
{IPPROTO_TCP, TCP_NODELAY, 1},
// turn keep-alive on
{SOL_SOCKET, SO_KEEPALIVE, 1},
// wait 20s before sending keep-alive packets
{SOL_TCP, TCP_KEEPIDLE, 20},
{IPPROTO_TCP, TCP_KEEPIDLE, 20},
// 4 keep-alive packets must fail to close
{SOL_TCP, TCP_KEEPCNT, 4},
{IPPROTO_TCP, TCP_KEEPCNT, 4},
// send keep-alive packets every 15s
{SOL_TCP, TCP_KEEPINTVL, 15}};
{IPPROTO_TCP, TCP_KEEPINTVL, 15}};
const size_t OPTCNT = sizeof(socket_options) / sizeof(socket_options[0]);

for (size_t i = 0; i < OPTCNT; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions src/mgcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ extern "C" {
#include "apple/mgcommon.h"
#endif // MGCLIENT_ON_APPLE

#ifdef MGCLIENT_ON_LINUX
#ifdef MGCLIENT_ON_POSIX
#include "linux/mgcommon.h"
#endif // MGCLIENT_ON_LINUX
#endif // MGCLIENT_ON_POSIX

#ifdef MGCLIENT_ON_WINDOWS
#include "windows/mgcommon.h"
Expand Down
4 changes: 2 additions & 2 deletions src/mgsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
#include <unistd.h>
#endif // MGCLIENT_ON_APPLE

#ifdef MGCLIENT_ON_LINUX
#ifdef MGCLIENT_ON_POSIX
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
Expand All @@ -38,7 +38,7 @@ extern "C" {
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#endif // MGCLIENT_ON_LINUX
#endif // MGCLIENT_ON_POSIX

#ifdef MGCLIENT_ON_WINDOWS
#include <Ws2tcpip.h>
Expand Down
4 changes: 2 additions & 2 deletions src/mgtransport.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#ifdef MGCLIENT_ON_LINUX
#ifdef MGCLIENT_ON_POSIX
#ifndef __EMSCRIPTEN__
#include <pthread.h>
#endif
#endif // MGCLIENT_ON_LINUX
#endif // MGCLIENT_ON_POSIX

#include "mgallocator.h"
#include "mgclient.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ add_gtest(client client.cpp)
# We're mocking the mg_secure_transport_init function in the test.
if(MGCLIENT_ON_APPLE)
target_link_libraries(client -Wl,-alias,___wrap_mg_secure_transport_init,_mg_secure_transport_init)
elseif(MGCLIENT_ON_LINUX)
elseif(MGCLIENT_ON_POSIX)
target_link_libraries(client -Wl,--wrap=mg_secure_transport_init)
endif()
add_gtest(transport transport.cpp)
Expand Down
Loading