🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8665

Re: Doing ProcessMessages() in the TServiceApplication

#8665
From: Rex Chen
Date: Tue, 05 Oct 2004 09:24
80 lines
2992 bytes
Hi

My job is to implement a win32 service with a COM Interface in it.

It allows a COM client connect to my service and input some data ,

invoking an "Issue" method and my service will make a socket connection to a
remote host

send it a message and then wait for reply from remote

after remote reply, my service will return a value to Client.

note that the 'message send' and 'message receive' are in the same connection.

so here is the code...

/****************************************************/

int __fastcall TService1::Issue()
{
  char msg[] = "Some Message here....";
  int   msglen = sizeof(msg);

  try
  {
    ClientSocket1->Active = true;    // initially it is false

    // looping until Active is true
    while( ClientSocket1->Active == false)
ServiceThread->ProcessRequests(false);

    // message sending
    ClientSocket1->Socket->SendBuf( msg, msglen);

    // looping until remote reply
    while( ClientSocket1->Active == true)
ServiceThread->ProcessRequests(false);
  }
  catch( ... )
  {
    ClientSocket1->Active = false;
    return -1;
  }

  return 0;
}

void __fastcall TService1::ClientSocket1Read(TObject *Sender, TCustomWinSocket
*Socket)
{
  char buff[BUFFSIZE];
  int    len;

  len = Socket->ReceiveLength();
  Socket->ReceiveBuf( buff, len);
  ..... // do some processing
}

/****************************************************/

It works OK when only one client at a time, it is goot enough for this job.

but sill wandering whether there is a better way to do this or not

(say looping in COM method instead of Service method ?)

Any suggestion will be appreciate^^

What you've said is true. I should have my program multithreading


"Remy Lebeau (TeamB)" wrote:

> You should not be looping like that to begin with.  What exactly are you
> trying to accomplish in the first place?  Typically, you should be using
> multiple threads instead.  Don't put your work in the service's main thread
> at all, leave that alone to service the incoming SCM requests only.
>
> Gambit
Technical Details
Message-ID: <4162683A.71B0D6DB@iii.org.tw>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4160EDF4.3A72D30A@iii.org.tw> <416171a2@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,92472450cc43f536
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Message-ID: <4162683A.71B0D6DB@iii.org.tw>
Date: Tue, 05 Oct 2004 17:24:10 +0800
From: Rex Chen <chensc@iii.org.tw>
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Doing ProcessMessages() in the TServiceApplication
References: <4160EDF4.3A72D30A@iii.org.tw> <416171a2@newsgroups.borland.com>
Content-Type: text/plain; charset=big5
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 140.92.9.43
X-Trace: newsgroups.borland.com 1096968384 140.92.9.43 (5 Oct 2004 02:26:24 -0700)
Lines: 81
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail