nitaym / nexus Goto Github PK
View Code? Open in Web Editor NEWNexus Communication Infrastructure
License: MIT License
Nexus Communication Infrastructure
License: MIT License
Hello,
// Connect to server. l_iResult = connect(m_hSocket, l_pAddrInfo->ai_addr, (int)l_pAddrInfo->ai_addrlen); if (!SOCKET_TEST_RESULT(l_iResult)) { #ifdef _WIN32 closesocket(m_hSocket); m_hSocket = INVALID_SOCKET; #else close(m_hSocket); m_hSocket = 0; #endif }
suggested fix for the points above:
`int l_iResult;
#ifdef _WIN32
WSADATA l_oWSAData;
// Initialize Winsock
l_iResult = WSAStartup(MAKEWORD(2,2), &l_oWSAData);
if (l_iResult != 0)
{
dprintf("CSocket::CSocket> WSAStartup failed: %d\n", l_iResult);
return E_NEXUS_FAIL;
}
#endif
addrinfo *l_pAddrInfo = NULL;
addrinfo l_oHints;
memset(&l_oHints, 0, sizeof(l_oHints) );
l_oHints.ai_family = AF_UNSPEC;
l_oHints.ai_socktype = SOCK_STREAM;
l_oHints.ai_protocol = IPPROTO_TCP;
stringstream ss;
ss << m_wPort;
l_iResult = getaddrinfo(m_sIP.c_str(), ss.str().c_str(), &l_oHints, &l_pAddrInfo);
if (l_iResult != 0)
{
#ifdef _WIN32
SOCKET_CLEANUP()
#else
SOCKET_CLEANUP
#endif
dprintf("CSocket::CSocket> getaddrinfo failed: %d\n", l_iResult);
return E_NEXUS_FAIL;
}
#ifdef _WIN32
m_hSocket = socket(l_pAddrInfo->ai_family, l_pAddrInfo->ai_socktype, l_pAddrInfo->ai_protocol);
#else
m_hSocket = socket(AF_INET, SOCK_STREAM, 0);
#endif
if (!SOCKET_TEST(m_hSocket))
{
dprintf("CSocket::CSocket> Error at socket(): %ld\n", SOCKET_GETLASTERROR);
#ifdef _WIN32
SOCKET_CLEANUP()
#else
SOCKET_CLEANUP
#endif
freeaddrinfo(l_pAddrInfo);
return E_NEXUS_FAIL;
}
// Connect to server.
l_iResult = connect(m_hSocket, l_pAddrInfo->ai_addr, (int)l_pAddrInfo->ai_addrlen);
if (!SOCKET_TEST_RESULT(l_iResult))
{
#ifdef _WIN32
closesocket(m_hSocket);
m_hSocket = INVALID_SOCKET;
#else
close(m_hSocket);
m_hSocket = -1;
#endif
}
// Should really try the next address returned by getaddrinfo
// if the connect call failed
// But for this simple code we just free the resources
// returned by getaddrinfo and print an error message
freeaddrinfo(l_pAddrInfo);
if (!SOCKET_TEST(m_hSocket))
{
dprintf("CClientSocket::Connect> Unable to connect to server!\n");
#ifdef _WIN32
SOCKET_CLEANUP()
#else
SOCKET_CLEANUP
#endif
return E_NEXUS_FAIL;
}
m_bIsConnected = true;
return E_NEXUS_OK;`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.