Select

S

Sektor

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/micro...roblem+.net+-1&rnum=14&hl=it#23a02804279079e3

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;
}
 
C

Code Jockey

Not sure about the framework you are using, but select() will return
immediately if there is something wrong with the handles provided, and there
does not seem to be any checking for errors with Socket::Select().

Also, I forget now exactly the select() semantics, but if the socket was
closed by the other side, there may be a "read-condition true" situation
that is detected when recv() returns 0.
 
S

Sektor

Thanks for the answer.
I'm using .net framework 2.0.
Did you try my code or another code with the select using the c++/cli?
Does it work for you?
Bye
Sektor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top