Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13305 > unrolled thread
| Started by | Ivan Ryan <ivan.ryan@gmail.com> |
|---|---|
| First post | 2012-03-28 16:59 -0700 |
| Last post | 2012-04-02 19:40 -0400 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
Timeout Exceptions and the state of DataInputStream Ivan Ryan <ivan.ryan@gmail.com> - 2012-03-28 16:59 -0700
Re: Timeout Exceptions and the state of DataInputStream Knute Johnson <nospam@knutejohnson.com> - 2012-04-02 14:14 -0700
Re: Timeout Exceptions and the state of DataInputStream Arne Vajhøj <arne@vajhoej.dk> - 2012-04-02 19:40 -0400
| From | Ivan Ryan <ivan.ryan@gmail.com> |
|---|---|
| Date | 2012-03-28 16:59 -0700 |
| Subject | Timeout Exceptions and the state of DataInputStream |
| Message-ID | <6b38110d-6a91-463c-ba4e-857a267705e8@b14g2000vbz.googlegroups.com> |
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. 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.
[toc] | [next] | [standalone]
| From | Knute Johnson <nospam@knutejohnson.com> |
|---|---|
| Date | 2012-04-02 14:14 -0700 |
| Message-ID | <jld4qt$6jk$1@dont-email.me> |
| In reply to | #13305 |
On 3/28/2012 4: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. > 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. I'm not sure why you would have a timeout of only 1 second but I would not expect the socket to timeout if you were actually reading data. Timeouts are typically designed to detect a lack of transmission of data for a given period. For a system with a remote connection I would think that 1 second could easily be too short a period. -- Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-04-02 19:40 -0400 |
| Message-ID | <4f7a38d9$0$295$14726298@news.sunsite.dk> |
| In reply to | #13305 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web