🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Server as Service - not working

#1600
From: Quentin David Jones
Date: Fri, 08 Dec 2006 01:15
135 lines
4759 bytes
Finally, here is the Server as a service.
This version does not work.
I suspect the inner loop in ServiceExecute.


//---------------------------------------------------------------------------
#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);
}

//---------------------------------------------------------------------------
// Service Execute - mainline of service

void __fastcall TFileDateService::ServiceExecute(TService *Sender)
{
  // Handle exceptions
  try
  {
    // Enable the socket
    ServerSocket->Active = true;
    ShowMessage("Socket activated");

    // handle requests until service terminated
    while( !Terminated )
    {
      // Not sure if this is right - QQQ
      ServiceThread->ProcessRequests(true);
    }

    // disable socket and exit
    ServerSocket->Active = false;
    ShowMessage("Socket de-activated");
  }
  catch(...)
  {
    // Not implemented yet - QQQ
    ShowMessage("d'oh");
  }
}

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

void __fastcall TFileDateService::ServerSocketClientRead(TObject *Sender,
      TCustomWinSocket *Socket)
{
  // File name and age variables
  AnsiString FileName, FileResult;
  TDateTime FileDateTime;
  int Age;

  ShowMessage("ClientRead");

  // handle exceptions
  try
  {
    // copy filename from client
    FileName = Socket->ReceiveText();

    // Lookup file date
    Age = FileAge( FileName );
    if( Age == -1 )
    {
      // File Not found
      FileResult = FileName + " : File Not Found";
    }
    else
    {
      // File found - return date/time
      FileDateTime = FileDateToDateTime( Age );
      FileResult = FileName + " date: " + (AnsiString) FileDateTime;
    }

    // Now return the result to the client
    ServerSocket->Socket->Connections[0]->SendText( FileResult );
  }
  catch(...)
  {
    // Not implemented yet - QQQ
    ShowMessage("D'oh !");
  }
}
//---------------------------------------------------------------------------

void __fastcall TFileDateService::ServiceStart(TService *Sender,
      bool &Started)
{
   Started = true;
   ServiceRunning = true;
   ShowMessage("Date Svc Started");
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceStop(TService *Sender, bool &Stopped)
{
   Stopped = true;
   ServiceRunning = false;
   ShowMessage("Date Svc Stopped");
}
//---------------------------------------------------------------------------

void __fastcall TFileDateService::ServicePause(TService *Sender, bool &Paused)
{
   Paused = true;
   ServiceRunning = false;
   ShowMessage("Date Svc Paused");
}
//---------------------------------------------------------------------------

void __fastcall TFileDateService::ServiceContinue(TService *Sender,
      bool &Continued)
{
   Continued = true;
   ServiceRunning = true;
   ShowMessage("Date Svc Continued");
}
//---------------------------------------------------------------------------
Technical Details
Message-ID: <4578bc9c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4578ba1b@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>
Subject: Server as Service - not working
Date: Fri, 8 Dec 2006 10:15:58 +0900
Lines: 138
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: <4578bc9c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1165540508 203.59.8.178 (7 Dec 2006 17:15:08 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail