Skip to content

Commit

Permalink
Support windows sockets in Glib.IO.channel_of_descr (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Soegtrop <[email protected]>
Co-authored-by: Jacques Garrigue <[email protected]>
  • Loading branch information
3 people authored May 14, 2024
1 parent c5419e7 commit ea5a8dc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/ml_glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <string.h>
#include <locale.h>
#ifdef _WIN32
/* to kill a #warning: include winsock2.h before windows.h */
#include <winsock2.h>
#include "win32.h"
#include <wtypes.h>
#include <io.h>
Expand All @@ -38,6 +40,11 @@
#include <caml/callback.h>
#include <caml/threads.h>

#ifdef _WIN32
/* for Socket_val */
#include <caml/unixsupport.h>
#endif

#include "wrappers.h"
#include "ml_glib.h"
#include "glib_tags.h"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ea5a8dc

Please sign in to comment.