Blocking function with async messages

I am working on a problem and could use some help.  I am using the
Winsock API to write an HTTP implementation.  Winsock provides the
ability to have Windows send an (asynchronous) message when an event
occurs such as when Data is ready to be read.  I have defined several
additional event messages in my application.

In my case, I want to get a Web page, and have defined a method of my
object called "GET".  But I want GET to look like a normal blocking
function to the caller.  That is, I only want the call to GET to return
when all of the Web page has been retrieved.  This may trigger a number
of events.

But since the calls I issue to Winsock are asynchronous, I don't seem to
have a way to make the GET synchronous.

I tried this: have the asynch calls set a boolean to TRUE when the data
has been returned, and wrote a loop like this in GET:

  procedure THTTP.GET;
     bNotComplete := TRUE;
     while bNotComplete do begin

To make GET return, I just set bNotComplete to FALSE anywhere in the
object and that should be that.

The problem is, I am getting erratic behavior.  Is this a resonable thing
to do?  It seems a bit ugly to me.  Are there other approaches?  Or, am I
attacking the problem the wrong way?

  Tom Harrison  (
  Sublime Software