Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CWinThread::CAsyncSocket::Create issues

CWinThread::CAsyncSocket::Create issues

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studiodata-structuresdebugginghelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Hi, I have a derived CAsyncSocket class which is a protected member of a Derived CWinThread class There are 4 of the derived CWinThread Classes each with their own derived CAsynSocket Class I create or rather allocate storage for the derived CWinThread class on the heap via new after I create the CWinThread derived class suspended and set various members as the ipaddr Then I do a Resumethread in the CwinThread::Initinstance I do the CAsyncSocket::Create this is where the issue is while tracing the code under VS debugger the code jumps out the CWinThread::Initinstance back to my main line loop When I allocate a CAsyncSocket Class on the stack outside of the loop and do a Create everything is cool I get a return code of 1

    F 1 Reply Last reply
    0
    • F ForNow

      Hi, I have a derived CAsyncSocket class which is a protected member of a Derived CWinThread class There are 4 of the derived CWinThread Classes each with their own derived CAsynSocket Class I create or rather allocate storage for the derived CWinThread class on the heap via new after I create the CWinThread derived class suspended and set various members as the ipaddr Then I do a Resumethread in the CwinThread::Initinstance I do the CAsyncSocket::Create this is where the issue is while tracing the code under VS debugger the code jumps out the CWinThread::Initinstance back to my main line loop When I allocate a CAsyncSocket Class on the stack outside of the loop and do a Create everything is cool I get a return code of 1

      F Offline
      F Offline
      ForNow
      wrote on last edited by
      #2

      Hi I moved my code from the initinstance to the CWinThread constructer and it worked ? Don't know why

      A 1 Reply Last reply
      0
      • F ForNow

        Hi I moved my code from the initinstance to the CWinThread constructer and it worked ? Don't know why

        A Offline
        A Offline
        Albert Holguin
        wrote on last edited by
        #3

        What was the issue? ...you never actually say what the problem was.

        F 1 Reply Last reply
        0
        • A Albert Holguin

          What was the issue? ...you never actually say what the problem was.

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #4

          Hi I have a loop in my CWinApp::Initinstance where I create 4 Derived CWinThreads a derived CAsyncSocket class is a protected member When I step into with the debugger to the CasyncSocket::create it takes a wild which is in the CWinThread::Initinstance it takes a branch out the CWinThread::Initinstance back to the loop as if there some sort of exception I tried a try { around the code but it didn't go to the catch it just jumped out of the CWinThread::Initinstance back to the loop

               for (i = 0, start\_port = 11007; i < 4; start\_port++, i++)
                 {
          
          
                 threadptr\[i\] = new SockCLeintThread(start\_port);
          
          	    
                 if (threadptr\[i\] == NULL)
           	       AfxMessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB\_ICONERROR);
          
          
          	    ret = threadptr\[i\]->CreateThread(CREATE\_SUSPENDED);
          		          if(ret == 0)
          		             errcd = GetLastError();
          

          //
          threadptr[i]->flags.is_connected = 0;
          threadptr[i]->flags.busy = 0;
          threadptr[i]->ResumeThread();

          BOOL SockCLeintThread::InitInstance
          {
          AfxSocketInit();
          // ipaddr = "192.168.1.4";
          // thisocket(myport);
          ipaddr = (LPCTSTR)"10.0.0.205";

                	 	 if(thisocket.Create(thisocket.port,SOCK\_STREAM,(FD\_READ | FD\_WRITE | FD\_OOB | FD\_ACCEPT | FD\_CONNECT | FD\_CLOSE),ipaddr)== 0)
                {
                                error\_code =  thisocket.GetLastError();
                         }
          
          
           DWORD value;
           BOOL val, return\_code;
           const void \*valptr = &val;
            thisocket.AsyncSelect(FD\_READ | FD\_WRITE | FD\_OOB | FD\_ACCEPT | FD\_CONNECT | FD\_CLOSE); // request notifications
           val = 1;
           return\_code = thisocket.SetSockOpt(SO\_KEEPALIVE,valptr,sizeof(BOOL));//
           val = 1;
          return\_code = thisocket.SetSockOpt(SO\_OOBINLINE,valptr,sizeof(BOOL));
           value = 1;
           return\_code = thisocket.IOCtl(FIONBIO,&value);
           return\_code = thisocket.IOCtl(FIONREAD,&value);
           return\_code = thisocket.IOCtl(SIOCATMARK,&value);
          			  sockbuffer = new TCHAR\[100\];
          

          }

          When I move this code to the SockCLientThread constructor it works

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups