From c9c63074bbd7025c624ab4987c3a32fd2e925b6a Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 5 Aug 2013 17:44:39 -0400 Subject: CLI communication now working. --- node/UdpSocket.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'node/UdpSocket.cpp') 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::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... + } } } -- cgit v1.2.3