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 30
 	int i;
34 31
 	int phase=0;
35 32
 
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 33
 	/* jku: try to increase buffer size as much as we can */
61 34
 	ioptvallen=sizeof(ioptval);
62 35
 	if (getsockopt( udp_sock, SOL_SOCKET, SO_RCVBUF, (void*) &ioptval,
63 36
 		    &ioptvallen) == -1 )
64 37
 	{
65 38
 		LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
66
-		goto error;
39
+		return -1;
67 40
 	}
68 41
 	if ( ioptval==0 ) 
69 42
 	{
... ...
@@ -97,7 +70,7 @@ int udp_init(unsigned long ip, unsigned short port)
97 70
 		    &voptvallen) == -1 )
98 71
 		{
99 72
 			LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
100
-			goto error;
73
+			return -1;
101 74
 		} else {
102 75
 			LOG(L_DBG, "DEBUG: setting SO_RCVBUF; set=%d,verify=%d\n", 
103 76
 				optval, voptval);
... ...
@@ -108,7 +81,7 @@ int udp_init(unsigned long ip, unsigned short port)
108 81
 				*/
109 82
                         	if (phase==0) { phase=1; optval >>=1 ; continue; } 
110 83
                         	else break;
111
-			}
84
+			} 
112 85
 		}
113 86
 
114 87
 	} /* for ... */
... ...
@@ -117,12 +90,46 @@ int udp_init(unsigned long ip, unsigned short port)
117 90
 		    &foptvallen) == -1 )
118 91
 	{
119 92
 		LOG(L_ERR, "ERROR: udp_init: getsockopt: %s\n", strerror(errno));
120
-		goto error;
93
+		return -1;
121 94
 	}
122 95
  	LOG(L_INFO, "INFO: udp_init: SO_RCVBUF is finally %d\n", foptval );
123 96
 
97
+	return 0;
124 98
 
125 99
 	/* EoJKU */
100
+}
101
+
102
+int udp_init(unsigned long ip, unsigned short port)
103
+{
104
+	struct sockaddr_in* addr;
105
+	int optval, optvallen;
106
+
107
+
108
+	addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
109
+	if (addr==0){
110
+		LOG(L_ERR, "ERROR: udp_init: out of memory\n");
111
+		goto error;
112
+	}
113
+	addr->sin_family=AF_INET;
114
+	addr->sin_port=htons(port);
115
+	addr->sin_addr.s_addr=ip;
116
+
117
+	udp_sock = socket(PF_INET, SOCK_DGRAM, 0);
118
+	if (udp_sock==-1){
119
+		LOG(L_ERR, "ERROR: udp_init: socket: %s\n", strerror(errno));
120
+		goto error;
121
+	}
122
+	/* set sock opts? */
123
+	optval=1;
124
+	if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR,
125
+					(void*)&optval, sizeof(optval)) ==-1)
126
+	{
127
+		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror(errno));
128
+		goto error;
129
+	}
130
+
131
+	if ( probe_max_receive_buffer(udp_sock)==-1) goto error;
132
+
126 133
 
127 134
 	if (bind(udp_sock, (struct sockaddr*) addr, sizeof(struct sockaddr))==-1){
128 135
 		LOG(L_ERR, "ERROR: udp_init: bind: %s\n", strerror(errno));