Mercurial > dropbear
comparison dbutil.c @ 251:b02e8eef3c3a
- new function to set "low delay" for a packet, set the ip TOS bit
(can help significantly over some links)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 21 Sep 2005 15:58:19 +0000 |
parents | 3311f4aa52cb |
children | 306499676384 |
comparison
equal
deleted
inserted
replaced
250:d059b0bb57dd | 251:b02e8eef3c3a |
---|---|
151 fprintf(stderr, "\n"); | 151 fprintf(stderr, "\n"); |
152 va_end(param); | 152 va_end(param); |
153 } | 153 } |
154 #endif /* DEBUG_TRACE */ | 154 #endif /* DEBUG_TRACE */ |
155 | 155 |
156 static void set_sock_priority(int sock) { | |
157 | |
158 int val; | |
159 | |
160 /* disable nagle */ | |
161 val = 1; | |
162 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val)); | |
163 | |
164 /* set the TOS bit. note that this will fail for ipv6, I can't find any | |
165 * equivalent. */ | |
166 #ifdef IPTOS_LOWDELAY | |
167 val = IPTOS_LOWDELAY; | |
168 setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val)); | |
169 #endif | |
170 | |
171 #ifdef SO_PRIORITY | |
172 /* linux specific, sets QoS class. | |
173 * 6 looks to be optimal for interactive traffic (see tc-prio(8) ). */ | |
174 val = 6; | |
175 setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &val, sizeof(val)); | |
176 #endif | |
177 | |
178 } | |
179 | |
156 /* Listen on address:port. Unless address is NULL, in which case listen on | 180 /* Listen on address:port. Unless address is NULL, in which case listen on |
157 * everything. If called with address == "", we'll listen on localhost/loopback. | 181 * everything. If called with address == "", we'll listen on localhost/loopback. |
158 * Returns the number of sockets bound on success, or -1 on failure. On | 182 * Returns the number of sockets bound on success, or -1 on failure. On |
159 * failure, if errstring wasn't NULL, it'll be a newly malloced error | 183 * failure, if errstring wasn't NULL, it'll be a newly malloced error |
160 * string.*/ | 184 * string.*/ |
221 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &val, sizeof(val)); | 245 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &val, sizeof(val)); |
222 linger.l_onoff = 1; | 246 linger.l_onoff = 1; |
223 linger.l_linger = 5; | 247 linger.l_linger = 5; |
224 setsockopt(sock, SOL_SOCKET, SO_LINGER, (void*)&linger, sizeof(linger)); | 248 setsockopt(sock, SOL_SOCKET, SO_LINGER, (void*)&linger, sizeof(linger)); |
225 | 249 |
226 /* disable nagle */ | 250 set_sock_priority(sock); |
227 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val)); | |
228 | 251 |
229 if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) { | 252 if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) { |
230 err = errno; | 253 err = errno; |
231 close(sock); | 254 close(sock); |
232 TRACE(("bind(%s) failed", port)) | 255 TRACE(("bind(%s) failed", port)) |
345 snprintf(*errstring, len, "Error connecting: %s", strerror(err)); | 368 snprintf(*errstring, len, "Error connecting: %s", strerror(err)); |
346 } | 369 } |
347 TRACE(("Error connecting: %s", strerror(err))) | 370 TRACE(("Error connecting: %s", strerror(err))) |
348 } else { | 371 } else { |
349 /* Success */ | 372 /* Success */ |
350 /* (err is used as a dummy var here) */ | 373 set_sock_priority(sock); |
351 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&err, sizeof(err)); | |
352 } | 374 } |
353 | 375 |
354 freeaddrinfo(res0); | 376 freeaddrinfo(res0); |
355 if (sock > 0 && errstring != NULL && *errstring != NULL) { | 377 if (sock > 0 && errstring != NULL && *errstring != NULL) { |
356 m_free(*errstring); | 378 m_free(*errstring); |