Aurel Bílý пре 6 година
родитељ
комит
3e5919d7dc
3 измењених фајлова са 15 додато и 13 уклоњено
  1. 4 4
      libs/uv/uv.ml
  2. 7 5
      libs/uv/uv_stubs.c
  3. 4 4
      src/macro/eval/evalStdLib.ml

+ 4 - 4
libs/uv/uv.ml

@@ -166,9 +166,9 @@ external tcp_init : t_loop -> t_tcp uv_result = "w_tcp_init"
 external tcp_nodelay : t_tcp -> bool -> unit uv_result = "w_tcp_nodelay"
 external tcp_keepalive : t_tcp -> bool -> int -> unit uv_result = "w_tcp_keepalive"
 external tcp_accept : t_loop -> t_tcp -> t_tcp uv_result = "w_tcp_accept"
-external tcp_bind_ipv4 : t_tcp -> int -> int -> unit uv_result = "w_tcp_bind_ipv4"
+external tcp_bind_ipv4 : t_tcp -> int32 -> int -> unit uv_result = "w_tcp_bind_ipv4"
 external tcp_bind_ipv6 : t_tcp -> bytes -> int -> bool -> unit uv_result = "w_tcp_bind_ipv6"
-external tcp_connect_ipv4 : t_tcp -> int -> int -> unit_cb -> unit uv_result = "w_tcp_connect_ipv4"
+external tcp_connect_ipv4 : t_tcp -> int32 -> int -> unit_cb -> unit uv_result = "w_tcp_connect_ipv4"
 external tcp_connect_ipv6 : t_tcp -> bytes -> int -> unit_cb -> unit uv_result = "w_tcp_connect_ipv6"
 external tcp_getsockname : t_tcp -> uv_ip_address_port uv_result = "w_tcp_getsockname"
 external tcp_getpeername : t_tcp -> uv_ip_address_port uv_result = "w_tcp_getpeername"
