WSA_INVALID_HANDLE Problem

This is a discussion on WSA_INVALID_HANDLE Problem within the Networking/Device Communication forums, part of the General Programming Boards category; Sockets are started to annoy me now. A SOCKET is just a u_int correct? So why is it that whenever ...

  1. #1
    and the hat of Marriage Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    178

    WSA_INVALID_HANDLE Problem

    Sockets are started to annoy me now. A SOCKET is just a u_int correct? So why is it that whenever I try to make a SOCKET == another SOCKET, doing operations on it always returns errors, and if I pass them into classes and member functions, they always return errors?

    Such as like this:

    Code:
    SOCKET newConn = lSocket.Accept(); 
    
    
            if (newConn != INVALID_SOCKET)
            {
                Socket ServerSocket(newConn);
                ServerSocket.SetIP(lSocket.GetIP());
    
    
                *StatusLogBox << "Attempted connection located.";
                *StatusLogBox << "Receiving Welcome Packet...";
                string received = ServerSocket.Receive();
    
    
                if (received.compare(RKL_INSTALL_DATA) == 0)
                {
                    *StatusLogBox << "Welcome Packet Received.";
                    int a = ServerSocket.Send(RKL_ACCEPTED_CONN);
    
    
                    i_Client->AddServer(newConn); //SOCKET is added to a vector as part of a globally declared class instance
                    i_Client->AddIP(ServerSocket.GetIP());
                    EventQueue->ThrowEvent(EVNT_NEW_INSTALL,new NewInstallEvent(ServerSocket.GetIP(),ServerSocket));
                }
                else
                {
                    *StatusLogBox << "v Connection terminated.";
                    ServerSocket.Drop();
                }
            }
    
    
            lSocket.SetBlocking(true);
    
    
            for (UINT i=0;i<i_Client->GetNumInstalls();i++)
            {
                if (i_Client->IsDataWaiting(i)) //Problem
    the function's send function (here) returns -1.

    Code:
    bool Client::IsDataWaiting(UINT index)
    {
        bool found = false; //found at least one server with data waiting
    
    
        SOCKET sv = Servers[index];
    
    
        if(send(sv,RKL_DATA_WAITING.c_str(),RKL_DATA_WAITING.length(),0) == SOCKET_ERROR)
        {
    Servers[0] (index==0), is the same newConn accept()ed SOCKET. Still the same number, but it returns -1 and WSAGetLastError() is... 6?

    Specified event object handle is invalid.An application attempts to use an event object, but the specified handle is not valid. Note that this error is returned by the operating system, so the error number may change in future releases of Windows.

    I've never seen that and when I looked, all I found was references to WSAWaitForMultipleEvents(), which I am not using. The handle should not have been deleted (although there is no handle so I'm even more confused.)

    I am at my last wit. What is up with SOCKETs?
    How to ask smart questions

    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesWritten);

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Does ServerSocket close or shutdown the SOCKET in its destructor? That object goes out of scope when you leave the
    Code:
    if (newConn != INVALID_SOCKET)
    block.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  2. sturct/pointer problem, and fscanf problem
    By hiphop4reel in forum C Programming
    Replies: 6
    Last Post: 07-28-2008, 09:40 AM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 08:14 AM
  5. Texture Problem(I got the NeHe tut working, but I have a problem)
    By SyntaxBubble in forum Game Programming
    Replies: 2
    Last Post: 12-02-2001, 09:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21