diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-05 17:44:39 -0400 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-08-05 17:44:39 -0400 |
| commit | c9c63074bbd7025c624ab4987c3a32fd2e925b6a (patch) | |
| tree | 42e2f6eb22299f806c8583b58838564acefa2eea /node/UdpSocket.cpp | |
| parent | 70f368fdc36cd91a3be0218fba7b2d4c6a8bc96f (diff) | |
| download | infinitytier-c9c63074bbd7025c624ab4987c3a32fd2e925b6a.tar.gz infinitytier-c9c63074bbd7025c624ab4987c3a32fd2e925b6a.zip | |
CLI communication now working.
Diffstat (limited to 'node/UdpSocket.cpp')
| -rw-r--r-- | node/UdpSocket.cpp | 19 |
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... + } } } |
