Wierd logic error....

This is a discussion on Wierd logic error.... within the C++ Programming forums, part of the General Programming Boards category; I am currently working on encapsulating winsock into a few classes in preparation for my p2p project that I am ...

  1. #1
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790

    Wierd logic error....

    I am currently working on encapsulating winsock into a few classes in preparation for my p2p project that I am planning. The problem, when my server class instantiates then calls the constructor, everything is fine; however, after the constructor call ends, my program immediately ends, no matter what I have after the constructor call, I cannot figure what in the heck is going wrong with this, because I was thinking originally it might come from the fact that I have one header file describing my classes, and different source files implementing each of those classes. THis was not the case, as even putting everything in my main source file didnt fix this problem.

    Code:
    int main()
        {
    
        T_SERVER ts;
        
        ts = T_SERVER(AF_INET,IPPROTO_TCP,SOCK_STREAM,DEF_PORT,10);
    
        printf("Hello\n");
    
        ts.ManageConnections();
        return 0;
        };
    now the server implementation(all of T_SOCKET works):
    Code:
    T_SERVER::T_SERVER(){
        T_SOCKET servSocket(BIND_LOCAL,AF_INET,"127.0.0.1",DEF_PORT,IPPROTO_TCP,SOCK_STREAM);
    
        bServRun = true;
    
        servSocket.PrepareSocket();
        servSocket.Socket();
        servSocket.Bind();
        servSocket.SetListenQueue(DEF_LQ);
        servSocket.Listen();
        maxfd = servSocket.GetSock();
        Sockets.push_back(servSocket);
        fprintf(stdout," : Server Initialized : \n");
        };
    
    T_SERVER::T_SERVER(SOCK_FAMILY sf,SOCK_PROTO sp,SOCK_TYPE st,PORT port,LISTEN_QUEUE lq){
        T_SOCKET servSocket(BIND_LOCAL,sf,"127.0.0.1",port,sp,st);
    
        bServRun = true;
    
        servSocket.PrepareSocket();
        servSocket.Socket();
        servSocket.Bind();
        servSocket.SetListenQueue(lq);
        servSocket.Listen();
        maxfd = servSocket.GetSock();
        Sockets.push_back(servSocket);
         fprintf(stdout," : Server Initialized : \n");
        }
    
    bool T_SERVER::ManageConnections(){
        while(bServRun){ // while server is running , we want to continually poll
            FILEDESC_LIST fdTemp;
    
    
            FD_ZERO(&fdTemp); // zero list
    
            // iterate through our SOCKETS and add them to the temporary fd_set so that they can be polled
            for(list<T_SOCKET>::iterator vSockIt = Sockets.begin();vSockIt != Sockets.end();vSockIt++)
                FD_SET(vSockIt->GetSock(),&fdTemp);
    
            int result = select(maxfd + 1,&fdTemp,NULL,NULL,0);
    
            // return if there is an error, if there arent any sockets to read, then end this iteration
            if(result == SOCKET_ERROR){
                fprintf(stderr," : Network Error - %i : \n",WSAGetLastError());
                return false;
                }
            else if(result == 0)
                continue;
    
            for(int i = 0; i < maxfd;i++){
    
                // handle connection
    
                }; 
    
            };
    
        return true;
        };
    now, in the contructors, the fprintf calls work;however, as I said, after the constructor call ends(this applies to both), the program just ends.

    NOTE: the constructors even do this when they have been totally commented out besides the printf call, and even when that is commented out the same result happens.

    EDIT: Nevermind, turns out that there ARE problems with my socket instantiation.
    Last edited by EvBladeRunnervE; 07-13-2004 at 10:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM

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