1

I encountered a very peculiar behavior on windows 7 with winsockets. Two librarys (Wt http://www.webtoolkit.eu/ libwebsocket https://libwebsockets.org/ ) and as well myself with a sample code got the errorcode 10022 ( Invalid argument. ) when running as normal user, and never when running as superuser. Neither the devs at the lib projects nor I can find a reason. I fear that its maybe a very hidden idiotic group rule in our company.

Example code to trigger:

#include <cstdlib>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <iostream>
#include <exception>
#include <stdexcept>
int main(int argc, char** argv) {
    WSADATA sinfo;
    int sr =  WSAStartup(MAKEWORD(2, 2),&sinfo);
    if (sr != 0)
    {
        std::cout << sr << std::endl;
        throw std::runtime_error("WSAStartup");
    }
    SOCKET listenSocket = socket(PF_INET, SOCK_STREAM, 0);
    if (listenSocket == INVALID_SOCKET)
    {
        std::cout << "Failed with "<< WSAGetLastError() << " " << GetLastError()<< std::endl;
        throw std::runtime_error("Socket");
    }
    WSACleanup();
    std::cout << "Finished" << std::endl;
    return 0;
} 

Output is: "Failed with 10022 10022"(and then of course the runtime_error caused terminate).

Superlokkus
  • 4,731
  • 1
  • 25
  • 57

1 Answers1

1

Finally I got the reason: This happens if the binary is being placed on e.g. execute from a network share/volume.

Microsoft has recognized the problems and delivers a hotfix: https://support.microsoft.com/en-us/kb/2649107

Superlokkus
  • 4,731
  • 1
  • 25
  • 57
  • 1
    Very curious. You might want to try setting the [`/SWAPRUN` linker flag](https://msdn.microsoft.com/en-us/library/chzz5ts6.aspx) and see if that makes any difference. – Harry Johnston Aug 12 '15 at 02:54
  • Phew had to build it with MSVC first, because I used mingw. But no, I used Visual Studio 2013 Essentials and enabled the swaprun option with the NET flag, but still same behavior. – Superlokkus Aug 12 '15 at 09:28
  • This is listed as a known problem and a hotfix is available under: https://support.microsoft.com/en-us/kb/2649107 – Superlokkus Aug 12 '15 at 22:47
  • Ah. According to that article the problem only occurs on NFS shares, which is an unusual configuration. That at least explains why nobody had heard of it before. :-) – Harry Johnston Aug 12 '15 at 22:53