Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: WaitForMultipleObjects

www.cryer.info
Managed Newsgroup Archive

Re: WaitForMultipleObjects

Subject:Re: WaitForMultipleObjects
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Wed, 16 Aug 2006 10:34:51

"Bart van der Werf" <bluelive@xs4all.nl> wrote in message
news:44e2f40b@newsgroups.borland.com...

>     WSAEventSelect( FSocket.Socket.Binding.Handle, FEvent, FD_READ +
> FD_CLOSE);

Indy uses (and requires) blocking sockets.  WSAEventSelect() cannot produce
those kinds of events for blocking sockets.  Worse, WSAEventSelect() forces
the specified socket into a non-blocking mode, which will break Indy.

>    WaitForManyObjects(@FEvent, 1, False, INFINITE);

Since you are only waiting on a single connection, just use Indy's own
Readable() method instead:

    if FSocket.IOHandler.Readable(IdTimeoutInfinite) then
        ...

However, I have to question your motives, because under normal
circumstances, you should not be waiting like that to begin with.  What
EXACTLY are you trying to accomplish?

> how can i expose such functionality through INDY ?

You have to store all of the desired socket handles into a list and then
pass that to the socket API select() function.  How you do that exactly
depends on the version of Indy that you are using, ie:

    --- Indy 9 ---

    uses
        IdStack;

    var
        List: TList;
        I: Integer;
    begin
        List := TList.Create;
        try
            List.Add(Pointer(FSocket.Socket.Binding.Handle));
            //...
            I := GStack.WSSelect(List, nil, nil, IdTimeoutInfinite);
        finally
            List.Free;
        end;
        //...
    end;


    --- Indy 10 ---

    uses
        IdStack;

    var
        List: TIdSocketList;
    begin
        List := TIdSocketList.CreateSocketList;
        try
            List.Add(FSocket.Socket.Binding.Handle);
            //...
            List.SelectRead(IdTimeoutInfinite);
        finally
            List.Free;
        end;
    end;


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive