From 78b699e907fd9da8eebf1f5954667abfdaff09ac Mon Sep 17 00:00:00 2001 From: Arnaud Grandville Date: Tue, 20 May 2014 16:55:34 +0200 Subject: [PATCH 1/7] I remove the libuv dependency and replace it with a simple link because uv.gyp compilation failed (uv_library parameter is missing ) --- samples/socks5-proxy/build.gyp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/samples/socks5-proxy/build.gyp b/samples/socks5-proxy/build.gyp index 771a1e146d..cba7a00e65 100644 --- a/samples/socks5-proxy/build.gyp +++ b/samples/socks5-proxy/build.gyp @@ -19,9 +19,8 @@ # IN THE SOFTWARE. { - 'targets': [ + 'targets': [ { - 'dependencies': ['../../uv.gyp:libuv'], 'target_name': 's5-proxy', 'type': 'executable', 'sources': [ @@ -36,7 +35,12 @@ 'conditions': [ ['OS=="win"', { 'defines': ['HAVE_UNISTD_H=0'], - 'sources': ['getopt.c'] + 'sources': ['getopt.c'], + 'link_settings': { + 'libraries': ['-llibuv.lib','-ladvapi32.lib','-lWs2_32.lib','-lPsapi.lib','-lIphlpapi.lib'], + 'library_dirs': ['../../Debug/lib'] + }, + 'include_dirs': ['../../include'] }, { 'defines': ['HAVE_UNISTD_H=1'] }] From d24e0dd3daa0c5cb9c2d0398c6a3839260b13498 Mon Sep 17 00:00:00 2001 From: Arnaud Grandville Date: Tue, 20 May 2014 16:56:39 +0200 Subject: [PATCH 2/7] specific unix include exclude --- samples/socks5-proxy/server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/socks5-proxy/server.c b/samples/socks5-proxy/server.c index 3f1ba42c9e..3267e15d38 100644 --- a/samples/socks5-proxy/server.c +++ b/samples/socks5-proxy/server.c @@ -20,7 +20,9 @@ */ #include "defs.h" +#if !defined(_WIN32) #include /* INET6_ADDRSTRLEN */ +#endif #include #include From 94a70c4f25f580562e1685c8b32566314725d818 Mon Sep 17 00:00:00 2001 From: Arnaud Grandville Date: Tue, 20 May 2014 16:57:53 +0200 Subject: [PATCH 3/7] to set the binding address parameter must be suffixed by '-b' not '-H' --- samples/socks5-proxy/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/socks5-proxy/main.c b/samples/socks5-proxy/main.c index 04020cbd3a..344d1ff596 100644 --- a/samples/socks5-proxy/main.c +++ b/samples/socks5-proxy/main.c @@ -63,9 +63,9 @@ const char *_getprogname(void) { static void parse_opts(server_config *cf, int argc, char **argv) { int opt; - while (-1 != (opt = getopt(argc, argv, "H:hp:"))) { + while (-1 != (opt = getopt(argc, argv, "b:hp:"))) { switch (opt) { - case 'H': + case 'b': cf->bind_host = optarg; break; From 2322e4776662b437555cd835c0ce44b235970a8e Mon Sep 17 00:00:00 2001 From: Arnaud Grandville Date: Tue, 20 May 2014 16:58:48 +0200 Subject: [PATCH 4/7] specific unix header exclude from windows compilation --- samples/socks5-proxy/getopt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/socks5-proxy/getopt.c b/samples/socks5-proxy/getopt.c index 8481b2264f..9e7cde3ffa 100644 --- a/samples/socks5-proxy/getopt.c +++ b/samples/socks5-proxy/getopt.c @@ -36,8 +36,9 @@ static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; #include #include #include +#if !defined(_WIN32) #include - +#endif extern const char *_getprogname(void); int opterr = 1, /* if error message should be printed */ From dba1fa4a136881e4a461ff2ddf94af6aed55341b Mon Sep 17 00:00:00 2001 From: Arnaud Grandville Date: Tue, 20 May 2014 17:04:21 +0200 Subject: [PATCH 5/7] in the uv_timer_start callback function timer_expire no more need the status parameter the conn struct is modified to let the conn_connect function reset it without filling the address with zero some modifications to reflect the new struct --- samples/socks5-proxy/client.c | 16 +++++++--------- samples/socks5-proxy/defs.h | 10 ++++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/samples/socks5-proxy/client.c b/samples/socks5-proxy/client.c index ae9913a1c6..ab1f94ca4c 100644 --- a/samples/socks5-proxy/client.c +++ b/samples/socks5-proxy/client.c @@ -95,7 +95,7 @@ static int do_kill(client_ctx *cx); static int do_almost_dead(client_ctx *cx); static int conn_cycle(const char *who, conn *a, conn *b); static void conn_timer_reset(conn *c); -static void conn_timer_expire(uv_timer_t *handle, int status); +static void conn_timer_expire(uv_timer_t *handle); static void conn_getaddrinfo(conn *c, const char *hostname); static void conn_getaddrinfo_done(uv_getaddrinfo_t *req, int status, @@ -530,7 +530,7 @@ static int do_kill(client_ctx *cx) { new_state = s_almost_dead_1; if (cx->state == s_req_lookup) { new_state = s_almost_dead_0; - uv_cancel(&cx->outgoing.t.req); + uv_cancel(&cx->outgoing.req); } conn_close(&cx->incoming); @@ -582,10 +582,8 @@ static void conn_timer_reset(conn *c) { 0)); } -static void conn_timer_expire(uv_timer_t *handle, int status) { +static void conn_timer_expire(uv_timer_t *handle) { conn *c; - - CHECK(0 == status); c = CONTAINER_OF(handle, conn, timer_handle); c->result = UV_ETIMEDOUT; do_next(c->client); @@ -599,7 +597,7 @@ static void conn_getaddrinfo(conn *c, const char *hostname) { hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; CHECK(0 == uv_getaddrinfo(c->client->sx->loop, - &c->t.addrinfo_req, + &c->addrinfo_req, conn_getaddrinfo_done, hostname, NULL, @@ -612,7 +610,7 @@ static void conn_getaddrinfo_done(uv_getaddrinfo_t *req, struct addrinfo *ai) { conn *c; - c = CONTAINER_OF(req, conn, t.addrinfo_req); + c = CONTAINER_OF(req, conn, addrinfo_req); c->result = status; if (status == 0) { @@ -635,7 +633,7 @@ static int conn_connect(conn *c) { ASSERT(c->t.addr.sa_family == AF_INET || c->t.addr.sa_family == AF_INET6); conn_timer_reset(c); - return uv_tcp_connect(&c->t.connect_req, + return uv_tcp_connect(&c->connect_req, &c->handle.tcp, &c->t.addr, conn_connect_done); @@ -648,7 +646,7 @@ static void conn_connect_done(uv_connect_t *req, int status) { return; /* Handle has been closed. */ } - c = CONTAINER_OF(req, conn, t.connect_req); + c = CONTAINER_OF(req, conn, connect_req); c->result = status; do_next(c->client); } diff --git a/samples/socks5-proxy/defs.h b/samples/socks5-proxy/defs.h index 99ee8160c8..5596a5dbdc 100644 --- a/samples/socks5-proxy/defs.h +++ b/samples/socks5-proxy/defs.h @@ -26,10 +26,12 @@ #include "uv.h" #include -#include /* sockaddr_in, sockaddr_in6 */ #include /* size_t, ssize_t */ #include +#if !defined(_WIN32) +#include /* sockaddr_in, sockaddr_in6 */ #include /* sockaddr */ +#endif struct client_ctx; @@ -59,11 +61,11 @@ typedef struct { } handle; uv_timer_t timer_handle; /* For detecting timeouts. */ uv_write_t write_req; + uv_getaddrinfo_t addrinfo_req; + uv_connect_t connect_req; + uv_req_t req; /* We only need one of these at a time so make them share memory. */ union { - uv_getaddrinfo_t addrinfo_req; - uv_connect_t connect_req; - uv_req_t req; struct sockaddr_in6 addr6; struct sockaddr_in addr4; struct sockaddr addr; From e0baf5067a62d11f062a3dee657b1b9498e818c0 Mon Sep 17 00:00:00 2001 From: Arnaud Grandville Date: Tue, 20 May 2014 17:05:12 +0200 Subject: [PATCH 6/7] a wrapper to compile build.gyp correctly --- samples/socks5-proxy/vcbuild.bat | 1 + 1 file changed, 1 insertion(+) create mode 100644 samples/socks5-proxy/vcbuild.bat diff --git a/samples/socks5-proxy/vcbuild.bat b/samples/socks5-proxy/vcbuild.bat new file mode 100644 index 0000000000..b7462a8077 --- /dev/null +++ b/samples/socks5-proxy/vcbuild.bat @@ -0,0 +1 @@ +python ..\..\gyp_uv.py build.gyp --generator-output=build \ No newline at end of file From 3b32002117f2b319ce72989b121929d76ae997df Mon Sep 17 00:00:00 2001 From: Arnaud Grandville Date: Wed, 21 May 2014 09:02:41 +0200 Subject: [PATCH 7/7] adding a missing variable To compile the libuv dependency, uv_library must a be declared --- samples/socks5-proxy/build.gyp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/samples/socks5-proxy/build.gyp b/samples/socks5-proxy/build.gyp index cba7a00e65..ca9f14c658 100644 --- a/samples/socks5-proxy/build.gyp +++ b/samples/socks5-proxy/build.gyp @@ -19,11 +19,13 @@ # IN THE SOFTWARE. { - 'targets': [ + 'targets': [ { - 'target_name': 's5-proxy', - 'type': 'executable', - 'sources': [ + 'variables': {'uv_library': 'static'}, + 'dependencies': ['../../uv.gyp:libuv'], + 'target_name': 's5-proxy', + 'type': 'executable', + 'sources': [ 'client.c', 'defs.h', 'main.c', @@ -35,12 +37,7 @@ 'conditions': [ ['OS=="win"', { 'defines': ['HAVE_UNISTD_H=0'], - 'sources': ['getopt.c'], - 'link_settings': { - 'libraries': ['-llibuv.lib','-ladvapi32.lib','-lWs2_32.lib','-lPsapi.lib','-lIphlpapi.lib'], - 'library_dirs': ['../../Debug/lib'] - }, - 'include_dirs': ['../../include'] + 'sources': ['getopt.c'] }, { 'defines': ['HAVE_UNISTD_H=1'] }]