home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pc3270sa.zip / apps / winaping / aping.cpp next >
Text File  |  2002-02-28  |  2KB  |  85 lines

  1. // aping.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "constdef.h"
  6. #include "aping.h"
  7.  
  8. #include "winaping.h"
  9. #include "mainfrm.h"
  10. #include "goview.h"
  11. #include "winapdoc.h"
  12. #include "docpic.h"
  13.  
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char BASED_CODE THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // aping
  21.  
  22. Aping::Aping()
  23. {
  24. }
  25.  
  26. Aping::~Aping()
  27. {
  28. }
  29.  
  30.  
  31. UINT Aping::PingIt(LPVOID pParam)
  32. {
  33.   CMainFrame*   pmf  = (CMainFrame*) pParam;
  34.   CWinapingDoc* pDoc = pmf->pDoc;
  35.   long          rc;
  36.   long          itertime;
  37.   BOOL          verifyok;
  38.  
  39.   rc = DoAllocate(pDoc);              // Go do cminit
  40.  
  41.   if ((rc <= 0) && (!pDoc->stoprunning))
  42.     pmf->pView->PostMessage(WM_REFRESH, 0, 0);
  43.  
  44.   if ((rc <= 0) &&  (!pDoc->stoprunning))
  45.     rc = DoExchange(pDoc);           // Go do exchange version/plateform info
  46.  
  47.   if ((rc == 0) && (!pDoc->stoprunning))
  48.     pmf->pView->PostMessage(WM_REFRESH, 0, 0);
  49.  
  50.   if ((rc == 0) &&  (!pDoc->stoprunning)) {
  51.     pDoc->buffer = (unsigned char *) malloc(pDoc->pingInfo.packetSize);
  52.     if (pDoc->buffer == NULL) {                          // failed to get buffer
  53.       pDoc->cmcall  = _T("Buffer allocation");
  54.       rc = LAST_MESSAGE_NUM-3;                           // special rc
  55.       }
  56.     else {                                               // Got a buffer
  57.       memset(pDoc->buffer, 0, pDoc->pingInfo.packetSize);
  58.       for (UINT i = 1; i <= pDoc->pingInfo.iterations; i++) {   // loop it
  59.         rc = DoIteration(pDoc, &itertime, &verifyok);    // Go do one iteration
  60.         if ((rc > 0) || (pDoc->stoprunning)) break;
  61.         if (!verifyok) itertime = -itertime;         // flag it if verify failed
  62.         pmf->pView->PostMessage(WM_REFRESH, i, itertime);
  63.         }
  64.       free (pDoc->buffer);
  65.       }
  66.     }
  67.  
  68.   if (rc != 0) {                       // display any error msg before deallc
  69.     DoTranslate(pDoc, rc);
  70.     pmf->pView->PostMessage(WM_CPICCALL_ERR, 0, 0);
  71.     Sleep(1000);                       // give it a little chance
  72.     }
  73.  
  74.   rc = DoDeallocate(pDoc);             // Always do cmdeallc
  75.  
  76.   if (rc != 0) {                       // display deallc error msg if any
  77.     DoTranslate(pDoc, rc);
  78.     pmf->pView->PostMessage(WM_CPICCALL_ERR, 0, 0);
  79.     Sleep(1000);                       // give it a little chance
  80.     }
  81.  
  82.   pmf->PostMessage(WM_APING_DONE, 0, 0);
  83.   return 0;
  84. }
  85.