summaryrefslogtreecommitdiff
path: root/src/opentracker.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/opentracker.c')
-rw-r--r--src/opentracker.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/opentracker.c b/src/opentracker.c
index 759a6d0..81b4df6 100644
--- a/src/opentracker.c
+++ b/src/opentracker.c
@@ -25,6 +25,7 @@
25#include "ot_config.h" 25#include "ot_config.h"
26#include "ot_hex.h" 26#include "ot_hex.h"
27#include "ot_http.h" 27#include "ot_http.h"
28#include "ot_iovec.h"
28#include "ot_ip.h" 29#include "ot_ip.h"
29#include "ot_livesync.h" 30#include "ot_livesync.h"
30#include "ot_mutex.h" 31#include "ot_mutex.h"
@@ -107,6 +108,7 @@ static void *server_mainloop(void *args) {
107 struct iovec *iovector; 108 struct iovec *iovector;
108 size_t iovec_entries; 109 size_t iovec_entries;
109 int is_partial; 110 int is_partial;
111 uint32_t generation;
110 112
111 (void)args; 113 (void)args;
112 114
@@ -149,8 +151,13 @@ static void *server_mainloop(void *args) {
149 } 151 }
150 } 152 }
151 153
152 while ((sock = workqueue_popresult(&iovec_entries, &iovector, &is_partial)) != -1) 154 while ((sock = workqueue_popresult(&iovec_entries, &iovector, &is_partial, &generation)) != -1) {
155 if (fdstate_generation((int)sock) != generation) {
156 iovec_free(&iovec_entries, &iovector);
157 continue;
158 }
153 http_sendiovecdata(sock, &ws, iovec_entries, iovector, is_partial); 159 http_sendiovecdata(sock, &ws, iovec_entries, iovector, is_partial);
160 }
154 161
155 if (time_is_past(next_timeout_check)) { 162 if (time_is_past(next_timeout_check)) {
156 int cursor = 0; 163 int cursor = 0;
@@ -220,6 +227,16 @@ static void listen_bind_one(ot_listen *entry) {
220#endif 227#endif
221} 228}
222 229
230static void listen_warn_if_taken(const ot_listen *entry) {
231 char address[64];
232
233 if (entry->proto != FLAG_UDP || !socket_udp_is_taken(entry->ip, entry->port))
234 return;
235
236 address[ip_format(address, entry->ip)] = 0;
237 fprintf(stderr, "Warning: udp address [%s]:%d is already in use, by another tracker instance perhaps.\n", address, entry->port);
238}
239
223/* Bound in the order the entries were given. 240/* Bound in the order the entries were given.
224 Note: On macOS SO_REUSEPORT delivers everything to the socket that bound last. */ 241 Note: On macOS SO_REUSEPORT delivers everything to the socket that bound last. */
225static void listen_bind_all(void) { 242static void listen_bind_all(void) {
@@ -227,6 +244,9 @@ static void listen_bind_all(void) {
227 ot_listen *entries = config_listen_entries(&count); 244 ot_listen *entries = config_listen_entries(&count);
228 245
229 for (i = 0; i < count; ++i) 246 for (i = 0; i < count; ++i)
247 listen_warn_if_taken(entries + i);
248
249 for (i = 0; i < count; ++i)
230 listen_bind_one(entries + i); 250 listen_bind_one(entries + i);
231} 251}
232 252