diff --git a/libbitdht/src/udp/udplayer.cc b/libbitdht/src/udp/udplayer.cc index db048b857..a0cc2324e 100644 --- a/libbitdht/src/udp/udplayer.cc +++ b/libbitdht/src/udp/udplayer.cc @@ -243,74 +243,66 @@ void UdpLayer::run() /* higher level interface */ void UdpLayer::recv_loop() { - int maxsize = 16000; + size_t maxsize = 16000; void *inbuf = malloc(maxsize); - if(inbuf == NULL) - { - std::cerr << "(EE) Error in memory allocation of size " << maxsize << " in " << __PRETTY_FUNCTION__ << std::endl; - return ; - } - - int status; - struct timeval timeout; + if(inbuf == NULL) + { + std::cerr << "(EE) Error in memory allocation of size " << maxsize + << " in " << __PRETTY_FUNCTION__ << std::endl; + return; + } + + int status; + struct timeval timeout; while(1) { - fd_set rset; - for(;;) + for(;;) { /* check if we need to stop */ bool toStop = false; { - bdStackMutex stack(sockMtx); /********** LOCK MUTEX *********/ + bdStackMutex stack(sockMtx); (void) stack; toStop = stopThread; } - + if (toStop) { #ifdef DEBUG_UDP_LAYER std::cerr << "UdpLayer::recv_loop() stopping thread" << std::endl; #endif - free(inbuf) ; + free(inbuf); stop(); + return; // Avoid compiler warning about usage of inbuf after free } - FD_ZERO(&rset); - FD_SET(sockfd, &rset); - timeout.tv_sec = 0; - timeout.tv_usec = 500000; /* 500 ms timeout */ - status = select(sockfd+1, &rset, NULL, NULL, &timeout); - if (status > 0) - { - break; /* data available, go read it */ - } - else if (status < 0) - { + fd_set rset; + FD_ZERO(&rset); + FD_SET(sockfd, &rset); + timeout.tv_sec = 0; + timeout.tv_usec = 500000; // 500 ms timeout + status = select(sockfd+1, &rset, NULL, NULL, &timeout); + if (status > 0) break; // data available, go read it #ifdef DEBUG_UDP_LAYER - std::cerr << "UdpLayer::recv_loop() Error: " << bdnet_errno() << std::endl; + else if (status < 0) std::cerr << "UdpLayer::recv_loop() Error: " + << bdnet_errno() << std::endl; #endif - } - }; + }; - int nsize = maxsize; + int nsize = static_cast(maxsize); struct sockaddr_in from; if (0 < receiveUdpPacket(inbuf, &nsize, from)) { #ifdef DEBUG_UDP_LAYER - std::cerr << "UdpLayer::readPkt() from : " << from << std::endl; - std::cerr << printPkt(inbuf, nsize); + std::cerr << "UdpLayer::readPkt() from : " << from << std::endl + << printPkt(inbuf, nsize); #endif - // send to reciever. - recv -> recvPkt(inbuf, nsize, from); + recv->recvPkt(inbuf, nsize, from); // pass to reciever. } - else - { #ifdef DEBUG_UDP_LAYER - std::cerr << "UdpLayer::readPkt() not ready" << from; - std::cerr << std::endl; + else std::cerr << "UdpLayer::readPkt() not ready" << from << std::endl; #endif - } } } diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index a1e8f984f..42bae411a 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -276,7 +276,7 @@ mac { DEFINES *= MINIUPNPC_VERSION=13 CONFIG += upnp_miniupnpc - CONFIG += c+11 + CONFIG += c++11 # zeroconf disabled at the end of libretroshare.pro (but need the code) #CONFIG += zeroconf diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index 47b0666fc..bb8b84d8c 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -178,32 +178,21 @@ std::ostream &printIndent(std::ostream &out, uint16_t indent); class RsRawItem: public RsItem { - public: - RsRawItem(uint32_t t, uint32_t size) - :RsItem(t), len(size) - { - data = rs_malloc(len); - } +public: + RsRawItem(uint32_t t, uint32_t size) : RsItem(t), len(size) + { data = rs_malloc(len); } + virtual ~RsRawItem() { free(data); } - virtual ~RsRawItem() - { - if (data) - free(data); - data = NULL; - len = 0; - } + uint32_t getRawLength() { return len; } + void * getRawData() { return data; } - uint32_t getRawLength() { return len; } - void *getRawData() { return data; } + virtual void clear() {} + virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - virtual void clear() { return; } /* what can it do? */ - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - - private: - void *data; - uint32_t len; +private: + void *data; + uint32_t len; }; - #endif /* RS_BASE_SERIALISER_H */ diff --git a/retroshare.pri b/retroshare.pri index fe7d77df2..5d8572807 100644 --- a/retroshare.pri +++ b/retroshare.pri @@ -84,7 +84,7 @@ macx { message(***retroshare.pri: No SDK, set it to MacOS 10.10 ) QMAKE_MAC_SDK = macosx10.10 } - CONFIG += c+11 + CONFIG += c++11 } unfinished {