summaryrefslogtreecommitdiff
path: root/node/UdpSocket.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-08-05 17:44:39 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-08-05 17:44:39 -0400
commitc9c63074bbd7025c624ab4987c3a32fd2e925b6a (patch)
tree42e2f6eb22299f806c8583b58838564acefa2eea /node/UdpSocket.cpp
parent70f368fdc36cd91a3be0218fba7b2d4c6a8bc96f (diff)
downloadinfinitytier-c9c63074bbd7025c624ab4987c3a32fd2e925b6a.tar.gz
infinitytier-c9c63074bbd7025c624ab4987c3a32fd2e925b6a.zip
CLI communication now working.
Diffstat (limited to 'node/UdpSocket.cpp')
-rw-r--r--node/UdpSocket.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/node/UdpSocket.cpp b/node/UdpSocket.cpp
index db2c4b56..12a0a989 100644
--- a/node/UdpSocket.cpp
+++ b/node/UdpSocket.cpp
@@ -125,7 +125,13 @@ UdpSocket::UdpSocket(
UdpSocket::~UdpSocket()
{
- close(_sock);
+ int s = _sock;
+ _sock = 0;
+ if (s > 0) {
+ ::shutdown(s,SHUT_RDWR);
+ ::close(s);
+ }
+ Thread<UdpSocket>::join(_thread);
}
bool UdpSocket::send(const InetAddress &to,const void *data,unsigned int len,int hopLimit)
@@ -148,19 +154,22 @@ bool UdpSocket::send(const InetAddress &to,const void *data,unsigned int len,int
void UdpSocket::threadMain()
throw()
{
- char buf[32768];
+ char buf[65536];
InetAddress from;
socklen_t salen;
int n;
- for(;;) {
+ while (_sock > 0) {
salen = from.saddrSpaceLen();
n = (int)recvfrom(_sock,buf,sizeof(buf),0,from.saddr(),&salen);
if (n < 0) {
if ((errno != EINTR)&&(errno != ETIMEDOUT))
break;
- } else if (n > 0)
- _packetHandler(this,_arg,from,buf,(unsigned int)n);
+ } else if (n > 0) {
+ try {
+ _packetHandler(this,_arg,from,buf,(unsigned int)n);
+ } catch ( ... ) {} // should never be thrown from here anyway...
+ }
}
}