-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathluv_unix.c
65 lines (50 loc) · 1.41 KB
/
luv_unix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// This file is part of Luv, released under the MIT license. See LICENSE.md for
// details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md.
#define CAML_NAME_SPACE
#include <caml/mlvalues.h>
#include <caml/unixsupport.h>
#include <uv.h>
CAMLprim value luv_unix_fd_to_os_fd(value unix_fd, value os_fd_storage)
{
uv_os_fd_t *os_fd = (uv_os_fd_t*)Nativeint_val(os_fd_storage);
#ifndef _WIN32
*os_fd = Int_val(unix_fd);
#else
if (Descr_kind_val(unix_fd) == KIND_HANDLE)
*os_fd = Handle_val(unix_fd);
else
*os_fd = -1;
#endif
return Val_unit;
}
CAMLprim value luv_unix_fd_to_os_socket(value unix_fd, value os_socket_storage)
{
uv_os_sock_t *os_socket = (uv_os_sock_t*)Nativeint_val(os_socket_storage);
#ifndef _WIN32
*os_socket = Int_val(unix_fd);
#else
if (Descr_kind_val(unix_fd) == KIND_SOCKET)
*os_socket = Handle_val(unix_fd);
else
*os_socket = -1;
#endif
return Val_unit;
}
CAMLprim value luv_os_fd_to_unix_fd(value os_fd_storage)
{
uv_os_fd_t *os_fd = (uv_os_fd_t*)Nativeint_val(os_fd_storage);
#ifndef _WIN32
return Val_int(*os_fd);
#else
return win_alloc_handle(*os_fd);
#endif
}
CAMLprim value luv_os_socket_to_unix_fd(value os_socket_storage)
{
uv_os_sock_t *os_socket = (uv_os_sock_t*)Nativeint_val(os_socket_storage);
#ifndef _WIN32
return Val_int(*os_socket);
#else
return win_alloc_socket(*os_socket);
#endif
}