Mega Search
23.2 Million


Sign Up

Make a donation  
TIdHTTP wihtout Synchronized events  
News Group: embarcadero.public.cppbuilder.internet.socket

Hi!

I'd like the TIdHTTP events to be fired in the same thread as the Get() 
method is running - especially the OnRedirect event. Is that possible 
without inheriting TIdHTTP? If not, how can I keep the redirection logic 
intact in my subclass?


class TIdHTTPUnsynchronizedEvents : public TIdHTTP {
protected:
   virtual bool __fastcall DoOnRedirect(AnsiString &Location,
                           AnsiString &VMethod, int RedirectCount);
public:
   inline __fastcall TTedHTTP(Classes::TComponent* AOwner) :
                     TIdHTTP(AOwner) { }
   inline __fastcall virtual ~TTedHTTP(void) { }
};

bool __fastcall TIdHTTPUnsynchronizedEvents::DoOnRedirect(
   AnsiString &Location, AnsiString &VMethod, int RedirectCount)
{
   bool Handled=false;
   if( OnRedirect ) {
     OnRedirect(this,Location,RedirectCount,Handled,VMethod);
   }
   // what now? :-)
}

This feels like the wrong approach...

Br,
Ted

-- 
Windows 7 32bit  |  RAD Studio 2007 | Indy 10_4819

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 19-Jun-2014, at 8:03 AM EST
From: Ted Lyngmo
 
Re: TIdHTTP wihtout Synchronized events  
News Group: embarcadero.public.cppbuilder.internet.socket
On 2014-06-19 17:03, Ted Lyngmo wrote:
> Hi!
>
> I'd like the TIdHTTP events to be fired in the same thread as the Get()
> method is running - especially the OnRedirect event.

Hmm, perhaps that's the way it's implemented already? Can I be so lucky? :-)

-- 
Windows 7 32bit  |  RAD Studio 2007 | Indy 10_4819

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 19-Jun-2014, at 8:36 AM EST
From: Ted Lyngmo
 
Re: TIdHTTP wihtout Synchronized events  
News Group: embarcadero.public.cppbuilder.internet.socket
On 2014-06-19 17:36, Ted Lyngmo wrote:
> On 2014-06-19 17:03, Ted Lyngmo wrote:
> > Hi!
> >
> > I'd like the TIdHTTP events to be fired in the same thread as the Get()
> > method is running - especially the OnRedirect event.
>
> Hmm, perhaps that's the way it's implemented already? Can I be so lucky? :-)

I used GetCurrentThreadId() in the various places and it seems I am that 
lucky. Forget this question :-)

Br,
Ted

-- 
Windows 7 32bit  |  RAD Studio 2007 | Indy 10_4819

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 19-Jun-2014, at 9:20 AM EST
From: Ted Lyngmo
 
Re: TIdHTTP wihtout Synchronized events  
News Group: embarcadero.public.cppbuilder.internet.socket
Ted wrote:

> I'd like the TIdHTTP events to be fired in the same thread as the
> Get() method is running

They already are.  You do not have to do anything special for that.

TIdHTTP (and most other Indy client components) do not use worker threads 
internally, they run in whatever thread context uses them.  That includes 
event handlers.

A few Indy client components do have internal worker threads, such as TIdTelnet, 
TIdCmdTCPClient, and TIdIPMCastClient.

> Is that possible without inheriting TIdHTTP?

Of course.  Just assign handlers to the events normally.  They will be triggered 
in whatever thread context is calling TIdHTTP::Get().

--
Remy Lebeau (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 19-Jun-2014, at 11:50 AM EST
From: Remy Lebeau (TeamB)