Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function channel_of_descr_socket (windows has different handles for sockets and files) #176

Merged
merged 4 commits into from
May 14, 2024
Merged
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
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
Loading