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
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/glib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ module Io = struct
type id
external channel_of_descr : Unix.file_descr -> channel
= "ml_g_io_channel_unix_new"
external channel_of_descr_socket : Unix.file_descr -> channel
= "ml_g_io_channel_unix_new_socket"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this rather be ml_g_io_channel_win32_new_socket ?
Note that the change is not visible in the interface, so this would not matter for CoqIDE.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean to rename the C function? One can of course do this. The reason I named it this way is that this is still about Windows' emulation of the Unix socket system. But I have no strong feelings about the naming.

external remove : id -> unit = "ml_g_source_remove"
external add_watch :
cond:condition list -> callback:(condition list -> bool) -> ?prio:int -> channel -> id
Expand Down
1 change: 1 addition & 0 deletions src/glib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module Io : sig
type condition = [ `ERR | `HUP | `IN | `NVAL | `OUT | `PRI]
type id
val channel_of_descr : Unix.file_descr -> channel
val channel_of_descr_socket : Unix.file_descr -> channel
val add_watch :
cond:condition list -> callback:(condition list -> bool) -> ?prio:int -> channel -> id
val remove : id -> unit
Expand Down
18 changes: 17 additions & 1 deletion 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,14 +337,23 @@ 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)
CAMLprim value ml_g_io_channel_unix_new_socket (value arg1) {
return Val_GIOChannel_noref (g_io_channel_unix_new (Int_val (arg1)));
}

#else
CAMLprim value ml_g_io_channel_unix_new(value wh)
{
return Val_GIOChannel_noref
(g_io_channel_unix_new
(g_io_channel_win32_new_fd
(_open_osfhandle((long)*(HANDLE*)Data_custom_val(wh), O_BINARY)));
}

CAMLprim value ml_g_io_channel_unix_new_socket(value wh)
{
return Val_GIOChannel_noref
(g_io_channel_win32_new_socket(Socket_val(wh)));
}
#endif

static gboolean ml_g_io_channel_watch(GIOChannel *s, GIOCondition c,
Expand Down