Browse code

core: - no fork unused sockets fix & cleanups mysql: - strptime XOPEN define

Andrei Pelinescu-Onciul authored on 01/12/2004 16:51:17
Showing 3 changed files
... ...
@@ -50,7 +50,7 @@ MAIN_NAME=ser
50 50
 VERSION = 0
51 51
 PATCHLEVEL = 8
52 52
 SUBLEVEL =   99
53
-EXTRAVERSION = -dev20
53
+EXTRAVERSION = -dev21
54 54
 
55 55
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
56 56
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -95,6 +95,7 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
95 95
 	socklen_t len;
96 96
 	union sockaddr_union from; 
97 97
 	struct socket_info* si;
98
+	struct ip_addr ip;
98 99
 
99 100
 	if (proto!=PROTO_UDP) {
100 101
 		LOG(L_CRIT, "BUG: get_out_socket can only be called for UDP\n");
... ...
@@ -118,39 +119,16 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
118 118
 				strerror(errno));
119 119
 		goto error;
120 120
 	}
121
-	for (si=udp_listen; si; si=si->next) {
122
-		switch(from.s.sa_family) {
123
-			case AF_INET:	
124
-						if (si->address.af!=AF_INET)
125
-								continue;
126
-						if (memcmp(&si->address.u,
127
-								&from.sin.sin_addr, 
128
-								si->address.len)==0)
129
-							goto found; /*  success */
130
-						break;
131
-#if defined(USE_IPV6)
132
-			case AF_INET6:	
133
-						if (si->address.af!=AF_INET6)
134
-								continue;
135
-						if (memcmp(&si->address.u,
136
-								&from.sin6.sin6_addr, len)==0)
137
-							goto found;
138
-						continue;
139
-#endif
140
-			default:	LOG(L_ERR, "ERROR: get_out_socket: "
141
-									"unknown family: %d\n",
142
-									from.s.sa_family);
143
-						goto error;
144
-		}
145
-	}
121
+	su2ip_addr(&ip, &from);
122
+	si=find_si(&ip, 0, proto);
123
+	if (si==0) goto error;
124
+	close(temp_sock);
125
+	DBG("DEBUG: get_out_socket: socket determined: %p\n", si );
126
+	return si;
146 127
 error:
147 128
 	LOG(L_ERR, "ERROR: get_out_socket: no socket found\n");
148 129
 	close(temp_sock);
149 130
 	return 0;
150
-found:
151
-	close(temp_sock);
152
-	DBG("DEBUG: get_out_socket: socket determined: %p\n", si );
153
-	return si;
154 131
 }
155 132
 
156 133
 
... ...
@@ -174,13 +152,28 @@ struct socket_info* get_send_socket(struct sip_msg *msg,
174 174
 											msg->force_send_socket->port_no,
175 175
 											proto);
176 176
 		}
177
-		if (msg->force_send_socket) 
177
+		if (msg->force_send_socket && (msg->force_send_socket->socket!=-1)) 
178 178
 			return msg->force_send_socket;
179
-		else
180
-			LOG(L_WARN, "WARNING: get_send_socket: protocol/port mismatch\n");
179
+		else{
180
+			if (msg->force_send_socket->socket==-1)
181
+				LOG(L_WARN, "WARNING: get_send_socket: not listening"
182
+						 " on the requested socket, no fork mode?\n");
183
+			else
184
+				LOG(L_WARN, "WARNING: get_send_socket: "
185
+						"protocol/port mismatch\n");
186
+		}
181 187
 	};
182 188
 
183
-	if (mhomed && proto==PROTO_UDP) return get_out_socket(to, proto);
189
+	if (mhomed && proto==PROTO_UDP){
190
+		send_sock=get_out_socket(to, proto);
191
+		if ((send_sock==0) || (send_sock->socket!=-1))
192
+			return send_sock; /* found or error*/
193
+		else if (send_sock->socket==-1){
194
+			LOG(L_WARN, "WARNING: get_send_socket: not listening on the"
195
+					" requested socket, no fork mode?\n");
196
+			/* continue: try to use some socket */
197
+		}
198
+	}
184 199
 
185 200
 	send_sock=0;
186 201
 	/* check if we need to change the socket (different address families -
... ...
@@ -112,6 +112,7 @@ static inline struct socket_info* new_sock_info(	char* name,
112 112
 	si=(struct socket_info*) pkg_malloc(sizeof(struct socket_info));
113 113
 	if (si==0) goto error;
114 114
 	memset(si, 0, sizeof(struct socket_info));
115
+	si->socket=-1;
115 116
 	si->name.len=strlen(name);
116 117
 	si->name.s=(char*)pkg_malloc(si->name.len+1); /* include \0 */
117 118
 	if (si->name.s==0) goto error;