🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #1611

Current code - API ASync Lookup error

#1611
From: Quentin David Jones
Date: Fri, 08 Dec 2006 04:45
137 lines
5246 bytes
Current Code for Server Service,
produces error about API ASync Lookup in event viewer


//---------------------------------------------------------------------------
#include "DateSvc.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TFileDateService *FileDateService;
//---------------------------------------------------------------------------

__fastcall TFileDateService::TFileDateService(TComponent* Owner)
 : TService(Owner)
{
}

TServiceController __fastcall TFileDateService::GetServiceController(void)
{
 return (TServiceController) ServiceController;
}

void __stdcall ServiceController(unsigned CtrlCode)
{
 FileDateService->Controller(CtrlCode);
}

//---------------------------------------------------------------------------
// ServerSocketClientRead - called when data available for reading from client

void __fastcall TFileDateService::ServerSocketClientRead(TObject *Sender,
      TCustomWinSocket *Socket)
{
   AnsiString FileName, FileResult;
   TSearchRec sr;

   // copy filename from client
   FileName = Socket->ReceiveText();

   // Lookup file date
   if( FindFirst(FileName, faAnyFile, sr) == 0 )
   {
     // File found - return date/time
     FindClose(sr);

     // Convert file time to date/time
     SYSTEMTIME st = {0};
     ::FileTimeToSystemTime(&sr.FindData.ftLastWriteTime, &st);

     // Generate result
     FileResult = FileName + " date: " + SystemTimeToDateTime(st).DateTimeString();
   }
   else
   {
     // File Not found
     FileResult = FileName + " : File Not Found";
   }

   // Now return the result to the client
   Socket->SendText(FileResult);
}

//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceStart(TService *Sender,
      bool &Started)
{
    ServerSocket->Active = true;
    LogMessage("Socket activated", EVENTLOG_INFORMATION_TYPE, 0, 0);
    Started = true;
}

//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceStop(TService *Sender, bool &Stopped)
{
   ServiceShutdown(Sender);
   Stopped = true;
   LogMessage("Socket DE-activated", EVENTLOG_INFORMATION_TYPE, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServicePause(TService *Sender, bool &Paused)
{
  // Check if socket has active connections
  if( ServerSocket->Socket->ActiveConnections == 0 )
  {
    // No connections, de-activate
    ServerSocket->Active = false;
    LogMessage("Socket de-activated for Svc pause",
      EVENTLOG_INFORMATION_TYPE, 0, 0);
    Paused = true;
  }
  else
  {
    // Active connections - cannot pause
    ErrCode = 5555; // use whatever you want
    LogMessage("Cannot pause Svc while clients are connected to the Socket",
      EVENTLOG_WARNING_TYPE, 0, 0);
    Paused = false;
  }
}

//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceContinue(TService *Sender,
      bool &Continued)
{
  // If socket is not active, turn it on
  if( !ServerSocket->Active )
  {
    ServerSocket->Active = true;
    LogMessage("Socket re-activated for continue",
       EVENTLOG_INFORMATION_TYPE, 0, 0);
  }
  Continued = true;
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceShutdown(TService *Sender)
{
  // If socket is active, shut it down
  if( ServerSocket->Active )
  {
    // Handle exception in socket de-activate
    try
    {
      // Shutdown the socket
      ServerSocket->Active = false;
      LogMessage("Socket de-activated",
        EVENTLOG_INFORMATION_TYPE,0, 0);
    }
    catch(const Exception &e)
    {
      // Exception occured in shutodnw
      ErrCode = 5556; // use whatever you want
      LogMessage("Socket not de-activated: " + e.Message,
        EVENTLOG_ERROR_TYPE, 0, 0);
    }
  }
}
Technical Details
Message-ID: <4578edb5$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4578ba1b@newsgroups.borland.com> <4578bc9c$1@newsgroups.borland.com> <4578d02b$1@newsgroups.borland.com> <4578dae2$1@newsgroups.borland.com> <4578ed46@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,c2ba0c1ed7538b68
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Quentin David Jones" <quentin.jones@romteck.com.spamprotect>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <4578ba1b@newsgroups.borland.com> <4578bc9c$1@newsgroups.borland.com> <4578d02b$1@newsgroups.borland.com> <4578dae2$1@newsgroups.borland.com> <4578ed46@newsgroups.borland.com>
Subject: Current code - API ASync Lookup error
Date: Fri, 8 Dec 2006 13:45:27 +0900
Lines: 140
Organization: Romteck P/L
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 203.59.8.178
Message-ID: <4578edb5$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1165553077 203.59.8.178 (7 Dec 2006 20:44:37 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail