bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

non-blocking socket


From: dani attila
Subject: non-blocking socket
Date: Mon, 09 Dec 2002 09:02:52 +0100

Hi,

I don't know if the following things are features or a bugs, so
I am sorry if I misunderstood something.
I wanted to use TCPStream (or tcpstream) in a non-blocking
mode, so I turned it on by stream.setCompletion(false). After
I found it difficult to recognize if the stream was still 
connected or an error happend. 
If the remote host closes the connection isActive() and 
isConnected() still say the stream is OK. Maybe the error() 
function should modify the state member variable in an error 
condition!
In the case of a reading from a non-blocking socket it can happen that
there is not as many bytes as I want to read. Then, getErrorNumber()
says errInput and stream.fail() = true. This ok but the result is
the same if the socket was closed. Maybe getErr...() should
return errNotConnected? Also, getErr..() should return errSuccess 
if a successful reading follows a bad one, becase now errid is 
never reseted.
The folowing modification in TCPStream::underflow() maybe would
solve the problem (same in readLine):

int TCPStream::underflow()
{
        ......

        if(!gptr())
                return EOF;

        if(gptr() < egptr())
                return (unsigned char)*gptr();

        rlen = (gbuf + bufsize) - eback();
        if(Socket::state == STREAM)
                rlen = ::read(so, (char *)eback(), rlen);
        else if(timeout && !Socket::isPending(pendingInput, timeout))
        {
                clear(ios::failbit | rdstate());
                error(errTimeout);
                return EOF;
        }
        else
                rlen = ::recv(so, (char *)eback(), rlen, 0);
        if(rlen < 1)
        {
                if(rlen < 0)
                {
                        clear(ios::failbit | rdstate());
                        error(errInput);
                }
                //!
                else {
                        clear(ios::failbit | rdstate());
                        error(errNotConnected);
                }
                //!
                return EOF;
        }
        //!
        error(errSuccess);
        //!
        setg(eback(), eback(), eback() + rlen);
        return (unsigned char) *gptr();
}


regards,
Attila Dani

ps.: I can detect correctly if a socket is closed with
isPending() etc. , but maybe this would be more consistent 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]