we're using CommonC++ for a few month now to implement a client server app. OS is SUN Solaris 2.6 with Visual Workshop 6.x.
since nearly everything works fine, we now have a problem with timeouts and non blocking reads in our app.
i'm using TCPSession to create a thread which communicates with the client. In the run method it has a loop like the following:
while (isPending(SOCKET_PENDING_INPUT, SocketTimeout))
{
char *sBuff;
sBuff = new char[x];
int nLen;
nLen = this->Readline(sBuff, 10, 1000);
}
so, the problems are:
1. i don't understand, why he runs into the while block, when nothing is send from the client.
2. the Readline method is called with timeout 1000, which should mean, come back, if nothing is sent in the next second, but it never comes back.
3. the Readline method calls the recv method. while constructing TCPSession, the sockets are set to nonblocking reads, which should mean, that recv should come back directly, if nothing is in the receive buffer. but it blocks.
4. the behaviour of the isPending methods is not clear for me. i can step trough the readline method seeing, that it calls the isPending from TCPSession with timeout, this delivers true in ANY case i've tested. then it calls the recv method and blocks. now, i interrupt the app, and see, i'm standing in the isPending method of Socket, with timeout set to infinit.
anybody here, who can explain this behaviour to me? perhaps, i did smething completly wrong ?
thx for help, every hint is welcome.
bye,
Michael Heck
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
found some answers to my own questions, but also some new questions.
as i figured out, answer to prob 1 und 4 is as follows:
the TCPSession uses the isPending method from TCPStream, which is a reimplementation of the Socket method.
The TCPStream::isPending(...) asks the streambuffer object with in_avail(), if something's here to read. this delivers true, even if the client hasn't sent anything.
so the new question is, why does the streambuffer method delivers true ?
same problem with the the Readline method, which uses also the TCPStream things.
Also i gured out, that the TCPSession set's non blocking io in the beginning of it's construtor, and undo this at end. this is not clearly documented, so i thought it was already non blocking and wondered about the behaviour.
so perhaps, someone can give me a hint about the streambuffer question ?
thx, michael
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hello,
we're using CommonC++ for a few month now to implement a client server app. OS is SUN Solaris 2.6 with Visual Workshop 6.x.
since nearly everything works fine, we now have a problem with timeouts and non blocking reads in our app.
i'm using TCPSession to create a thread which communicates with the client. In the run method it has a loop like the following:
while (isPending(SOCKET_PENDING_INPUT, SocketTimeout))
{
char *sBuff;
sBuff = new char[x];
int nLen;
nLen = this->Readline(sBuff, 10, 1000);
}
so, the problems are:
1. i don't understand, why he runs into the while block, when nothing is send from the client.
2. the Readline method is called with timeout 1000, which should mean, come back, if nothing is sent in the next second, but it never comes back.
3. the Readline method calls the recv method. while constructing TCPSession, the sockets are set to nonblocking reads, which should mean, that recv should come back directly, if nothing is in the receive buffer. but it blocks.
4. the behaviour of the isPending methods is not clear for me. i can step trough the readline method seeing, that it calls the isPending from TCPSession with timeout, this delivers true in ANY case i've tested. then it calls the recv method and blocks. now, i interrupt the app, and see, i'm standing in the isPending method of Socket, with timeout set to infinit.
anybody here, who can explain this behaviour to me? perhaps, i did smething completly wrong ?
thx for help, every hint is welcome.
bye,
Michael Heck
found some answers to my own questions, but also some new questions.
as i figured out, answer to prob 1 und 4 is as follows:
the TCPSession uses the isPending method from TCPStream, which is a reimplementation of the Socket method.
The TCPStream::isPending(...) asks the streambuffer object with in_avail(), if something's here to read. this delivers true, even if the client hasn't sent anything.
so the new question is, why does the streambuffer method delivers true ?
same problem with the the Readline method, which uses also the TCPStream things.
Also i gured out, that the TCPSession set's non blocking io in the beginning of it's construtor, and undo this at end. this is not clearly documented, so i thought it was already non blocking and wondered about the behaviour.
so perhaps, someone can give me a hint about the streambuffer question ?
thx, michael