...
|
...
|
@@ -32,6 +32,9 @@
|
32
|
32
|
* 2003-01-20 locking fixes, hashtables (andrei)
|
33
|
33
|
* 2003-02-20 s/lock_t/gen_lock_t/ to avoid a conflict on solaris (andrei)
|
34
|
34
|
* 2003-02-25 Nagle is disabled if -DDISABLE_NAGLE (andrei)
|
|
35
|
+ * 2003-03-29 SO_REUSEADDR before calling bind to allow
|
|
36
|
+ * server restart, Nagle set on the (hopefuly)
|
|
37
|
+ * correct socket
|
35
|
38
|
*/
|
36
|
39
|
|
37
|
40
|
|
...
|
...
|
@@ -161,7 +164,10 @@ struct tcp_connection* tcpconn_connect(union sockaddr_union* server)
|
161
|
164
|
#ifdef DISABLE_NAGLE
|
162
|
165
|
flag=1;
|
163
|
166
|
if ( (tcp_proto_no!=-1) &&
|
164
|
|
- (setsockopt(sock_info->socket, tcp_proto_no , TCP_NODELAY,
|
|
167
|
+/* fix: I used to get here
|
|
168
|
+ * ERROR: tcp_connect: could not disable Nagle: Protocol not available
|
|
169
|
+ * (setsockopt(sock_info->socket, tcp_proto_no , TCP_NODELAY, */
|
|
170
|
+ (setsockopt(s, tcp_proto_no , TCP_NODELAY,
|
165
|
171
|
&flag, sizeof(flag))<0) ){
|
166
|
172
|
LOG(L_ERR, "ERROR: tcp_connect: could not disable Nagle: %s\n",
|
167
|
173
|
strerror(errno));
|
...
|
...
|
@@ -441,6 +447,9 @@ void tcpconn_timeout(fd_set* set)
|
441
|
447
|
int tcp_init(struct socket_info* sock_info)
|
442
|
448
|
{
|
443
|
449
|
union sockaddr_union* addr;
|
|
450
|
+#if defined(SO_REUSEADDR) && !defined(TCP_DONT_REUSEADDR)
|
|
451
|
+ int optval;
|
|
452
|
+#endif
|
444
|
453
|
#ifdef DISABLE_NAGLE
|
445
|
454
|
int flag;
|
446
|
455
|
struct protoent* pe;
|
...
|
...
|
@@ -474,6 +483,27 @@ int tcp_init(struct socket_info* sock_info)
|
474
|
483
|
strerror(errno));
|
475
|
484
|
}
|
476
|
485
|
#endif
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+#if defined(SO_REUSEADDR) && !defined(TCP_DONT_REUSEADDR)
|
|
489
|
+ /* Stevens, "Network Programming", Section 7.5, "Generic Socket
|
|
490
|
+ * Options": "...server started,..a child continues..on existing
|
|
491
|
+ * connection..listening server is restarted...call to bind fails
|
|
492
|
+ * ... ALL TCP servers should specify the SO_REUSEADDRE option
|
|
493
|
+ * to allow the server to be restarted in this situation
|
|
494
|
+ *
|
|
495
|
+ * Indeed, without this option, the server can't restart.
|
|
496
|
+ * -jiri
|
|
497
|
+ */
|
|
498
|
+ optval=1;
|
|
499
|
+ if (setsockopt(sock_info->socket, SOL_SOCKET, SO_REUSEADDR,
|
|
500
|
+ (void*)&optval, sizeof(optval))==-1) {
|
|
501
|
+ LOG(L_ERR, "ERROR: tcp_init: setsockopt %s\n",
|
|
502
|
+ strerror(errno));
|
|
503
|
+ goto error;
|
|
504
|
+ }
|
|
505
|
+#endif
|
|
506
|
+
|
477
|
507
|
if (bind(sock_info->socket, &addr->s, sockaddru_len(*addr))==-1){
|
478
|
508
|
LOG(L_ERR, "ERROR: tcp_init: bind(%x, %p, %d) on %s: %s\n",
|
479
|
509
|
sock_info->socket, &addr->s,
|