bug-commoncpp
[Top][All Lists]
Advanced

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

(no subject)


From: triendl klaus
Subject: (no subject)
Date: Mon, 2 Sep 2002 23:22:13 +0200

hi everybody,

i have a question to Socket::isPending(enPending, timeout).

according to the signature of this method it should be possible to tell this 
method to end after a certain time period if no data comes in anymore even if 
data is expected to come.

i looked closely at the code of TCPStream::isPending() and Socket::isPending() 
but for me it doesn't work like this.
in my case, isPending(Socket::pendingInput) in the client application is always 
blocking forever if the server doesn't send anything (or enough), even if i 
give a timout value.

i tried it both on my linux machine and with windows but no success.
it's important of course because what to do if the server doesn't send the 
whole data but is supposed to do so?


here is what i wanna do:
i establish a connection to the server, send him a header for the length of the 
coming binary data. the server should do something with the data and send back 
a response - also in form of a header with the length and binary data.


the code snippet:
        
        TCPStream con..
        .
        .
        con.write..
        .
        .
        char szBuf[..];
        int nBytesReceived = 0;
        int nDataLen = 0;
        int nBytesAvail;
        int i = 0;
        while (con.isPending(Socket::pendingInput), 100) // this should exit 
after 100ms, or?
        {
                if (!nDataLen)
                {
                        con.get(szBuf[i]);
                        if (szBuf[i] == 0x00)
                                nDataLen = atoi(szBuf);
                        ++i;
                        continue;
                }
                nBytesAvail = con.readsome(szBuf, nDataLen);
                cerr.write(szBuf, nBytesAvail);
                nBytesReceived += nBytesAvail;
                if (nBytesReceived == nDataLen)
                        break;
        }




thanks for every answer,

triendl klaus




reply via email to

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