Open ac opened 9 years ago
can you do a pull request of that change?
Here is the patch:
diff --git a/samples/socks5-proxy/client.c b/samples/socks5-proxy/client.c
index ae9913a..00ec98c 100644
--- a/samples/socks5-proxy/client.c
+++ b/samples/socks5-proxy/client.c
@@ -635,7 +635,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 +648,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 99ee816..e539dd5 100644
--- a/samples/socks5-proxy/defs.h
+++ b/samples/socks5-proxy/defs.h
@@ -26,10 +26,16 @@
#include "uv.h"
#include <assert.h>
+#ifdef _WIN32
+#include <Winsock2.h>
+#else
#include <netinet/in.h> /* sockaddr_in, sockaddr_in6 */
+#endif
#include <stddef.h> /* size_t, ssize_t */
#include <stdint.h>
+#ifndef _WIN32
#include <sys/socket.h> /* sockaddr */
+#endif
struct client_ctx;
@@ -60,9 +66,9 @@ typedef struct {
uv_timer_t timer_handle; /* For detecting timeouts. */
uv_write_t write_req;
/* We only need one of these at a time so make them share memory. */
+ uv_connect_t connect_req;
union {
uv_getaddrinfo_t addrinfo_req;
- uv_connect_t connect_req;
uv_req_t req;
struct sockaddr_in6 addr6;
struct sockaddr_in addr4;
The "uv_connect_t connect_req;" member of "conn" structure in defs.h should not be inside "union t" because used in same time as "t.addr4" in connect request. So t.addr4 contents overwrites the t.connect_req.
I've moved connect_req on level up, and now socks server works under Windows too. ... uv_connect_t connect_req; union { uv_getaddrinfo_t addrinfo_req; uv_req_t req; struct sockaddr_in6 addr6; struct sockaddr_in addr4; struct sockaddr addr; char buf[2048]; /* Scratch space. Used to read data into. */ } t; ...