@@ -184,9 +184,9 @@ type udp_message = {
 type udp_read_cb = udp_message uv_result -> unit
 
 external udp_init : t_loop -> t_udp uv_result = "w_udp_init"
-external udp_bind_ipv4 : t_udp -> int -> int -> unit uv_result = "w_udp_bind_ipv4"
+external udp_bind_ipv4 : t_udp -> int32 -> int -> unit uv_result = "w_udp_bind_ipv4"
 external udp_bind_ipv6 : t_udp -> bytes -> int -> bool -> unit uv_result = "w_udp_bind_ipv6"
-external udp_send_ipv4 : t_udp -> bytes -> int -> int -> int -> int -> unit_cb -> unit uv_result = "w_udp_send_ipv4_bytecode" "w_udp_send_ipv4"
+external udp_send_ipv4 : t_udp -> bytes -> int -> int -> int32 -> int -> unit_cb -> unit uv_result = "w_udp_send_ipv4_bytecode" "w_udp_send_ipv4"
 external udp_send_ipv6 : t_udp -> bytes -> int -> int -> bytes -> int -> unit_cb -> unit uv_result = "w_udp_send_ipv6_bytecode" "w_udp_send_ipv6"
 external udp_recv_start : t_udp -> udp_read_cb -> unit uv_result = "w_udp_recv_start"
 external udp_recv_stop : t_udp -> unit uv_result = "w_udp_recv_stop"

+ 7 - 5
libs/uv/uv_stubs.c

@@ -7,6 +7,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <uv.h>
 
 #if (UV_VERSION_MAJOR <= 0)
@@ -678,7 +679,7 @@ CAMLprim value w_stream_of_handle(value handle) {
 	struct sockaddr_in var; \
 	var.sin_family = AF_INET; \
 	var.sin_port = htons((unsigned short)port); \
-	var.sin_addr.s_addr = htonl(host);
+	var.sin_addr.s_addr = htonl((unsigned int)host);
 #define UV_SOCKADDR_IPV6(var, host, port) \
 	struct sockaddr_in6 var; \
 	memset(&var, 0, sizeof(var)); \
@@ -723,7 +724,7 @@ CAMLprim value w_tcp_accept(value loop, value server) {
 
 CAMLprim value w_tcp_bind_ipv4(value handle, value host, value port) {
 	CAMLparam3(handle, host, port);
-	UV_SOCKADDR_IPV4(addr, Int_val(host), Int_val(port));
+	UV_SOCKADDR_IPV4(addr, Int32_val(host), Int_val(port));
 	UV_ERROR_CHECK(uv_tcp_bind(Tcp_val(handle), (const struct sockaddr *)&addr, 0));
 	UV_SUCCESS_UNIT;
 }
@@ -737,7 +738,7 @@ CAMLprim value w_tcp_bind_ipv6(value handle, value host, value port, value ipv6o
 
 CAMLprim value w_tcp_connect_ipv4(value handle, value host, value port, value cb) {
 	CAMLparam4(handle, host, port, cb);
-	UV_SOCKADDR_IPV4(addr, Int_val(host), Int_val(port));
+	UV_SOCKADDR_IPV4(addr, Int32_val(host), Int_val(port));
 	UV_ALLOC_REQ(req, uv_connect_t, cb);
 	UV_ERROR_CHECK_C(uv_tcp_connect(Connect_val(req), Tcp_val(handle), (const struct sockaddr *)&addr, (void (*)(uv_connect_t *, int))handle_stream_cb), UV_FREE_REQ(Connect_val(req)));
 	UV_SUCCESS_UNIT;
@@ -838,7 +839,7 @@ CAMLprim value w_udp_init(value loop) {
 
 CAMLprim value w_udp_bind_ipv4(value handle, value host, value port) {
 	CAMLparam3(handle, host, port);
-	UV_SOCKADDR_IPV4(addr, Int_val(host), Int_val(port));
+	UV_SOCKADDR_IPV4(addr, Int32_val(host), Int_val(port));
 	UV_ERROR_CHECK(uv_udp_bind(Udp_val(handle), (const struct sockaddr *)&addr, 0));
 	UV_SUCCESS_UNIT;
 }
@@ -853,7 +854,7 @@ CAMLprim value w_udp_bind_ipv6(value handle, value host, value port, value ipv6o
 CAMLprim value w_udp_send_ipv4(value handle, value msg, value offset, value length, value host, value port, value cb) {
 	CAMLparam5(handle, msg, offset, length, host);
 	CAMLxparam2(port, cb);
-	UV_SOCKADDR_IPV4(addr, Int_val(host), Int_val(port));
+	UV_SOCKADDR_IPV4(addr, Int32_val(host), Int_val(port));
 	UV_ALLOC_REQ(req, uv_udp_send_t, cb);
 	uv_buf_t buf = uv_buf_init(&Byte(msg, Int_val(offset)), Int_val(length));
 	UV_ERROR_CHECK_C(uv_udp_send(UdpSend_val(req), Udp_val(handle), &buf, 1, (const struct sockaddr *)&addr, (void (*)(uv_udp_send_t *, int))handle_stream_cb), UV_FREE_REQ(UdpSend_val(req)));
@@ -1008,6 +1009,7 @@ static void handle_dns_gai_cb(uv_getaddrinfo_t *req, int status, struct addrinfo
 	CAMLreturn0;
 }
 
+// TODO: this is needed for Windows support.
 #ifndef AI_ADDRCONFIG
 #define AI_ADDRCONFIG 0x0400
 #endif

+ 4 - 4
src/macro/eval/evalStdLib.ml

@@ -3502,7 +3502,7 @@ module StdUv = struct
 			let ipv6only = decode_bool ipv6only in
 			wrap_sync (match host with
 				| VEnumValue {eindex = 0; eargs = [|ip|]} ->
-					let ip = decode_int ip in
+					let ip = decode_i32 ip in
 					Uv.tcp_bind_ipv4 this ip port
 				| VEnumValue {eindex = 1; eargs = [|ip|]} ->
 					let ip = decode_bytes ip in
@@ -3516,7 +3516,7 @@ module StdUv = struct
 			let port = decode_int port in
 			wrap_sync (match host with
 				| VEnumValue {eindex = 0; eargs = [|ip|]} ->
-					let ip = decode_int ip in
+					let ip = decode_i32 ip in
 					Uv.tcp_connect_ipv4 this ip port (wrap_cb_unit cb)
 				| VEnumValue {eindex = 1; eargs = [|ip|]} ->
 					let ip = decode_bytes ip in
@@ -3586,7 +3586,7 @@ module StdUv = struct
 				let port = decode_int port in
 				wrap_sync (match address with
 					| VEnumValue {eindex = 0; eargs = [|ip|]} ->
-						let ip = decode_int ip in
+						let ip = decode_i32 ip in
 						Uv.udp_send_ipv4 this msg offset length ip port (wrap_cb_unit cb)
 					| VEnumValue {eindex = 1; eargs = [|ip|]} ->
 						let ip = decode_bytes ip in
@@ -3606,7 +3606,7 @@ module StdUv = struct
 			let ipv6only = decode_bool ipv6only in
 			wrap_sync (match host with
 				| VEnumValue {eindex = 0; eargs = [|ip|]} ->
-					let ip = decode_int ip in
+					let ip = decode_i32 ip in
 					Uv.udp_bind_ipv4 this ip port
 				| VEnumValue {eindex = 1; eargs = [|ip|]} ->
 					let ip = decode_bytes ip in