Changeset 11956 for trunk/libtransmission/tr-udp.c
- Timestamp:
- Feb 18, 2011, 12:43:47 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/tr-udp.c
r11926 r11956 33 33 #include "tr-utp.h" 34 34 #include "tr-udp.h" 35 36 /* Since we use a single UDP socket in order to implement multiple 37 uTP sockets, try to set up huge buffers. */ 38 39 #define RECV_BUFFER_SIZE (4 * 1024 * 1024) 40 #define SEND_BUFFER_SIZE (1 * 1024 * 1024) 41 #define SMALL_BUFFER_SIZE (32 * 1024) 42 43 static void 44 set_socket_buffers(int fd, int large) 45 { 46 int size, rbuf, sbuf, rc; 47 socklen_t rbuf_len = sizeof(rbuf), sbuf_len = sizeof(sbuf); 48 49 size = large ? RECV_BUFFER_SIZE : SMALL_BUFFER_SIZE; 50 rc = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); 51 if(rc < 0) 52 tr_nerr("UDP", "Failed to set receive buffer: %s", 53 tr_strerror(errno)); 54 55 size = large ? SEND_BUFFER_SIZE : SMALL_BUFFER_SIZE; 56 rc = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)); 57 if(rc < 0) 58 tr_nerr("UDP", "Failed to set send buffer: %s", 59 tr_strerror(errno)); 60 61 if(large) { 62 rc = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &rbuf, &rbuf_len); 63 if(rc < 0) 64 rbuf = 0; 65 66 rc = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sbuf, &sbuf_len); 67 if(rc < 0) 68 sbuf = 0; 69 70 if(rbuf < RECV_BUFFER_SIZE) { 71 tr_nerr("UDP", "Failed to set receive buffer: requested %d, got %d", 72 RECV_BUFFER_SIZE, rbuf); 73 #ifdef __linux__ 74 tr_ninf("UDP", 75 "Please add the line " 76 "\"net.core.rmem_max = %d\" to /etc/sysctl.conf", 77 RECV_BUFFER_SIZE); 78 #endif 79 } 80 81 if(sbuf < SEND_BUFFER_SIZE) { 82 tr_nerr("UDP", "Failed to set send buffer: requested %d, got %d", 83 SEND_BUFFER_SIZE, sbuf); 84 #ifdef __linux__ 85 tr_ninf("UDP", 86 "Please add the line " 87 "\"net.core.wmem_max = %d\" to /etc/sysctl.conf", 88 SEND_BUFFER_SIZE); 89 #endif 90 } 91 } 92 } 93 94 void 95 tr_udpSetSocketBuffers(tr_session *session) 96 { 97 tr_bool utp = tr_sessionIsUTPEnabled(session); 98 if(session->udp_socket >= 0) 99 set_socket_buffers(session->udp_socket, utp); 100 if(session->udp6_socket >= 0) 101 set_socket_buffers(session->udp6_socket, utp); 102 } 103 104 105 35 106 36 107 /* BEP-32 has a rather nice explanation of why we need to bind to one … … 200 271 } 201 272 273 tr_udpSetSocketBuffers(ss); 274 202 275 if(ss->isDHTEnabled) 203 276 tr_dhtInit(ss);
Note: See TracChangeset
for help on using the changeset viewer.