JDK-4031100 : I need to set a timeout on a socket write
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.1,1.1.5,1.1.6
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS:
    generic,solaris_2.5,solaris_2.5.1,windows_nt generic,solaris_2.5,solaris_2.5.1,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 1997-02-08
  • Updated: 2002-10-29
  • Resolved: 2002-10-29
Related Reports
Duplicate :  
Description

Name: mc57594			Date: 02/07/97


The socket class has a method (setSotimeout) to set a timeout
on a read from a socket. However I (and I'm sure others) also 
need to set a timeout on a write from a socket. 

Let me explain:

If you need to communicate to a machine across a wide area 
network with routers etc. it is possible (or even likely) that 
a write on a socket will suspend because of network congestion.

The TCP/IP timeout period is far too long and I need to return
an error relatively quickly (5 - 10 seconds).

I therefore request that the method setSotimeout be extended to
include a write on a socket.

company  -  Pick 'n Pay  , email  -  ###@###.###
======================================================================

Comments
WORK AROUND Name: mc57594 Date: 02/07/97 The only obvious workaround is to use a different threads for read and write. ======================================================================
11-06-2004

EVALUATION We will likely introduce a mechanism to do select-like functionality in 1.3. This would let the user do what he needs to do. benjamin.renaud@Eng 1997-08-26 Contingent upon the support of asynchronous I/O. yingxian.wang@eng 2000-01-13 Using setSoTimeout to set a timeout for getInputStream().write is not appropriate for a blocking socket. Specifically write is specified to send the entire byte buffer rather than return the number of bytes sent. Even if it returns a byte count or threw an InterruptIOException indicating the number of bytes the quanity indicates the number of bytes queued to the TCP/IP and not the number of bytes actually transmitted to the peer. However if the requirement is to timeout if the data cannot be queued within a reasonable timeout (ie: peer is not reading or there is congestion) then this can be done with NIO. Specifically one can use a selector and register a channel for OP_WRITE events. The application can then select with a timeout. ###@###.### 2001-12-11 This feature is now covered by the NIO API which provides non-blocking operations on sockets. An application wishing a very fine control over outgoing operations like a Socket write should therefore use the SocketChannels instead. ###@###.### 2002-10-29
29-10-2002