 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bart van der Werf Guest
|
Posted: Wed Aug 16, 2006 3:34 pm Post subject: WaitForMultipleObjects |
|
|
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
|
Posted: Wed Aug 16, 2006 10:34 pm Post subject: Re: WaitForMultipleObjects |
|
|
"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
|
Posted: Thu Aug 17, 2006 8:11 am Post subject: Re: WaitForMultipleObjects |
|
|
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
|
Posted: Thu Aug 17, 2006 3:17 pm Post subject: Re: WaitForMultipleObjects |
|
|
"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
|
Posted: Mon Aug 21, 2006 6:32 pm Post subject: Re: WaitForMultipleObjects |
|
|
"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 |
|
 |
|
|
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
|
|