From ea5a8dc34e0b2e5fd5fcd6c0d37832e9a1074989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Gilbert?= Date: Tue, 14 May 2024 05:59:46 +0200 Subject: [PATCH] Support windows sockets in Glib.IO.channel_of_descr (#176) Co-authored-by: Michael Soegtrop <7895506+MSoegtropIMC@users.noreply.github.com> Co-authored-by: Jacques Garrigue --- src/ml_glib.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ml_glib.c b/src/ml_glib.c index 725f340c..f0ac82ee 100644 --- a/src/ml_glib.c +++ b/src/ml_glib.c @@ -25,6 +25,8 @@ #include #include #ifdef _WIN32 +/* to kill a #warning: include winsock2.h before windows.h */ +#include #include "win32.h" #include #include @@ -38,6 +40,11 @@ #include #include +#ifdef _WIN32 +/* for Socket_val */ +#include +#endif + #include "wrappers.h" #include "ml_glib.h" #include "glib_tags.h" @@ -330,13 +337,14 @@ Make_Val_final_pointer_ext (GIOChannel, _noref, Ignore, g_io_channel_unref, 20) #ifndef _WIN32 ML_1 (g_io_channel_unix_new, Int_val, Val_GIOChannel_noref) - #else CAMLprim value ml_g_io_channel_unix_new(value wh) { return Val_GIOChannel_noref - (g_io_channel_unix_new - (_open_osfhandle((long)*(HANDLE*)Data_custom_val(wh), O_BINARY))); + (Descr_kind_val(wh) == KIND_SOCKET ? + g_io_channel_win32_new_socket(Socket_val(wh)) : + g_io_channel_win32_new_fd + (_open_osfhandle((intptr_t)Handle_val(wh), O_BINARY))) ; } #endif