Menu

TCPStream ,isPending linux and poll ?

Help
Anonymous
2002-04-16
2002-06-05
  • Anonymous

    Anonymous - 2002-04-16

    Hi,

    I'm trying to use TCPstream. I've had some success, in that I can connect to a server.

    I'm using RH 7.2, kernel 2.4.7, commom c++1.9.7

    My problem is with the isPending method.

    strm.isPending(SOCKET_PENDING_INPUT, 2000)
    will always return true, even if there is no pending input, i.e the server has sent nothing. I've even tried killing the server before ispending is called, but still the same.

    strm.isPending(SOCKET_PENDING_OUPUT, 2000)

    acts in s similar manner.

    strm.isPending(SOCKET_PENDING_ERROR, 2000)

    always return false, even when the server is dead.

    The only way I can get isPending to act differently is to Kill the server and then try to write to the output stream,

    sstrm << somechar

    then:

    strm.isPending(SOCKET_PENDING_OUPUT, 2000)

    will return false, I've looked into the socket.cpp code and i can see that revent from poll is 24, which is POLLUP and POLLERROR

    then if I do:

    trm.isPending(SOCKET_PENDING_INPUT, 2000)

    I still get a return value of true, looking again into socket.cpp, I can see that revent from poll is 25, which is:POLLHUP, POLLERROR,POLLIN.

    This seems to be strange?

    excuting :

    strm.isPending(SOCKET_PENDING_ERROR, 2000)

    after killing the server and doing a write will now return true.

    It seems to me that something strange is happening with linux poll? Can anyone help clarify what is happening here? Is there a fix for this?

    Thanks

    Neil.

     
    • Steven Ostrowski

      I'm having the same problem with this. In general, I'm trying to read data off the tcpstream, I've tried all ways of doing it (using the >> operator, read, getline, etc) and all have their own problems. I'd like to just use the >> operator since it's the cleanest.

      Currently, I'm trying to say something like:
      numAvail = tcp.rdbuf().in_avail();
      tcp.read(myBuf, numAvail);

      Often, numAvail is returning 0, even though the isPending says that there is data pending...

      getting frustrated... =)

       
      • Buck

        Buck - 2002-06-05

        streamsize streambuf::in_avail() should return the number of characters available in the streambuf. unfortunately, if you've drained the streambuf then this will be zero, whether the underlying OS socket buffer has data ready or not

        so i think once you know data isPending() in the OS socket buffer, you probably just have to bite the bullet and do a tcp.read(myBuf, some_size) to get the streambuf to underflow() and make a read system call on the OS socket to reload the streambuf. if data isPending(), then this shouldn't block (so long as somebody else doesn't read the data first)

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.