Browse Source

Refine #2162

pull/2174/head
Max Lv 6 years ago
parent
commit
46ff0a8045
2 changed files with 13 additions and 6 deletions
  1. 9
      src/server.c
  2. 10
      src/udprelay.c

9
src/server.c

@ -2050,6 +2050,7 @@ main(int argc, char **argv)
}
if (mode != TCP_ONLY) {
int num_listen_ctx = 0;
for (int i = 0; i < server_num; i++) {
const char *host = server_host[i];
const char *port = server_port;
@ -2061,7 +2062,13 @@ main(int argc, char **argv)
else
LOGI("udp server listening at %s:%s", host ? host : "0.0.0.0", port);
// Setup UDP
init_udprelay(host, port, mtu, crypto, atoi(timeout), iface);
int err = init_udprelay(host, port, mtu, crypto, atoi(timeout), iface);
if (err == -1) continue;
num_listen_ctx++;
}
if (num_listen_ctx == 0) {
FATAL("failed to listen on any address");
}
}

10
src/udprelay.c

@ -1355,20 +1355,20 @@ init_udprelay(const char *server_host, const char *server_port,
buf_size = packet_size * 2;
}
// Initialize cache
struct cache *conn_cache;
cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);
// ////////////////////////////////////////////////
// Setup server context
// Bind to port
int serverfd = create_server_socket(server_host, server_port);
if (serverfd < 0) {
FATAL("[udp] bind() error");
return -1;
}
setnonblocking(serverfd);
// Initialize cache
struct cache *conn_cache;
cache_create(&conn_cache, MAX_UDP_CONN_NUM, free_cb);
server_ctx_t *server_ctx = new_server_ctx(serverfd);
#ifdef MODULE_REMOTE
server_ctx->loop = loop;

Loading…
Cancel
Save