Win32 ::shutdown() returns -1, but WSAGetLastError() returns 0?
Date : March 29 2020, 07:55 AM
wish help you to fix your issue The answer ended up being that nearly any system calls can clear Win32's "LastError()" errors... In my case, throwing an exception meant formatting and logging a message, which caused the error to be clear... And even though I was calling WSAGetLastError() immediately in my catch(...) it was already too late...
|
WSAGetLastError() returns 122
Tag : cpp , By : Chandra P Singh
Date : March 29 2020, 07:55 AM
will be helpful for those in need The problem is your implementation of operator const char*(). Once that function returns, your stringstream object is no longer valid because it is no longer in scope.
|
WSAGetLastError() returns 64?
Date : March 29 2020, 07:55 AM
around this issue Socket error codes start at 10000. 64 is not a documented socket error code that WSAGetLastError() can return. However, Windows error code 64 is ERROR_NETNAME_DELETED ("The specified network name is no longer available.").
|
Why do I get the WSAENOTSOCK error in this code?
Tag : cpp , By : Mostapen
Date : March 29 2020, 07:55 AM
this will help You are initializing the Socket member to the wrong value in the Winsock constructor - NULL instead of INVALID_SOCKET. They are not the same value. You are calling WSAAsyncSelect() regardless of whether socket() succeeds or fails. You are displaying error messages if things fail, but you are not stopping your code when they do fail. You need to clean up your error handling. class Winsock
{
public:
Winsock();
void Initialize(HWND);
void ReceiveMsg();
private:
SOCKET m_Socket;
...
};
Winsock::Winsock()
: m_Socket(INVALID_SOCKET)
{
}
void Winsock::Initialize(HWND hwnd)
{
SendMessage(hwnd, LOG_ADD, 0, (LPARAM)L"Initializing winsock... ");
WSADATA wsaDat = {0};
if (WSAStartup(MAKEWORD(2,2), &wsaDat) != 0)
{
SendMessage(hwnd, LOG_ADD, 0, (LPARAM)L"Winsock initialization failed");
return;
}
SendMessage(hwnd, LOG_ADD, 0, (LPARAM)L"Done!\nCreating a socket... ");
m_Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (m_Socket == INVALID_SOCKET)
{
SendMessage(hwnd, LOG_ADD, 0, (LPARAM)L"Socket Creation failed");
return;
}
SendMessage(hwnd, LOG_ADD, 0, (LPARAM)L"Done!\nRequesting Windows message-based notification of network events... ");
if (WSAAsyncSelect(m_Socket, hwnd, WM_SOCKET, FD_CLOSE|FD_READ) != 0)
{
SendMessage(hwnd, LOG_ADD, 0, (LPARAM)L"WSAAsyncSelect failed");
return;
}
/* More code */
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
if(SUCCEEDED(CoInitialize(NULL)))
{
Game game;
game.CreateResources(hInst);
game.ShowMainScreen();
...
}
}
void Game::CreateResources(HINSTANCE hInst)
{
m_hWnd = CreateWindowClass(hInst);
pMessageLog = CreateMessageLog();
pD2DResources = CreateD2DResources(m_hWnd);
pWinsock = CreateWinsock();
pWinsock->Initialize(m_hWnd);
}
|
ConnectEx returns false and WSAGetLastError returns 0
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Missed some context in the problem description. The socket was bound to an I/O completion port. The function call failed but result of ConnectEx was received through GetQueuedCompletionStatus in a worker thread. EDIT: I should have called WSAGetLastError() instead.
|