From c0be7a64fda56db83e6428f173845d45728442e1 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 14 Aug 2023 16:14:37 -0400
Subject: [PATCH] Patched to compile with Visual Studio.
The CMake change is just pasted in from SDL_image, to coerce MSVC to
generate an import library, which it won't do if it thinks there are
no public symbols in the DLL, but this was a blind paste, and should
be considered suspect for now.
---
CMakeLists.txt | 6 ++++++
SDL_net.c | 8 ++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1407b40..5fa7bdd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,6 +9,12 @@ target_include_directories(SDL3_net PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SO
target_link_libraries(SDL3_net PRIVATE SDL3::SDL3)
if(WIN32)
target_link_libraries(SDL3_net PRIVATE ws2_32)
+ set_target_properties(SDL3_net PROPERTIES
+ OUTPUT_NAME "SDL3_net"
+ DEFINE_SYMBOL DLL_EXPORT
+ EXPORT_NAME SDL3_net
+ C_VISIBILITY_PRESET "hidden"
+ )
endif()
if(UNIX AND NOT APPLE)
set_property(TARGET SDL3_net PROPERTY SOVERSION ${PROJECT_VERSION_MAJOR})
diff --git a/SDL_net.c b/SDL_net.c
index 32cf4a8..e24c777 100644
--- a/SDL_net.c
+++ b/SDL_net.c
@@ -845,14 +845,14 @@ static int PumpStreamSocket(SDLNet_StreamSocket *sock)
return 0; // streams are reliable, so instead of packet loss, we introduce lag.
}
- const ssize_t bw = write(sock->handle, sock->pending_output_buffer, sock->pending_output_len);
+ const int bw = (int) write(sock->handle, sock->pending_output_buffer, sock->pending_output_len);
if (bw < 0) {
const int err = LastSocketError();
return WouldBlock(err) ? 0 : SDL_SetError("Failed to write to socket: %s", strerror(err));
- } else if (bw < (ssize_t) sock->pending_output_len) {
- SDL_memmove(sock->pending_output_buffer, sock->pending_output_buffer + bw, sock->pending_output_len - (int) bw);
+ } else if (bw < sock->pending_output_len) {
+ SDL_memmove(sock->pending_output_buffer, sock->pending_output_buffer + bw, sock->pending_output_len - bw);
}
- sock->pending_output_len -= (int) bw;
+ sock->pending_output_len -= bw;
UpdateStreamSocketSimulatedFailure(sock);
}