Loading src/windows/socket.cpp +7 −3 Original line number Diff line number Diff line Loading @@ -33,19 +33,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <cstdio> #include <cstring> #include <fcntl.h> #include <winsock.h> #include <string.h> #include "exception.h" #include "socket.h" #include "error.h" #include "config.h" #include <windows.h> #define HIDDEN __attribute__ ((visibility ("hidden"))) //#define HIDDEN __attribute__ ((visibility ("hidden"))) WSADATA* netplus::socket::_WSAData = nullptr; #define WIN32_LEAN_AND_MEAN #pragma comment (lib, "Ws2_32.lib") namespace netplus { std::atomic<int> _Instance; }; Loading src/windows/tcp.cpp +32 −31 Original line number Diff line number Diff line Loading @@ -27,14 +27,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <chrono> #include <thread> #include <cstring> #include <vector> #include <cstdio> #include <cstring> #include <windows.h> #include <winsock2.h> #include <fcntl.h> #include <winsock.h> #include <string.h> #include "exception.h" #include "socket.h" Loading Loading @@ -92,29 +92,29 @@ netplus::tcp::tcp(const char* addr, int port,int maxconnections,int sockopts) { ::freeaddrinfo(result); int optval = 1; setsockopt(_Socket, SOL_SOCKET, sockopts,&optval,sizeof(optval)); char* optval = nullptr; setsockopt(_Socket, SOL_SOCKET, sockopts,optval,sizeof(optval)); _Type=sockettype::TCP; } netplus::tcp::~tcp(){ if(_Socket>=0) ::close(_Socket); ::closesocket(_Socket); ::free(_SocketPtr); } netplus::tcp::tcp() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _Socket=::socket(((struct sockaddr*)_SocketPtr)->sa_family,SOCK_STREAM,0);; _SocketPtr=::malloc(sizeof(addrinfo)); _SocketPtrSize=sizeof(addrinfo); ((struct addrinfo*)_SocketPtr)->ai_family=AF_UNSPEC; _Socket=::socket(((struct addrinfo*)_SocketPtr)->ai_family,SOCK_STREAM,0);; _Type=sockettype::TCP; } netplus::tcp::tcp(int sock) { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _SocketPtr=::malloc(sizeof(addrinfo)); _SocketPtrSize=sizeof(addrinfo); ((struct addrinfo*)_SocketPtr)->ai_family=AF_UNSPEC; _Socket=sock; _Type=sockettype::TCP; } Loading Loading @@ -144,9 +144,9 @@ int netplus::tcp::getMaxconnections(){ void netplus::tcp::accept(socket *csock){ NetException exception; struct sockaddr myaddr; struct addrinfo myaddr; socklen_t myaddrlen=sizeof(myaddr); *csock=::accept(_Socket,(struct sockaddr *)&myaddr,&myaddrlen); *csock=::accept(_Socket,(struct addrinfo *)&myaddr,&myaddrlen); if(csock->_Socket<0){ int etype=NetException::Error; if(errno==EAGAIN) Loading @@ -164,7 +164,8 @@ void netplus::tcp::accept(socket *csock){ void netplus::tcp::bind(){ NetException exception; if (::bind(_Socket,((const struct sockaddr *)_SocketPtr), _SocketPtrSize) < 0){ if (::bind(_Socket,((const struct addrinfo *)_SocketPtr)->ai_addr, ((const struct addrinfo*)_SocketPtr)->ai_addrlen) < 0){ exception[NetException::Error] << "Can't bind Server Socket"; throw exception; } Loading @@ -180,10 +181,10 @@ unsigned int netplus::tcp::sendData(socket *csock, void* data, unsigned long siz NetException exception; int rval=::sendto(csock->_Socket, data, (char*)data, size, flags, (struct sockaddr *)&csock->_SocketPtr, (struct addrinfo *)&csock->_SocketPtr, csock->_SocketPtrSize ); if(rval<0){ Loading @@ -210,11 +211,11 @@ unsigned int netplus::tcp::recvData(socket *csock, void* data, unsigned long siz NetException exception; int recvsize=::recvfrom(csock->_Socket, data, (char*)data, size, flags, (struct sockaddr *)&csock->_SocketPtr, &csock->_SocketPtrSize (struct addrinfo *)csock->_SocketPtr, csock->_SocketPtrSize ); if(recvsize<0){ int etype=NetException::Error; Loading @@ -235,7 +236,7 @@ unsigned int netplus::tcp::recvData(socket *csock, void* data, unsigned long siz void netplus::tcp::connect(socket *csock){ NetException exception; if ( ::connect(csock->_Socket,(struct sockaddr*)csock->_SocketPtr,csock->_SocketPtrSize) < 0) { if ( ::connect(csock->_Socket,(struct addrinfo*)csock->_SocketPtr,csock->_SocketPtrSize) < 0) { char errstr[512]; strerror_r_netplus(errno,errstr,512); Loading @@ -247,12 +248,12 @@ void netplus::tcp::connect(socket *csock){ void netplus::tcp::getAddress(std::string &addr){ if(!_SocketPtr) return; char ipaddr[INET6_ADDRSTRLEN]; if(((struct sockaddr*)_SocketPtr)->sa_family==AF_INET6) inet_ntop(AF_INET6, &(((struct sockaddr_in6*)_SocketPtr)->sin6_addr), ipaddr, INET6_ADDRSTRLEN); else inet_ntop(AF_INET, &((struct sockaddr_in*)_SocketPtr)->sin_addr, ipaddr, INET_ADDRSTRLEN); addr=ipaddr; //if(!_SocketPtr) // return; //char ipaddr[INET6_ADDRSTRLEN]; //if(((struct addrinfo*)_SocketPtr)->sa_family==AF_INET6) // inet_ntop(AF_INET6, &(((struct addrinfo_in6*)_SocketPtr)->sin6_addr), ipaddr, INET6_ADDRSTRLEN); //else // inet_ntop(AF_INET, &((struct addrinfo_in*)_SocketPtr)->sin_addr, ipaddr, INET_ADDRSTRLEN); //addr=ipaddr; } src/windows/udp.cpp +19 −21 Original line number Diff line number Diff line Loading @@ -27,16 +27,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <chrono> #include <thread> #include <cstring> #include <vector> #include <cstdio> #include <cstring> #include <fcntl.h> #include <cstdio> #include <windows.h> #include <winsock2.h> #include <ws2tcpip.h> #include <string.h> #include <fcntl.h> #include "exception.h" #include "socket.h" Loading Loading @@ -95,7 +92,7 @@ netplus::udp::udp(const char* addr, int port,int maxconnections,int sockopts) { break; } ::freeaddrinfo(result); freeaddrinfo(result); } netplus::udp::~udp(){ Loading @@ -106,9 +103,9 @@ netplus::udp::~udp(){ } netplus::udp::udp(int sock){ _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _SocketPtr=::malloc(sizeof(addrinfo)); _SocketPtrSize=sizeof(addrinfo); ((struct addrinfo*)_SocketPtr)->ai_family=AF_UNSPEC; _Socket=sock; _Type=sockettype::UDP; } Loading Loading @@ -137,9 +134,9 @@ int netplus::udp::getMaxconnections(){ void netplus::udp::accept(socket *csock){ NetException exception; struct sockaddr_storage myaddr; struct addrinfo myaddr; socklen_t myaddrlen; *csock = ::accept(_Socket,(struct sockaddr *)&myaddr,&myaddrlen); *csock = ::accept(_Socket, &myaddr, &myaddrlen); if(csock->_Socket<0){ exception[NetException::Error] << "Can't accept on Socket"; throw exception; Loading @@ -151,7 +148,8 @@ void netplus::udp::accept(socket *csock){ void netplus::udp::bind(){ NetException exception; if (::bind(_Socket,((const struct sockaddr *)_SocketPtr), _SocketPtrSize) < 0){ if (::bind(_Socket,((const struct addrinfo*)_SocketPtr)->ai_addr, ((const struct addrinfo*)_SocketPtr)->ai_addrlen) < 0){ exception[NetException::Error] << "Can't bind Server Socket"; throw exception; } Loading Loading @@ -226,14 +224,14 @@ void netplus::udp::connect(socket *csock){ } void netplus::udp::getAddress(std::string &addr){ if(!_SocketPtr) return; char ipaddr[INET6_ADDRSTRLEN]; if(((struct sockaddr*)_SocketPtr)->sa_family==AF_INET6) inet_ntop(AF_INET6, &(((struct sockaddr_in6*)_SocketPtr)->sin6_addr), ipaddr, INET6_ADDRSTRLEN); else inet_ntop(AF_INET, &((struct sockaddr_in*)_SocketPtr)->sin_addr, ipaddr, INET_ADDRSTRLEN); addr=ipaddr; //if(!_SocketPtr) // return; //char ipaddr[INET6_ADDRSTRLEN]; //if(((struct sockaddr*)_SocketPtr)->sa_family==AF_INET6) // inet_ntop(AF_INET6, &(((struct sockaddr_in6*)_SocketPtr)->sin6_addr), ipaddr, INET6_ADDRSTRLEN); //else // inet_ntop(AF_INET, &((struct sockaddr_in*)_SocketPtr)->sin_addr, ipaddr, INET_ADDRSTRLEN); //addr=ipaddr; } Loading
src/windows/socket.cpp +7 −3 Original line number Diff line number Diff line Loading @@ -33,19 +33,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <cstdio> #include <cstring> #include <fcntl.h> #include <winsock.h> #include <string.h> #include "exception.h" #include "socket.h" #include "error.h" #include "config.h" #include <windows.h> #define HIDDEN __attribute__ ((visibility ("hidden"))) //#define HIDDEN __attribute__ ((visibility ("hidden"))) WSADATA* netplus::socket::_WSAData = nullptr; #define WIN32_LEAN_AND_MEAN #pragma comment (lib, "Ws2_32.lib") namespace netplus { std::atomic<int> _Instance; }; Loading
src/windows/tcp.cpp +32 −31 Original line number Diff line number Diff line Loading @@ -27,14 +27,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <chrono> #include <thread> #include <cstring> #include <vector> #include <cstdio> #include <cstring> #include <windows.h> #include <winsock2.h> #include <fcntl.h> #include <winsock.h> #include <string.h> #include "exception.h" #include "socket.h" Loading Loading @@ -92,29 +92,29 @@ netplus::tcp::tcp(const char* addr, int port,int maxconnections,int sockopts) { ::freeaddrinfo(result); int optval = 1; setsockopt(_Socket, SOL_SOCKET, sockopts,&optval,sizeof(optval)); char* optval = nullptr; setsockopt(_Socket, SOL_SOCKET, sockopts,optval,sizeof(optval)); _Type=sockettype::TCP; } netplus::tcp::~tcp(){ if(_Socket>=0) ::close(_Socket); ::closesocket(_Socket); ::free(_SocketPtr); } netplus::tcp::tcp() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _Socket=::socket(((struct sockaddr*)_SocketPtr)->sa_family,SOCK_STREAM,0);; _SocketPtr=::malloc(sizeof(addrinfo)); _SocketPtrSize=sizeof(addrinfo); ((struct addrinfo*)_SocketPtr)->ai_family=AF_UNSPEC; _Socket=::socket(((struct addrinfo*)_SocketPtr)->ai_family,SOCK_STREAM,0);; _Type=sockettype::TCP; } netplus::tcp::tcp(int sock) { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _SocketPtr=::malloc(sizeof(addrinfo)); _SocketPtrSize=sizeof(addrinfo); ((struct addrinfo*)_SocketPtr)->ai_family=AF_UNSPEC; _Socket=sock; _Type=sockettype::TCP; } Loading Loading @@ -144,9 +144,9 @@ int netplus::tcp::getMaxconnections(){ void netplus::tcp::accept(socket *csock){ NetException exception; struct sockaddr myaddr; struct addrinfo myaddr; socklen_t myaddrlen=sizeof(myaddr); *csock=::accept(_Socket,(struct sockaddr *)&myaddr,&myaddrlen); *csock=::accept(_Socket,(struct addrinfo *)&myaddr,&myaddrlen); if(csock->_Socket<0){ int etype=NetException::Error; if(errno==EAGAIN) Loading @@ -164,7 +164,8 @@ void netplus::tcp::accept(socket *csock){ void netplus::tcp::bind(){ NetException exception; if (::bind(_Socket,((const struct sockaddr *)_SocketPtr), _SocketPtrSize) < 0){ if (::bind(_Socket,((const struct addrinfo *)_SocketPtr)->ai_addr, ((const struct addrinfo*)_SocketPtr)->ai_addrlen) < 0){ exception[NetException::Error] << "Can't bind Server Socket"; throw exception; } Loading @@ -180,10 +181,10 @@ unsigned int netplus::tcp::sendData(socket *csock, void* data, unsigned long siz NetException exception; int rval=::sendto(csock->_Socket, data, (char*)data, size, flags, (struct sockaddr *)&csock->_SocketPtr, (struct addrinfo *)&csock->_SocketPtr, csock->_SocketPtrSize ); if(rval<0){ Loading @@ -210,11 +211,11 @@ unsigned int netplus::tcp::recvData(socket *csock, void* data, unsigned long siz NetException exception; int recvsize=::recvfrom(csock->_Socket, data, (char*)data, size, flags, (struct sockaddr *)&csock->_SocketPtr, &csock->_SocketPtrSize (struct addrinfo *)csock->_SocketPtr, csock->_SocketPtrSize ); if(recvsize<0){ int etype=NetException::Error; Loading @@ -235,7 +236,7 @@ unsigned int netplus::tcp::recvData(socket *csock, void* data, unsigned long siz void netplus::tcp::connect(socket *csock){ NetException exception; if ( ::connect(csock->_Socket,(struct sockaddr*)csock->_SocketPtr,csock->_SocketPtrSize) < 0) { if ( ::connect(csock->_Socket,(struct addrinfo*)csock->_SocketPtr,csock->_SocketPtrSize) < 0) { char errstr[512]; strerror_r_netplus(errno,errstr,512); Loading @@ -247,12 +248,12 @@ void netplus::tcp::connect(socket *csock){ void netplus::tcp::getAddress(std::string &addr){ if(!_SocketPtr) return; char ipaddr[INET6_ADDRSTRLEN]; if(((struct sockaddr*)_SocketPtr)->sa_family==AF_INET6) inet_ntop(AF_INET6, &(((struct sockaddr_in6*)_SocketPtr)->sin6_addr), ipaddr, INET6_ADDRSTRLEN); else inet_ntop(AF_INET, &((struct sockaddr_in*)_SocketPtr)->sin_addr, ipaddr, INET_ADDRSTRLEN); addr=ipaddr; //if(!_SocketPtr) // return; //char ipaddr[INET6_ADDRSTRLEN]; //if(((struct addrinfo*)_SocketPtr)->sa_family==AF_INET6) // inet_ntop(AF_INET6, &(((struct addrinfo_in6*)_SocketPtr)->sin6_addr), ipaddr, INET6_ADDRSTRLEN); //else // inet_ntop(AF_INET, &((struct addrinfo_in*)_SocketPtr)->sin_addr, ipaddr, INET_ADDRSTRLEN); //addr=ipaddr; }
src/windows/udp.cpp +19 −21 Original line number Diff line number Diff line Loading @@ -27,16 +27,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <chrono> #include <thread> #include <cstring> #include <vector> #include <cstdio> #include <cstring> #include <fcntl.h> #include <cstdio> #include <windows.h> #include <winsock2.h> #include <ws2tcpip.h> #include <string.h> #include <fcntl.h> #include "exception.h" #include "socket.h" Loading Loading @@ -95,7 +92,7 @@ netplus::udp::udp(const char* addr, int port,int maxconnections,int sockopts) { break; } ::freeaddrinfo(result); freeaddrinfo(result); } netplus::udp::~udp(){ Loading @@ -106,9 +103,9 @@ netplus::udp::~udp(){ } netplus::udp::udp(int sock){ _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _SocketPtr=::malloc(sizeof(addrinfo)); _SocketPtrSize=sizeof(addrinfo); ((struct addrinfo*)_SocketPtr)->ai_family=AF_UNSPEC; _Socket=sock; _Type=sockettype::UDP; } Loading Loading @@ -137,9 +134,9 @@ int netplus::udp::getMaxconnections(){ void netplus::udp::accept(socket *csock){ NetException exception; struct sockaddr_storage myaddr; struct addrinfo myaddr; socklen_t myaddrlen; *csock = ::accept(_Socket,(struct sockaddr *)&myaddr,&myaddrlen); *csock = ::accept(_Socket, &myaddr, &myaddrlen); if(csock->_Socket<0){ exception[NetException::Error] << "Can't accept on Socket"; throw exception; Loading @@ -151,7 +148,8 @@ void netplus::udp::accept(socket *csock){ void netplus::udp::bind(){ NetException exception; if (::bind(_Socket,((const struct sockaddr *)_SocketPtr), _SocketPtrSize) < 0){ if (::bind(_Socket,((const struct addrinfo*)_SocketPtr)->ai_addr, ((const struct addrinfo*)_SocketPtr)->ai_addrlen) < 0){ exception[NetException::Error] << "Can't bind Server Socket"; throw exception; } Loading Loading @@ -226,14 +224,14 @@ void netplus::udp::connect(socket *csock){ } void netplus::udp::getAddress(std::string &addr){ if(!_SocketPtr) return; char ipaddr[INET6_ADDRSTRLEN]; if(((struct sockaddr*)_SocketPtr)->sa_family==AF_INET6) inet_ntop(AF_INET6, &(((struct sockaddr_in6*)_SocketPtr)->sin6_addr), ipaddr, INET6_ADDRSTRLEN); else inet_ntop(AF_INET, &((struct sockaddr_in*)_SocketPtr)->sin_addr, ipaddr, INET_ADDRSTRLEN); addr=ipaddr; //if(!_SocketPtr) // return; //char ipaddr[INET6_ADDRSTRLEN]; //if(((struct sockaddr*)_SocketPtr)->sa_family==AF_INET6) // inet_ntop(AF_INET6, &(((struct sockaddr_in6*)_SocketPtr)->sin6_addr), ipaddr, INET6_ADDRSTRLEN); //else // inet_ntop(AF_INET, &((struct sockaddr_in*)_SocketPtr)->sin_addr, ipaddr, INET_ADDRSTRLEN); //addr=ipaddr; }