BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WaitForMultipleObjects

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Bart van der Werf
Guest





PostPosted: Wed Aug 16, 2006 3:34 pm    Post subject: WaitForMultipleObjects Reply with quote



I want to use WaitForMultipleObjects to wait for a pool of connections.

with this peice of code as a start im currently trying to get it to work.

WSAEventSelect( FSocket.Socket.Binding.Handle, FEvent, FD_READ +
FD_CLOSE);
WaitForManyObjects(@FEvent, 1, False, INFINITE);


however WASEventSelect will put the socket into non blocking mode, something
i don't want for the writing part of the connection, how can i expose such
functionality through INDY ?

grt, Bart van der Werf
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Aug 16, 2006 10:34 pm    Post subject: Re: WaitForMultipleObjects Reply with quote



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

Quote:
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.

Quote:
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?

Quote:
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
Back to top
Alex Brainman
Guest





PostPosted: Thu Aug 17, 2006 8:11 am    Post subject: Re: WaitForMultipleObjects Reply with quote



Bart van der Werf wrote:
Quote:
I want to use WaitForMultipleObjects to wait for a pool of connections.


I'm not using Indy myself, but I use ioctlsocket function with FIONBIO
parameter to set/clear non-blocking i/o setting of my socket.


Alex
Back to top
Bart van der Werf
Guest





PostPosted: Thu Aug 17, 2006 3:17 pm    Post subject: Re: WaitForMultipleObjects Reply with quote

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:44e3577b$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Bart van der Werf" <bluelive (AT) xs4all (DOT) nl> wrote in message
news:44e2f40b (AT) newsgroups (DOT) 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.

Which is somethign i was affraid of, im currently recoding all of it to use
winsock directly.

Quote:
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?

I have multiple connections and a thread that is not fully dedicated to the
task of blocking on these connections if they are inactive, and i have some
more events that i must also monitor in the same waitfor (infact a complex
waitfor that allows me to workaround the 64 handle problem using threading)

Quote:
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:

Snip


Ooh great examples :)

I might rethink rewriting it using winsock if i can find a way to also wait
for a few non indy handles.

grt, bart
Back to top
Bart van der Werf
Guest





PostPosted: Mon Aug 21, 2006 6:32 pm    Post subject: Re: WaitForMultipleObjects Reply with quote

"Bart van der Werf" <bluelive (AT) xs4all (DOT) nl> wrote in message
news:44e2f40b (AT) newsgroups (DOT) borland.com...
Quote:
I want to use WaitForMultipleObjects to wait for a pool of connections.

with this peice of code as a start im currently trying to get it to work.

WSAEventSelect( FSocket.Socket.Binding.Handle, FEvent, FD_READ +
FD_CLOSE);
WaitForManyObjects(@FEvent, 1, False, INFINITE);

Rewrite it to talk directly to winsock, only added about 500 lines and 2
days
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.