Skip to content

Commit

Permalink
merge handle and socket into one function
Browse files Browse the repository at this point in the history
  • Loading branch information
garrigue committed Feb 27, 2024
1 parent 1488a00 commit 60d3efe
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/glib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ 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_win32_new_socket"
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: 0 additions & 1 deletion src/glib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ 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
13 changes: 4 additions & 9 deletions src/ml_glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,15 @@ 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)
/* Duplicate for compatibility */
CAMLprim value ml_g_io_channel_win32_new_socket (value arg1) {
return ml_g_io_channel_unix_new (arg1);
}

#else
CAMLprim value ml_g_io_channel_unix_new(value wh)
{
return Val_GIOChannel_noref
(g_io_channel_win32_new_fd
(_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))) ;
}

ML_1 (g_io_channel_win32_new_socket, Socket_val, Val_GIOChannel_noref)
#endif

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

0 comments on commit 60d3efe

Please sign in to comment.