Browse code

moved max buffer size probing to a separate procedure

Jiri Kuthan authored on 14/11/2001 06:57:20
Showing 1 changed files
... ...
@@ -21,11 +21,8 @@
21 21
 
22 22
 int udp_sock;
23 23
 
24
-
25
-
26
-int udp_init(unsigned long ip, unsigned short port)
24
+int probe_max_receive_buffer( int udp_sock )
27 25
 {
28
-	struct sockaddr_in* addr;
29 26
 	int optval, optvallen;
30 27
 	int ioptval, ioptvallen;
31 28
 	int foptval, foptvallen;
... ...
@@ -33,37 +30,13 @@ int udp_init(unsigned long ip, unsigned short port)
33 33
 	int i;
34 34
 	int phase=0;
35 35
 
36
-
37
-	addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
38
-	if (addr==0){
39
-		LOG(L_ERR, "ERROR: udp_init: out of memory\n");
40
-		goto error;
41
-	}
42
-	addr->sin_family=AF_INET;
43
-	addr->sin_port=htons(port);
44
-	addr->sin_addr.s_addr=ip;
45
-
46
-	udp_sock = socket(PF_INET, SOCK_DGRAM, 0);
47
-	if (udp_sock==-1){
48
-		LOG(L_ERR, "ERROR: udp_init: socket: %s\n", strerror(errno));
49
-		goto error;
50
-	}
51
-	/* set sock opts? */
52
-	optval=1;
53
-	if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR,
54
-					(void*)&optval, sizeof(optval)) ==-1)
55
-	{
56
-		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
57
-		goto error;
58
-	}
59
-
60 36
 	/* jku: try to increase buffer size as much as we can */
61 37
 	ioptvallen=sizeof(ioptval);
62 38
 	if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &ioptval,
63 39
 		    &ioptvallen) == -1 )
64 40
 	{
65 41
 		LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
66
-		goto error;
42
+		return -1;
67 43
 	}
68 44
 	if ( ioptval==0 ) 
69 45
 	{
... ...
@@ -97,7 +70,7 @@ int udp_init(unsigned long ip, unsigned short port)
97 97
 		    &voptvallen) == -1 )
98 98
 		{
99 99
 			LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
100
-			goto error;
100
+			return -1;
101 101
 		} else {
102 102
 			LOG(L_DBG, "DEBUG: setting SO_RCVBUF; set=%d,verify=%d\n", 
103 103
 				optval, voptval);
... ...
@@ -108,7 +81,7 @@ int udp_init(unsigned long ip, unsigned short port)
108 108
 				*/
109 109
                         	if (phase==0) { phase=1; optval >>=1 ; continue; } 
110 110
                         	else break;
111
-			}
111
+			} 
112 112
 		}
113 113
 
114 114
 	} /* for ... */
... ...
@@ -117,12 +90,46 @@ int udp_init(unsigned long ip, unsigned short port)
117 117
 		    &foptvallen) == -1 )
118 118
 	{
119 119
 		LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
120
-		goto error;
120
+		return -1;
121 121
 	}
122 122
  	LOG(L_INFO, "INFO: udp_init: SO_RCVBUF is finally %d\n", foptval );
123 123
 
124
+	return 0;
124 125
 
125 126
 	/* EoJKU */
127
+}
128
+
129
+int udp_init(unsigned long ip, unsigned short port)
130
+{
131
+	struct sockaddr_in* addr;
132
+	int optval, optvallen;
133
+
134
+
135
+	addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
136
+	if (addr==0){
137
+		LOG(L_ERR, "ERROR: udp_init: out of memory\n");
138
+		goto error;
139
+	}
140
+	addr->sin_family=AF_INET;
141
+	addr->sin_port=htons(port);
142
+	addr->sin_addr.s_addr=ip;
143
+
144
+	udp_sock = socket(PF_INET, SOCK_DGRAM, 0);
145
+	if (udp_sock==-1){
146
+		LOG(L_ERR, "ERROR: udp_init: socket: %s\n", strerror(errno));
147
+		goto error;
148
+	}
149
+	/* set sock opts? */
150
+	optval=1;
151
+	if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR,
152
+					(void*)&optval, sizeof(optval)) ==-1)
153
+	{
154
+		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
155
+		goto error;
156
+	}
157
+
158
+	if ( probe_max_receive_buffer(udp_sock)==-1) goto error;
159
+
126 160
 
127 161
 	if (bind(udp_sock, (struct sockaddr*) addr, sizeof(struct sockaddr))==-1){
128 162
 		LOG(L_ERR, "ERROR: udp_init: bind: %s\n", strerror(errno));