use recvfrom() instead of read()

This commit is contained in:
roberto@sirius
2010-11-25 09:44:07 +01:00
parent 152fb9cde9
commit 1d03fdee64
3 changed files with 24 additions and 7 deletions
+5 -3
View File
@@ -340,15 +340,17 @@ void master_loop(char **argv, char **environ) {
}
if (uwsgi_poll[i].fd == uwsgi.cluster_fd) {
if (uwsgi_get_dgram(uwsgi.cluster_fd, uwsgi.wsgi_requests[0])) {
continue;
}
switch(uwsgi.wsgi_requests[0]->uh.modifier1) {
case 99:
uwsgi_log("requested configuration data, sending %d bytes\n", cluster_opt_size);
sendto(uwsgi.cluster_fd, cluster_opt_buf, cluster_opt_size, 0, (struct sockaddr *) &uwsgi.mc_cluster_addr, sizeof(uwsgi.mc_cluster_addr));
if (uwsgi.wsgi_requests[0]->uh.modifier2 == 0) {
uwsgi_log("requested configuration data, sending %d bytes\n", cluster_opt_size);
sendto(uwsgi.cluster_fd, cluster_opt_buf, cluster_opt_size, 0, (struct sockaddr *) &uwsgi.mc_cluster_addr, sizeof(uwsgi.mc_cluster_addr));
}
break;
case 73:
uwsgi_log_verbose("[uWSGI cluster %s] new node available: %.*s\n", uwsgi.cluster, uwsgi.wsgi_requests[0]->uh.pktsize, uwsgi.wsgi_requests[0]->buffer);
+14 -4
View File
@@ -602,6 +602,9 @@ int uwsgi_get_dgram(int fd, struct wsgi_request *wsgi_req) {
struct uwsgi_header *uh;
static char *buffer = NULL;
struct sockaddr_in sin;
socklen_t sin_len = sizeof(struct sockaddr_in);
if (!buffer) {
buffer = malloc(uwsgi.buffer_size + 4);
if (!buffer) {
@@ -611,13 +614,15 @@ int uwsgi_get_dgram(int fd, struct wsgi_request *wsgi_req) {
}
rlen = read(fd, buffer, uwsgi.buffer_size + 4);
rlen = recvfrom(fd, buffer, uwsgi.buffer_size + 4, 0, (struct sockaddr *) &sin, &sin_len);
if (rlen < 0) {
uwsgi_error("read()");
uwsgi_error("recvfrom");
return -1;
}
uwsgi_log("recevied request from %s\n", inet_ntoa(sin.sin_addr));
if (rlen < 4) {
uwsgi_log("invalid uwsgi packet\n");
return -1;
@@ -651,14 +656,19 @@ int uwsgi_hooked_parse_dict_dgram(int fd, char *buffer, size_t len, uint8_t modi
uint16_t keysize = 0, valsize = 0;
char *key;
struct sockaddr_in sin;
socklen_t sin_len = sizeof(struct sockaddr_in);
rlen = read(fd, buffer, len);
rlen = recvfrom(fd, buffer, len, 0, (struct sockaddr *) &sin, &sin_len);
if (rlen < 0) {
uwsgi_error("read()");
uwsgi_error("recvfrom()");
return -1;
}
uwsgi_log("recevied request from %s\n", inet_ntoa(sin.sin_addr));
uwsgi_log("RLEN: %d\n", rlen);
// check for valid dict 4(header) 2(non-zero key)+1 2(value)
+5
View File
@@ -140,6 +140,7 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
#ifdef UWSGI_MULTICAST
struct ip_mreq mc;
uint8_t loop = 0;
int ttl = 1;
#endif
udp_port = strchr(socket_name, ':');
@@ -197,6 +198,10 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
if (setsockopt(serverfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mc, sizeof(mc))) {
uwsgi_error("setsockopt()");
}
if (setsockopt(serverfd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) {
uwsgi_error("setsockopt()");
}
}
#endif