Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Async / sync class design question

Reply
Thread Tools

Async / sync class design question

 
 
Angus
Guest
Posts: n/a
 
      11-05-2006
Hello

I have written my own C++ class to handle winsock. It uses an asynchronous
programming model so basically you ask for something and then when network
has info it gets sent to my class and I can deal with it. Basically, a user
class derives from this networking class and overrides functions such as
OnCompleteMessage.

Sometimes, however, it is more convenient for the user class if it can call
a function which then provides the response on returning. Should I provide
synchronous functions in my class? Or is this bad design? Instead should
user class just work in same asynchronous manner? Or is there a good way to
deal with this sync function requirement some other way?

I know all this sounds vague but I am really looking for general design
guidance. I am happy to provide more details on the class or the class
itself if that would be useful.

Angus


 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      11-05-2006
Angus wrote:
> Hello
>
> I have written my own C++ class to handle winsock. It uses an asynchronous
> programming model so basically you ask for something and then when network
> has info it gets sent to my class and I can deal with it. Basically, a user
> class derives from this networking class and overrides functions such as
> OnCompleteMessage.
>
> Sometimes, however, it is more convenient for the user class if it can call
> a function which then provides the response on returning. Should I provide
> synchronous functions in my class? Or is this bad design? Instead should
> user class just work in same asynchronous manner? Or is there a good way to
> deal with this sync function requirement some other way?
>

That question depends on too many external considerations to have a
single answer. Can the application do useful work while it is waiting
for an asynchronous request to be processed? If so, it might as well
use one. If not, it should use a synchronous request.

Is the application event driven, or does it use threads?

Provide both if you are unsure of the usage pattern.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Angus
Guest
Posts: n/a
 
      11-05-2006
In answer to your question, sometimes the application can do useful work
while we wait. And the application is event driven.

But if, for example, I need a response from the server to start processing
something - eg:

1. Request a string from server

2. When we have string, do some string processing on the string.

I need to wait for 1. to finish before I can start on 2. I need a sort of
WaitForResponse function? Is that the way to do it?

I have a function in the network class called OnCompleteMessage. But how do
I know that the completemessage I get from this function is the particular
one I asked for here. Do I send a request asking for some sort of
requestid? Then wait until receive event that requestid x has completed?

I am still hazy about how to best do all this.

Angus



"Ian Collins" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Angus wrote:
> > Hello
> >
> > I have written my own C++ class to handle winsock. It uses an

asynchronous
> > programming model so basically you ask for something and then when

network
> > has info it gets sent to my class and I can deal with it. Basically, a

user
> > class derives from this networking class and overrides functions such as
> > OnCompleteMessage.
> >
> > Sometimes, however, it is more convenient for the user class if it can

call
> > a function which then provides the response on returning. Should I

provide
> > synchronous functions in my class? Or is this bad design? Instead

should
> > user class just work in same asynchronous manner? Or is there a good

way to
> > deal with this sync function requirement some other way?
> >

> That question depends on too many external considerations to have a
> single answer. Can the application do useful work while it is waiting
> for an asynchronous request to be processed? If so, it might as well
> use one. If not, it should use a synchronous request.
>
> Is the application event driven, or does it use threads?
>
> Provide both if you are unsure of the usage pattern.
>
> --
> Ian Collins.



 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      11-05-2006
Angus wrote:

Please don't top post.

> "Ian Collins" <(E-Mail Removed)> wrote in message
>>
>>That question depends on too many external considerations to have a
>>single answer. Can the application do useful work while it is waiting
>>for an asynchronous request to be processed? If so, it might as well
>>use one. If not, it should use a synchronous request.
>>
>>Is the application event driven, or does it use threads?
>>
>>Provide both if you are unsure of the usage pattern.
>>

> In answer to your question, sometimes the application can do useful work
> while we wait. And the application is event driven.
>
> But if, for example, I need a response from the server to start processing
> something - eg:
>
> 1. Request a string from server
>
> 2. When we have string, do some string processing on the string.
>
> I need to wait for 1. to finish before I can start on 2. I need a sort of
> WaitForResponse function? Is that the way to do it?
>

Fairly typical situation where you have to block. You can do this with
an async only interface, but it's clearer and safer to use a sync call.

> I have a function in the network class called OnCompleteMessage. But how do
> I know that the completemessage I get from this function is the particular
> one I asked for here. Do I send a request asking for some sort of
> requestid? Then wait until receive event that requestid x has completed?
>
> I am still hazy about how to best do all this.
>

Sounds like you have a long way to go. Restrict yourself to one
outstanding message, get that working then tackle the reply/response
matching issues.

--
Ian Collins.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie: async mode dedicated versus async mode interactive!! Pink_Floyd Cisco 4 06-16-2006 12:16 AM
Generic controlling sync/async reset Niv VHDL 9 01-05-2006 10:33 PM
sync.rb difference between Sync::UN, Sync::EX and Sync::SH Trans Ruby 2 12-12-2005 02:43 PM
Async webservice call in async webpage (.Net 2.0) does not return Steven ASP .Net Web Services 0 11-30-2005 01:06 AM
Basic question regarding sync and async serial interfaces... Ed Simmons Cisco 6 08-01-2004 03:13 AM



Advertisments