comparison dbutil.c @ 870:80af450dae76

Set IPTOS_LOWDELAY on PTY sessions only
author Catalin Patulea <cat@vv.carleton.ca>
date Mon, 02 Dec 2013 22:55:43 +0800
parents 30ab30e46452
children aa689d140928
comparison
equal deleted inserted replaced
869:c63e7644db60 870:80af450dae76
175 fprintf(stderr, "\n"); 175 fprintf(stderr, "\n");
176 va_end(param); 176 va_end(param);
177 } 177 }
178 #endif /* DEBUG_TRACE */ 178 #endif /* DEBUG_TRACE */
179 179
180 static void set_sock_priority(int sock) { 180 void set_sock_nodelay(int sock) {
181
182 int val; 181 int val;
183 182
184 /* disable nagle */ 183 /* disable nagle */
185 val = 1; 184 val = 1;
186 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val)); 185 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val));
186 }
187
188 void set_sock_priority(int sock) {
189
190 int val, rc;
187 191
188 /* set the TOS bit for either ipv4 or ipv6 */ 192 /* set the TOS bit for either ipv4 or ipv6 */
189 #ifdef IPTOS_LOWDELAY 193 #ifdef IPTOS_LOWDELAY
190 val = IPTOS_LOWDELAY; 194 val = IPTOS_LOWDELAY;
191 #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) 195 #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)
192 setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val)); 196 rc = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val));
193 #endif 197 if (rc < 0)
194 setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val)); 198 dropbear_log(LOG_WARNING, "Couldn't set IPV6_TCLASS (%s)",
199 strerror(errno));
200 #endif
201 rc = setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val));
202 if (rc < 0)
203 dropbear_log(LOG_WARNING, "Couldn't set IP_TOS (%s)",
204 strerror(errno));
195 #endif 205 #endif
196 206
197 #ifdef SO_PRIORITY 207 #ifdef SO_PRIORITY
198 /* linux specific, sets QoS class. 208 /* linux specific, sets QoS class.
199 * 6 looks to be optimal for interactive traffic (see tc-prio(8) ). */ 209 * 6 looks to be optimal for interactive traffic (see tc-prio(8) ). */
200 val = 6; 210 val = TC_PRIO_INTERACTIVE;
201 setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &val, sizeof(val)); 211 rc = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &val, sizeof(val));
212 if (rc < 0)
213 dropbear_log(LOG_WARNING, "Couldn't set SO_PRIORITY (%s)",
214 strerror(errno));
202 #endif 215 #endif
203 216
204 } 217 }
205 218
206 /* Listen on address:port. 219 /* Listen on address:port.
288 dropbear_log(LOG_WARNING, "Couldn't set IPV6_V6ONLY"); 301 dropbear_log(LOG_WARNING, "Couldn't set IPV6_V6ONLY");
289 } 302 }
290 } 303 }
291 #endif 304 #endif
292 305
293 set_sock_priority(sock); 306 set_sock_nodelay(sock);
294 307
295 if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) { 308 if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
296 err = errno; 309 err = errno;
297 close(sock); 310 close(sock);
298 TRACE(("bind(%s) failed", port)) 311 TRACE(("bind(%s) failed", port))
427 snprintf(*errstring, len, "Error connecting: %s", strerror(err)); 440 snprintf(*errstring, len, "Error connecting: %s", strerror(err));
428 } 441 }
429 TRACE(("Error connecting: %s", strerror(err))) 442 TRACE(("Error connecting: %s", strerror(err)))
430 } else { 443 } else {
431 /* Success */ 444 /* Success */
432 set_sock_priority(sock); 445 set_sock_nodelay(sock);
433 } 446 }
434 447
435 freeaddrinfo(res0); 448 freeaddrinfo(res0);
436 if (sock > 0 && errstring != NULL && *errstring != NULL) { 449 if (sock > 0 && errstring != NULL && *errstring != NULL) {
437 m_free(*errstring); 450 m_free(*errstring);