Hi guys,
I have just a problem with the Select timeout parameter.
The MSDN tells us:
microSeconds
The time-out value, in microseconds. A -1 value indicates an infinite
time-out.
I try to use -1 as timeout value but the select returns immediately.
That's correct if, at least, one of the list passed to the select has count
property 0.
But that's not happening to me.
Is it a bug? Did I make any kind of errors?
Someone seems to have the same problem using C#:
http://groups.google.it/group/micros...a02804279079e3
Thanks in advance.
Sektor.
Following the code used (it's like a proxy):
// Waiting for a connection
Socket^ fromClient = _accept(); // TcpListener, Start, AcceptSocket
// Create a connection to the server
TcpClient^ toServer = gcnew TcpClient();
toServer->Connect(Server Name, ServerPort);
//These work well
//bool b1 = fromClient->Poll(-1, SelectMode::Sel ectRead);
//bool b2 = toServer->Client->Poll(-1, SelectMode::Sel ectRead);
ArrayList^ checkRead = gcnew ArrayList();
array<Byte>^ buf = gcnew array<Byte>(DEF AULT_BUF_SIZE);
int n = 0;
bool toBeClose = false;
// Forward data
while (1) {
checkRead->Add(fromClient );
checkRead->Add(toServer->Client);
try {
Socket::Select( checkRead, nullptr, nullptr, -1);
for each (Socket^ s in checkRead) {
n = s->Receive(buf) ;
if (n <= 0) {
toBeClose = true;
break;
}
Array::Resize(b uf, n);
Byte prx;
if (s->Equals(fromCli ent)) {
toServer->GetStream()->Write(buf, 0, n);
} else {
fromClient->Send(buf);
}
Array::Resize(b uf, DEFAULT_BUF_SIZ E);
}
} catch (SocketExceptio n^ e) {
Console::WriteL ine("Sockets closed");
Console::WriteL ine(e->ToString());
return;
}
checkRead->Clear();
if (toBeClose)
break;
}