Should i Synchronize Session.object code execution in OnCommadGet

Giganews Newsgroups
Subject: Should i Synchronize Session.object code execution in OnCommadGet
Posted by:  Ken Madsen (kenh…@yahoo.dk)
Date: Wed, 31 Oct 2007

I am creating a http server that might become buisy  so i have to get
some advice.

I am using Turbo delphi 2006 prof. and indy 10.1.5

Here is some sample code of my implementation:

TMySession = class(TComponent)
private
public
  procedure DoSomething(ARequestInfo: TIdHTTPRequestInfo;
                        AResponseInfo: TIdHTTPResponseInfo);
end;

procedure TMySession.DoSomething(ARequestInfo,AResponseInfo);
begin
  // Maybe Accessing disk read and write
  // Maybe connect to a tcpserver thrue indy.TIdTCPClient
  // Reading from ARequestInfo and Write to AresponseInfo
end;

-------

TForm1 = class(TForm)
  HTTPServ: TIdHTTPServer;
  procedure HTTPServSessionStart(Sender: TIdHTTPSession);
  procedure HTTPServSessionEnd(Sender: TIdHTTPSession);
  procedure HTTPServCommandGet(AContext: TIdContext;
                                ARequestInfo: TIdHTTPRequestInfo;
                                AResponseInfo: TIdHTTPResponseInfo);
end;

procedure TForm1.HTTPServSessionStart(Sender: TIdHTTPSession);
begin
  Sender.Content.AddObject(FloatToStr(Now), TMySession.Create(nil));
end;

procedure TForm1.HTTPServSessionEnd(Sender: TIdHTTPSession);
begin
  TMySession(Sender.Content.Objects[0]).Free;
end;

procedure TForm1.HTTPServCommandGet(AContext: TIdContext;
                                    ARequestInfo: TIdHTTPRequestInfo;
                                    AResponseInfo: TIdHTTPResponseInfo);
begin
TMySession(ARequestInfo.Session.Content.Objects[0]).
  DoSomeThing(ARequestInfo,AResponseInfo);
end;

The clients may send more than one request at a time (or right after
another)

Is my implementation threadsafe or should i do something myself to be
sure the clients sessions dont interfear with another and if in case,
how can i do that?

Kindly regards and thanks in advance!

Ken Madsen

Replies