Groups > Novell > Novell Libc > Re: TCPIP Events - 1 attachment




TCPIP Events

TCPIP Events
Wed, 13 Jun 2007 00:28:01 GMT
I am new to TCPIP programming and I have a loop on my listener and it 
stops stops.  WSAWaitForMultipleEvents might not be returning anything 
anymore. What debugging code do I need to put in there to find out what 
is going wrong.

    while(iWorking || pbThreadCount > 0){
      if (CheckKeyStatus(mainScrID)) {
         GetKey(mainScrID, &iKeyType, &iKey, &iStatus,
&iScanCode, 0L);

        if (iKeyType == FUNCTION_KEY){
          switch(iKey){
              case 7: /* Stuff here*/
                         break;
              case 8:  Info();
                        break;
          }
        }
      }

      rc = WSAWaitForMultipleEvents(1,(const WSAEVENT FAR 
*)&acceptEvent, FALSE, 1000, FALSE);

      ltime(&tNowTime);

      if (tNowTime - tLastTime > 60){
          tLastTime = tNowTime;
          PBPrintTime(tNowTime - tStartTime);
      }

//      if (rc != 258){
//         printf("RC: %d",rc);
//      }

       switch (rc){
            case WSA_WAIT_EVENT_0: rc = 
WSAEnumNetworkEvents(listenSocket, acceptEvent, &NetworkEvents);

                                   if (rc == SOCKET_ERROR){
                                      sprintf(szBuffer, 
"WSAEnumNetworkEvents() error: %d\n",WSAGetLastError());
                                      ScreenLogWrite(szBuffer);
                                      break;
                                   }
                                   else{
                                      li_sxLen = sizeof(lsx_inAddress);
                                      li_nbytes = 
recvfrom(listenSocket,(char *)lsz_buf,sizeof(lsz_buf),0, (struct 
sockaddr *) &lsx_inAddress, &li_sxLen);

                                      if (iWorking){
                                         lPBThread = PBGetThreadFromPool();

                                      }
                                      else
                                         lPBThread = NULL;

                                      if (lPBThread == NULL){
                                         connectSocket = 
accept(listenSocket, (struct sockaddr *)&remAddr, &raddr);
                                         sprintf(szBuffer, "MaxThread 
Limit reached from :%d.%d.%d.%d",
 
remAddr.sin_addr.S_un.S_un_b.s_b1,
 
remAddr.sin_addr.S_un.S_un_b.s_b2,
 
remAddr.sin_addr.S_un.S_un_b.s_b3,
 
remAddr.sin_addr.S_un.S_un_b.s_b4);
                                         //sprintf(szBuffer, "MaxThread 
Limit Reached: %d\n",pbMaxThreads);
                                         closesocket(connectSocket);
                                         ScreenLogWrite(szBuffer);
                                         break;
                                      }

                                      // got connection and accept the 
connection
                                      lPBThread->connectSocket = 
accept(listenSocket, (struct sockaddr *)&remAddr, &raddr);

                                      if (lPBThread->connectSocket == 
INVALID_SOCKET){
                                         sprintf(szBuffer, "accept() 
error: %d\n",WSAGetLastError());
                                         ScreenLogWrite(szBuffer);
                                         break;
                                      }

                                      lPBThread->clientAddress = remAddr;
                                      //lPBThread->myContext = 
NXContextAlloc(HandleConnection , (void*)lPBThread, NX_PRIO_MED, 0, 
NX_CTX_NORMAL, &iError);
 
NXThreadCreate(lPBThread->myContext, NX_THR_DETACHED, 
&lPBThread->myThreadId);

 
//NXThreadCreateSx(HandleConnection, (void*)lPBThread, NX_THR_DETACHED, 
lPBThread->myContext, &lPBThread->myThread);
                                         if (lPBThread->myThreadId != NULL){
                                         pbThreadCount++;
                                         itoa(pbThreadCount, szBuffer, 10);
                                         DisplayScreenText(mainScrID, 9, 
14, 6, "      ");
                                         DisplayScreenText(mainScrID, 9, 
14, strlen(szBuffer), szBuffer);
 
FillScreenAreaAttribute(mainScrID, 9,14,9,16,31);
                                      }
                                      else{
                                         ScreenLogWrite("Thread Create 
Failed!");
                                      }
                                    }
                                    break;

             case WSA_WAIT_TIMEOUT: if (li_startupFlag == 1){
                                        li_startupFlag = 0;
                                     }

                                     DisplayScreenText(mainScrID, 7, 14, 
1, &lsz_spinner[li_spinnerPos++]);
                                     FillScreenAreaAttribute(mainScrID, 
7, 14, 1, 1, 31);

                                     if (li_spinnerPos > 3)
                                        li_spinnerPos = 0;

                                    break;
             case WSA_WAIT_FAILED:  printf("WSA_WAIT_FAILED returned 
from read wait\r\n");
             default:              break;
        }//end switch

       gettimeofday( &tp, &tpz );
       t = tp.tv_sec;
       today = localtime( &t );
       ScreenLogWrite(asctime(today));
     }//end while

     if (acceptEvent != NULL)
        WSACloseEvent(acceptEvent);

     if (listenSocket != INVALID_SOCKET){
        closesocket(listenSocket);
        listenSocket = INVALID_SOCKET;
     }

    ScreenLogWrite("AcceptConnection Abort");
     return 0;
Post Reply
Re: TCPIP Events - 1 attachment
Wed, 13 Jun 2007 09:34:04 GMT
Hi Bob,
Bob Piskac <bob@pbsoftware.com> wrote in
news:lSGbi.1621$%54.474@prv-forum2.provo.novell.com: 
> I am new to TCPIP programming and I have a loop on my listener and it 
> stops stops.  WSAWaitForMultipleEvents might not be returning anything 
> anymore. What debugging code do I need to put in there to find out what 
> is going wrong.
I found an old CLIB-based sample on my HD called echo-daemon.c which might 
help you; it opens some debug screens to show what's going on....
I got it compiled with CLIB (for what its written), but for LIBC you need to 
port the stuff which is screen-, semaphore-  and thread-related....
the Winsock stuff should though be identical, and at least might help a 
bit...
perhaps we can get Jeff for taking a look at it; would be nice to have that 
sample in LIBC...
Gün.
Post Reply
Re: TCPIP Events - 1 attachment
Thu, 14 Jun 2007 00:16:53 GMT
Thanks, I will start the rewrite and post it back.
Guenter wrote:
> Hi Bob,
> 
> Bob Piskac <bob@pbsoftware.com> wrote in
> news:lSGbi.1621$%54.474@prv-forum2.provo.novell.com: 
> 
>> I am new to TCPIP programming and I have a loop on my listener and it 
>> stops stops.  WSAWaitForMultipleEvents might not be returning anything

>> anymore. What debugging code do I need to put in there to find out what

>> is going wrong.
> I found an old CLIB-based sample on my HD called echo-daemon.c which might

> help you; it opens some debug screens to show what's going on....
> I got it compiled with CLIB (for what its written), but for LIBC you need
to 
> port the stuff which is screen-, semaphore-  and thread-related....
> the Winsock stuff should though be identical, and at least might help a 
> bit...
> perhaps we can get Jeff for taking a look at it; would be nice to have that

> sample in LIBC...
> 
> Gün.
Post Reply
Re: TCPIP Events - 1 attachment
Wed, 20 Jun 2007 00:58:43 GMT
I found my mistake.  I commented out my socket error handling....

ccode = recv(lPBThread->connectSocket, lPBThread->szBuf, iClientSize, 0);

switch(ccode){
    case SOCKET_ERROR: errorCode = WSAGetLastError();
              if (errorCode != 10035){
                 sprintf(szBuffer,"recv(12) error: %d", errorCode);
                 ScreenLogWrite(szBuffer);
             }
     break;

I think I did not know that a 10035 error code was ok.  So, I just 
commented it out.  I added error handling and all seems well now.  Time 
Post Reply
about | contact