Loading src/posix/socket.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,8 @@ #define HIDDEN __attribute__ ((visibility ("hidden"))) int netplus::socket::_InitCount = 0; netplus::socket::socket(){ _Socket=-1; _SocketPtr=nullptr; Loading src/posix/tcp.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "error.h" netplus::tcp::tcp(const char* uxsocket,int maxconnections,int sockopts) { netplus::tcp::tcp(const char* uxsocket,int maxconnections,int sockopts) : socket(){ NetException exception; int optval = 1; if(sockopts == -1) Loading @@ -71,7 +71,7 @@ netplus::tcp::tcp(const char* uxsocket,int maxconnections,int sockopts) { _Type=sockettype::TCP; } netplus::tcp::tcp(const char* addr, int port,int maxconnections,int sockopts) { netplus::tcp::tcp(const char* addr, int port,int maxconnections,int sockopts) : socket() { NetException exception; _Maxconnections=maxconnections; if(sockopts == -1) Loading Loading @@ -128,7 +128,8 @@ netplus::tcp::~tcp(){ ::free(_SocketPtr); } netplus::tcp::tcp() { netplus::tcp::tcp() : socket() { ++_InitCount; _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; Loading @@ -136,7 +137,7 @@ netplus::tcp::tcp() { _Type=sockettype::TCP; } netplus::tcp::tcp(int sock) { netplus::tcp::tcp(int sock) : socket() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; Loading src/posix/udp.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "error.h" netplus::udp::udp() { netplus::udp::udp() : socket() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; Loading @@ -54,7 +54,7 @@ netplus::udp::udp() { _Type=sockettype::UDP; } netplus::udp::udp(const char* uxsocket,int maxconnections,int sockopts) { netplus::udp::udp(const char* uxsocket,int maxconnections,int sockopts) : socket() { NetException exception; int optval = 1; if(sockopts == -1) Loading @@ -80,7 +80,7 @@ netplus::udp::udp(const char* uxsocket,int maxconnections,int sockopts) { _Type=sockettype::UDP; } netplus::udp::udp(const char* addr, int port,int maxconnections,int sockopts) { netplus::udp::udp(const char* addr, int port,int maxconnections,int sockopts) : socket() { NetException exception; _Maxconnections=maxconnections; if(sockopts == -1) Loading Loading @@ -132,7 +132,7 @@ netplus::udp::~udp(){ ::free(_SocketPtr); } netplus::udp::udp(int sock){ netplus::udp::udp(int sock) : socket() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; Loading src/socket.h +16 −15 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ namespace netplus { SOCKET _Socket; int _Type; void *_Extension; static std::atomic<int> _InitCount; #ifdef Windows WSAData *_WSAData; #endif // Windows Loading src/windows/socket.cpp +6 −8 Original line number Diff line number Diff line Loading @@ -46,27 +46,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma comment (lib, "Ws2_32.lib") namespace netplus { std::atomic<int> _Instance; }; std::atomic<int> netplus::socket::_InitCount=0; netplus::socket::socket(){ _Socket=-1; _SocketPtr=nullptr; _Type=-1; ++_Instance; if (!_WSAData) { if (_InitCount<1) { if (WSAStartup(MAKEWORD(2, 2), _WSAData) != 0) { NetException exception; exception[NetException::Critical] << "udp: WSAStartup failed: "; exception[NetException::Critical] << "socket: WSAStartup failed: "; } } ++_InitCount; } netplus::socket::~socket(){ --_Instance; --_InitCount; int zero = 0; if (_Instance.compare_exchange_strong(zero, std::memory_order_release)) { if (_InitCount.compare_exchange_strong(zero, std::memory_order_release)) { WSACleanup(); delete _WSAData; _WSAData = nullptr; Loading Loading
src/posix/socket.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,8 @@ #define HIDDEN __attribute__ ((visibility ("hidden"))) int netplus::socket::_InitCount = 0; netplus::socket::socket(){ _Socket=-1; _SocketPtr=nullptr; Loading
src/posix/tcp.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "error.h" netplus::tcp::tcp(const char* uxsocket,int maxconnections,int sockopts) { netplus::tcp::tcp(const char* uxsocket,int maxconnections,int sockopts) : socket(){ NetException exception; int optval = 1; if(sockopts == -1) Loading @@ -71,7 +71,7 @@ netplus::tcp::tcp(const char* uxsocket,int maxconnections,int sockopts) { _Type=sockettype::TCP; } netplus::tcp::tcp(const char* addr, int port,int maxconnections,int sockopts) { netplus::tcp::tcp(const char* addr, int port,int maxconnections,int sockopts) : socket() { NetException exception; _Maxconnections=maxconnections; if(sockopts == -1) Loading Loading @@ -128,7 +128,8 @@ netplus::tcp::~tcp(){ ::free(_SocketPtr); } netplus::tcp::tcp() { netplus::tcp::tcp() : socket() { ++_InitCount; _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; Loading @@ -136,7 +137,7 @@ netplus::tcp::tcp() { _Type=sockettype::TCP; } netplus::tcp::tcp(int sock) { netplus::tcp::tcp(int sock) : socket() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; Loading
src/posix/udp.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "error.h" netplus::udp::udp() { netplus::udp::udp() : socket() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; Loading @@ -54,7 +54,7 @@ netplus::udp::udp() { _Type=sockettype::UDP; } netplus::udp::udp(const char* uxsocket,int maxconnections,int sockopts) { netplus::udp::udp(const char* uxsocket,int maxconnections,int sockopts) : socket() { NetException exception; int optval = 1; if(sockopts == -1) Loading @@ -80,7 +80,7 @@ netplus::udp::udp(const char* uxsocket,int maxconnections,int sockopts) { _Type=sockettype::UDP; } netplus::udp::udp(const char* addr, int port,int maxconnections,int sockopts) { netplus::udp::udp(const char* addr, int port,int maxconnections,int sockopts) : socket() { NetException exception; _Maxconnections=maxconnections; if(sockopts == -1) Loading Loading @@ -132,7 +132,7 @@ netplus::udp::~udp(){ ::free(_SocketPtr); } netplus::udp::udp(int sock){ netplus::udp::udp(int sock) : socket() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; Loading
src/socket.h +16 −15 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ namespace netplus { SOCKET _Socket; int _Type; void *_Extension; static std::atomic<int> _InitCount; #ifdef Windows WSAData *_WSAData; #endif // Windows Loading
src/windows/socket.cpp +6 −8 Original line number Diff line number Diff line Loading @@ -46,27 +46,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma comment (lib, "Ws2_32.lib") namespace netplus { std::atomic<int> _Instance; }; std::atomic<int> netplus::socket::_InitCount=0; netplus::socket::socket(){ _Socket=-1; _SocketPtr=nullptr; _Type=-1; ++_Instance; if (!_WSAData) { if (_InitCount<1) { if (WSAStartup(MAKEWORD(2, 2), _WSAData) != 0) { NetException exception; exception[NetException::Critical] << "udp: WSAStartup failed: "; exception[NetException::Critical] << "socket: WSAStartup failed: "; } } ++_InitCount; } netplus::socket::~socket(){ --_Instance; --_InitCount; int zero = 0; if (_Instance.compare_exchange_strong(zero, std::memory_order_release)) { if (_InitCount.compare_exchange_strong(zero, std::memory_order_release)) { WSACleanup(); delete _WSAData; _WSAData = nullptr; Loading