Re: Timeout Exceptions and the state of DataInputStream

Discussion in 'Java' started by Arne Vajhøj, Apr 3, 2012.

  1. Arne Vajhøj

    Arne Vajhøj Guest

    On 3/28/2012 7:59 PM, Ivan Ryan wrote:
    > I was wondering how the DataInputStream class handles Socket timeouts.
    >
    > For example, with code like the following:
    >
    > someSocket.setSoTimeout(1000);
    >
    > DataInputStream in = new DataInputStream(someSocket.getInputStream());
    >
    > long x = in.readLong()
    >
    > What would happen if the stream times out when reading the long.


    I think DataInputStream should just pass the SocketTimeoutException
    on from the some InputStream.

    > Would calling in.readLong() again give the correct value. This
    > assumes that the socket doesn't timeout the 2nd time.
    >
    > I assume that since the DataInputStream could be reading one byte at a
    > time, it doesn't hold internal state. This would mean that a few
    > bytes of the long could be lost?
    >
    > Another option is that the stream would "unread" the bytes or
    > something.


    Unless the Java docs actually guarantees a specific behavior, then
    you should not assume anything about lost or non lost. Anything could
    happen and it could differ between implementation and between version.

    You may need to redesign the logic.

    Arne
     
    Arne Vajhøj, Apr 3, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Thorner
    Replies:
    2
    Views:
    639
    John Thorner
    Nov 2, 2003
  2. Chris Berg
    Replies:
    1
    Views:
    7,283
    Esmond Pitt
    Nov 26, 2003
  3. Patrick
    Replies:
    6
    Views:
    886
    Roedy Green
    Jul 13, 2004
  4. JScoobyCed

    DataOutputStream/DataInputStream

    JScoobyCed, Aug 10, 2004, in forum: Java
    Replies:
    2
    Views:
    918
    Michael Borgwardt
    Aug 11, 2004
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,314
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page