[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r2349 - in GNUnet/src: server transports
From: |
grothoff |
Subject: |
[GNUnet-SVN] r2349 - in GNUnet/src: server transports |
Date: |
Mon, 19 Dec 2005 03:43:59 -0800 (PST) |
Author: grothoff
Date: 2005-12-19 03:43:39 -0800 (Mon, 19 Dec 2005)
New Revision: 2349
Modified:
GNUnet/src/server/gnunet-transport-check.c
GNUnet/src/transports/udp.c
GNUnet/src/transports/udp6.c
Log:
mantis 989
Modified: GNUnet/src/server/gnunet-transport-check.c
===================================================================
--- GNUnet/src/server/gnunet-transport-check.c 2005-12-19 10:58:20 UTC (rev
2348)
+++ GNUnet/src/server/gnunet-transport-check.c 2005-12-19 11:43:39 UTC (rev
2349)
@@ -409,9 +409,7 @@
return SYSERR;
} else {
if (size == 0)
- size = 2;
- else
- size++;
+ size = 1;
expectedSize = size;
expectedValue = MALLOC(size);
expectedValue[--size] = '\0';
Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2005-12-19 10:58:20 UTC (rev 2348)
+++ GNUnet/src/transports/udp.c 2005-12-19 11:43:39 UTC (rev 2349)
@@ -209,12 +209,48 @@
P2P_PACKET * mp;
UDPMessage udpm;
IPaddr ipaddr;
+ int error;
+ int pending;
+ int ret;
+ fd_set readSet;
+ fd_set errorSet;
+ fd_set writeSet;
SEMAPHORE_UP(serverSignal);
while (udp_shutdown == NO) {
+ FD_ZERO(&readSet);
+ FD_ZERO(&writeSet);
+ FD_ZERO(&errorSet);
+ FD_SET(udp_sock, &readSet);
+ ret = SELECT(udp_sock + 1, &readSet, &writeSet, &errorSet, NULL);
+ if (ret == -1) {
+ if (udp_shutdown == YES)
+ break;
+ if (errno == EINTR)
+ continue;
+ DIE_STRERROR("select");
+ }
+ if (! FD_ISSET(udp_sock, &readSet))
+ continue;
+ pending = 0;
+ error = ioctl(udp_sock,
+ FIONREAD,
+ &pending);
+ if (error != 0) {
+ LOG_STRERROR(LOG_ERROR, "ioctl");
+ continue;
+ }
+ if (pending <= 0) {
+ LOG(LOG_WARNING,
+ _("UDP: select returned, but ioctl reports 0 bytes available!\n"));
+ continue;
+ }
+ if (pending >= 65536) {
+ BREAK();
+ continue;
+ }
mp = MALLOC(sizeof(P2P_PACKET));
- mp->msg = MALLOC(udpAPI.mtu + sizeof(UDPMessage));
- RETRY:
+ mp->msg = MALLOC(pending);
memset(&incoming,
0,
sizeof(struct sockaddr_in));
@@ -225,20 +261,20 @@
}
size = RECVFROM(udp_sock,
mp->msg,
- udpAPI.mtu + sizeof(UDPMessage),
+ pending,
0,
(struct sockaddr * )&incoming,
&addrlen);
if ( (size < 0) ||
(udp_shutdown == YES) ) {
+ FREE(mp->msg);
+ FREE(mp);
if (udp_shutdown == NO) {
if ( (errno == EINTR) ||
(errno == EAGAIN) ||
- (errno == ECONNREFUSED) )
- goto RETRY;
+ (errno == ECONNREFUSED) )
+ continue;
}
- FREE(mp->msg);
- FREE(mp);
if (udp_shutdown == NO)
LOG_STRERROR(LOG_ERROR, "recvfrom");
break; /* die/shutdown */
@@ -252,7 +288,9 @@
_("Received invalid UDP message from %u.%u.%u.%u:%u, dropping.\n"),
PRIP(ntohl(*(int*)&incoming.sin_addr)),
ntohs(incoming.sin_port));
- goto RETRY;
+ FREE(mp->msg);
+ FREE(mp);
+ continue;
}
memcpy(&udpm,
&((char*)mp->msg)[size - sizeof(UDPMessage)],
@@ -275,7 +313,9 @@
_("Packet received from %u.%u.%u.%u:%u (UDP) failed format check.\n"),
PRIP(ntohl(*(int*)&incoming.sin_addr)),
ntohs(incoming.sin_port));
- goto RETRY;
+ FREE(mp->msg);
+ FREE(mp);
+ continue;
}
GNUNET_ASSERT(sizeof(struct in_addr) == sizeof(IPaddr));
memcpy(&ipaddr,
@@ -287,7 +327,9 @@
"address %u.%u.%u.%u.\n"),
"UDP",
PRIP(ntohl(*(int*)&incoming.sin_addr)));
- goto RETRY; /* drop on the floor */
+ FREE(mp->msg);
+ FREE(mp);
+ continue;
}
/* message ok, fill in mp and pass to core */
mp->tsession = NULL;
Modified: GNUnet/src/transports/udp6.c
===================================================================
--- GNUnet/src/transports/udp6.c 2005-12-19 10:58:20 UTC (rev 2348)
+++ GNUnet/src/transports/udp6.c 2005-12-19 11:43:39 UTC (rev 2349)
@@ -194,12 +194,43 @@
P2P_PACKET * mp;
UDP6Message udp6m;
char inet6[INET6_ADDRSTRLEN];
+ int error;
+ int pending;
+ int ret;
+ fd_set readSet;
+ fd_set errorSet;
+ fd_set writeSet;
SEMAPHORE_UP(serverSignal);
while (udp6_shutdown == NO) {
+ FD_ZERO(&readSet);
+ FD_ZERO(&writeSet);
+ FD_ZERO(&errorSet);
+ FD_SET(udp6_sock, &readSet);
+ ret = SELECT(udp6_sock + 1, &readSet, &writeSet, &errorSet, NULL);
+ if (ret == -1) {
+ if (udp6_shutdown == YES)
+ break;
+ if (errno == EINTR)
+ continue;
+ DIE_STRERROR("select");
+ }
+ if (! FD_ISSET(udp6_sock, &readSet))
+ continue;
+ pending = 0;
+ error = ioctl(udp6_sock,
+ FIONREAD,
+ &pending);
+ if (error != 0) {
+ LOG_STRERROR(LOG_ERROR, "ioctl");
+ continue;
+ }
+ if (pending >= 65536) {
+ BREAK();
+ continue;
+ }
mp = MALLOC(sizeof(P2P_PACKET));
- mp->msg = MALLOC(udp6API.mtu + sizeof(UDP6Message));
- RETRY:
+ mp->msg = MALLOC(pending);
memset(&incoming,
0,
sizeof(struct sockaddr_in6));
@@ -210,20 +241,21 @@
}
size = RECVFROM(udp6_sock,
mp->msg,
- udp6API.mtu + sizeof(UDP6Message),
+ pending,
0,
(struct sockaddr * )&incoming,
&addrlen);
if ( (size < 0) ||
(udp6_shutdown == YES) ) {
+ FREE(mp->msg);
+ FREE(mp);
if (udp6_shutdown == NO) {
if ( (errno == EINTR) ||
(errno == EAGAIN) ||
- (errno == ECONNREFUSED) )
- goto RETRY;
+ (errno == ECONNREFUSED) ) {
+ continue;
+ }
}
- FREE(mp->msg);
- FREE(mp);
if (udp6_shutdown == NO)
LOG_STRERROR(LOG_ERROR, "recvfrom");
break; /* die/shutdown */
@@ -237,7 +269,9 @@
inet6,
INET6_ADDRSTRLEN),
ntohs(incoming.sin6_port));
- goto RETRY;
+ FREE(mp->msg);
+ FREE(mp);
+ continue;
}
memcpy(&udp6m,
&((char*)mp->msg)[size - sizeof(UDP6Message)],
@@ -266,7 +300,9 @@
inet6,
INET6_ADDRSTRLEN),
ntohs(incoming.sin6_port));
- goto RETRY;
+ FREE(mp->msg);
+ FREE(mp);
+ continue;
}
GNUNET_ASSERT(sizeof(struct in6_addr) == sizeof(IP6addr));
if (YES == isBlacklisted((IP6addr*)&incoming.sin6_addr)) {
@@ -277,7 +313,9 @@
&incoming,
inet6,
INET6_ADDRSTRLEN));
- goto RETRY; /* drop on the floor */
+ FREE(mp->msg);
+ FREE(mp);
+ continue;
}
/* message ok, fill in mp and pass to core */
mp->tsession = NULL;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r2349 - in GNUnet/src: server transports,
grothoff <=