comparison dbutil.c @ 871:aa689d140928

- Sockets are set to lowdelay priority initially to improve conneciton setup time - Set non-pty connections to bulk for client and server
author Matt Johnston <matt@ucc.asn.au>
date Tue, 03 Dec 2013 00:04:48 +0800
parents 80af450dae76
children ff597bf2cfb0
comparison
equal deleted inserted replaced
870:80af450dae76 871:aa689d140928
183 /* disable nagle */ 183 /* disable nagle */
184 val = 1; 184 val = 1;
185 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val)); 185 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val));
186 } 186 }
187 187
188 void set_sock_priority(int sock) { 188 void set_sock_priority(int sock, enum dropbear_prio prio) {
189 189
190 int val, rc; 190 int iptos_val = 0, so_prio_val = 0, rc;
191 191
192 /* set the TOS bit for either ipv4 or ipv6 */ 192 /* set the TOS bit for either ipv4 or ipv6 */
193 #ifdef IPTOS_LOWDELAY 193 #ifdef IPTOS_LOWDELAY
194 val = IPTOS_LOWDELAY; 194 if (prio == DROPBEAR_PRIO_LOWDELAY) {
195 iptos_val = IPTOS_LOWDELAY;
196 } else if (prio == DROPBEAR_PRIO_BULK) {
197 iptos_val = IPTOS_THROUGHPUT;
198 }
195 #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) 199 #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)
196 rc = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val)); 200 rc = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&iptos_val, sizeof(iptos_val));
197 if (rc < 0) 201 if (rc < 0) {
198 dropbear_log(LOG_WARNING, "Couldn't set IPV6_TCLASS (%s)", 202 TRACE(("Couldn't set IPV6_TCLASS (%s)", strerror(errno)));
199 strerror(errno)); 203 }
200 #endif 204 #endif
201 rc = setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val)); 205 rc = setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&iptos_val, sizeof(iptos_val));
202 if (rc < 0) 206 if (rc < 0) {
203 dropbear_log(LOG_WARNING, "Couldn't set IP_TOS (%s)", 207 TRACE(("Couldn't set IP_TOS (%s)", strerror(errno)));
204 strerror(errno)); 208 }
205 #endif 209 #endif
206 210
207 #ifdef SO_PRIORITY 211 #ifdef SO_PRIORITY
208 /* linux specific, sets QoS class. 212 if (prio == DROPBEAR_PRIO_LOWDELAY) {
209 * 6 looks to be optimal for interactive traffic (see tc-prio(8) ). */ 213 so_prio_val = TC_PRIO_INTERACTIVE;
210 val = TC_PRIO_INTERACTIVE; 214 } else if (prio == DROPBEAR_PRIO_BULK) {
211 rc = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &val, sizeof(val)); 215 so_prio_val = TC_PRIO_BULK;
216 }
217 /* linux specific, sets QoS class. see tc-prio(8) */
218 rc = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &so_prio_val, sizeof(so_prio_val));
212 if (rc < 0) 219 if (rc < 0)
213 dropbear_log(LOG_WARNING, "Couldn't set SO_PRIORITY (%s)", 220 dropbear_log(LOG_WARNING, "Couldn't set SO_PRIORITY (%s)",
214 strerror(errno)); 221 strerror(errno));
215 #endif 222 #endif
216 223