Name: dbT83986 Date: 08/15/99
Prior to invoking a read method on a socket call, I am setting a maximum time via the setSoTimeout(timewait) method. The problem is when the timeout happens and an exception is raised, I couldn't find a simple way to determine the current exception is related to expiration of the set time or not. I do not want to parse the text message of the exception and look for the string "Read timed out" as this may not be platform and release independent. I would like to check the expection just like other exceptions like if (e.getMessage().equalsIgnoreCase(bndexcp.getMessage()))
where bindexcp is an instance as given below: BindException bndexcp = new BindException();
Here is a portion of the code where socket read call is made after setting a time value:
try
{ if (readtime > 0 )
timewait = readtime; // milli secs
else
timewait = 20000; // default time
do
{ icb.clSocket.setSoTimeout(timewait);
strt_time = System.currentTimeMillis();
num = icb.reader.read(msg, (32600 - bytes_left), bytes_left);
if (num == -1)
{ icb.msglog.LogMsg("Connection lost on read", 1);
return(-3); // jss
}
else
icb.msglog.LogMsg("# Bytes read " + num, 8);
bytes_left -= num;
rc = irepCheckMsg(recv_buf, icb);
icb.msglog.LogMsg("rc from irepCheckMsg " + String.valueOf(rc), 8);
switch(rc)
{
case 0: return(0);
case -3: return(-3);
}
timewait -= (int)(System.currentTimeMillis() - strt_time);
}while(timewait > 0);
}
catch (Exception e)
{ icb.msglog.LogMsg(e.getMessage(), 1);
if (e.getMessage().equalsIgnoreCase(iointexcp.getMessage()))
{ icb.msglog.LogMsg("IO exception encountered in read process", 8);
return(-3); // jss
}
timewait -= (int)(System.currentTimeMillis() - strt_time);
icb.msglog.LogMsg("timewait" + timewait + " ", timewait);
if (timewait <= 100) /* previously it was 0 instead of 100 */
rc = -2; /* assuming read timed out */
else
rc = IREP.check_exception(e);
return(rc);
}
(Review ID: 93411)
======================================================================
- duplicates
-
JDK-4158021 cannot distinguish Thread.interrupt and Socket.setSoTimeout exceptions
-
- Resolved
-