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(ServerName, ServerPort);
//These work well
//bool b1 = fromClient->Poll(-1, SelectMode::SelectRead);
//bool b2 = toServer->Client->Poll(-1, SelectMode::SelectRead);
ArrayList^ checkRead = gcnew ArrayList();
array<Byte>^ buf = gcnew array<Byte>(DEFAULT_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(buf, n);
Byte prx;
if (s->Equals(fromClient)) {
toServer->GetStream()->Write(buf, 0, n);
} else {
fromClient->Send(buf);
}
Array::Resize(buf, DEFAULT_BUF_SIZE);
}
} catch (SocketException^ e) {
Console::WriteLine("Sockets closed");
Console::WriteLine(e->ToString());
return;
}
checkRead->Clear();
if (toBeClose)
break;
}