BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TidPop3Server as a TService???

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Vern Six
Guest





PostPosted: Thu Feb 26, 2004 4:45 am    Post subject: TidPop3Server as a TService??? Reply with quote



I've written a fairly decent (I think) implementation of
TIdPop3Server. It works great (except for one small bug with a
stringlist that I am still tracking down)... but... I really need it
to be a TService and not a TApplication.

I know I can create and activate it in the TService.Execute method but
what then? Won't the TService.Execute just finish and then exit?
Causing the service to terminate?

I've never written an "event loop" type wrapper that I think I need
for this thing. Anyone have an idea where I should start???

A tangent question... if I use SLEEP(x) in the TService.Execute method
what will that do to the TIdPop3Server and it's calls to my
TIdServerThreadEvent functions? ie: OnConnect, OnDisconnect, etc.
Will a SLEEP() in the TService.Excute cause them to not function if
the TIdPop3Server tries to call them??

Thanks fellas. Sorry if my questions seem stupid. I'm 99.99% of the
way there... just a few little quirks that I need to work out.


------
Stop Spam before it ever reaches your inbox...
learn how by visting... http://www.SpamRival.com
Back to top
Ioan Ghip
Guest





PostPosted: Thu Feb 26, 2004 5:46 am    Post subject: Re: TidPop3Server as a TService??? Reply with quote




Quote:
Thanks fellas. Sorry if my questions seem stupid. I'm 99.99% of the
way there... just a few little quirks that I need to work out.


here is how your ServiceExecute peocedure has to look:


procedure TPFXInet.ServiceExecute(Sender: TService);
begin
FServer := TFaxTCPServer.Create;
{ Execute until we're told to stop }
while not Terminated do
begin
{ wait 2 seconds }
Sleep(2000);
{ Let other threads execute }
ServiceThread.ProcessRequests(FALSE);
end; { while not Terminated }
end;

and here is the whole service:
//---------------------------------
unit commmain;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
faxserver;

type
TPFXInet = class(TService)
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
procedure ServiceExecute(Sender: TService);
private
{ Private declarations }
FServer: TFaxTCPServer;
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;

var
PFXInet: TPFXInet;

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
PFXInet.Controller(CtrlCode);
end;

function TPFXInet.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;

procedure TPFXInet.ServiceStart(Sender: TService; var Started: Boolean);
begin
{ tell the OS that we're starting }
Started := TRUE;
end;

procedure TPFXInet.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
{ Tell the service thread to terminate }
ServiceThread.Terminate;
{ Tell the OS that we're stopping }
Stopped := TRUE;
FreeAndNil(FServer);
end;

procedure TPFXInet.ServiceExecute(Sender: TService);
begin
FServer := TFaxTCPServer.Create;
{ Execute until we're told to stop }
while not Terminated do
begin
{ wait 2 seconds }
Sleep(2000);
{ Let other threads execute }
ServiceThread.ProcessRequests(FALSE);
end; { while not Terminated }
end;


end.

//---------------------------------




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Feb 26, 2004 7:51 am    Post subject: Re: TidPop3Server as a TService??? Reply with quote



"Vern Six" <vsix (AT) vernsix (DOT) com> wrote


Quote:
I know I can create and activate it in the TService.Execute method

I do not suggest you use OnExecute at all. Active the TIdPop3Server in the
OnStart event instead, and deactivate it in the OnStop and OnShutdown
events. You can place the TIdPop3Server onto the service's designer (A
TService is a TDataModule descendant, afterall), you don't need to create it
dynamically at runtime.

Quote:
Won't the TService.Execute just finish and then exit?

Not if you don't use it to begin with. The service wll run just fine
without an OnExecute event handler assigned.

Quote:
A tangent question... if I use SLEEP(x) in the TService.Execute
method what will that do to the TIdPop3Server and it's calls to
my TIdServerThreadEvent functions?

Not a thing at all. TIdPop3Server is multi-threaded internally, all
operation are performed in threads other than the service thread.

Quote:
Will a SLEEP() in the TService.Excute cause them to not function
if the TIdPop3Server tries to call them??

No.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Feb 26, 2004 7:54 am    Post subject: Re: TidPop3Server as a TService??? Reply with quote

"Ioan Ghip" <delphi5e_not_this_ (AT) hotmail (DOT) com> wrote


Quote:
here is how your ServiceExecute peocedure has to look:

Here is a simplier service design:

type
TMyService = class(TService)
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
published
IdPOP3Server1: TIdPOP3Server;
public
function GetServiceController: TServiceController; override;
end;

var
MyService: TMyService;

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
MyService.Controller(CtrlCode);
end;

function TMyService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;

procedure TMyService.ServiceStart(Sender: TService; var Started:
Boolean);
begin
IdPop3Server1.Active := True;
Started := IdPop3Server1.Active;
end;

procedure TPFXInet.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
IdPop3Server1.Active := False;
Stopped := not IdPop3Server1.Active;
end;

end.


Gambit



Back to top
Ioan Ghip
Guest





PostPosted: Thu Feb 26, 2004 6:22 pm    Post subject: Re: TidPop3Server as a TService??? Reply with quote

Quote:
Not if you don't use it to begin with. The service wll run just fine
without an OnExecute event handler assigned.

that's good to know.
thanks Remy, I learn a lot of good stuff from you here.

-i



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.