You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ra...@apache.org on 2008/03/11 04:49:28 UTC
svn commit: r635792 - in /hadoop/core/trunk: CHANGES.txt
src/java/org/apache/hadoop/net/SocketIOWithTimeout.java
Author: rangadi
Date: Mon Mar 10 20:49:24 2008
New Revision: 635792
URL: http://svn.apache.org/viewvc?rev=635792&view=rev
Log:
HADOOP-2971. select multiple times if it returns early in
SocketIOWithTimeout. (rangadi)
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/java/org/apache/hadoop/net/SocketIOWithTimeout.java
Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=635792&r1=635791&r2=635792&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Mon Mar 10 20:49:24 2008
@@ -167,6 +167,9 @@
HADOOP-2973. Fix TestLocalDFS for Windows platform.
(Tsz Wo (Nicholas), SZE via dhruba)
+ HADOOP-2971. select multiple times if it returns early in
+ SocketIOWithTimeout. (rangadi)
+
Release 0.16.1 - 2008-03-13
INCOMPATIBLE CHANGES
Modified: hadoop/core/trunk/src/java/org/apache/hadoop/net/SocketIOWithTimeout.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/net/SocketIOWithTimeout.java?rev=635792&r1=635791&r2=635792&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/net/SocketIOWithTimeout.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/net/SocketIOWithTimeout.java Mon Mar 10 20:49:24 2008
@@ -163,20 +163,6 @@
}
if (count == 0) {
- String channelStr = "Unknown Channel";
- if (channel instanceof SocketChannel) {
- Socket sock = ((SocketChannel)channel).socket();
- SocketAddress remote = sock.getRemoteSocketAddress();
- SocketAddress local = sock.getLocalSocketAddress();
- channelStr = (remote == null ? "Unknown Addr" : remote) +
- " (local: " +
- (local == null ? "Unknown Addr" : local) + ")";
- } else if (channel instanceof Pipe.SinkChannel ||
- channel instanceof Pipe.SourceChannel) {
- channelStr = "pipe";
- } else if (channel instanceof DatagramChannel) {
- channelStr = "datagram channel";
- }
String waitingFor = ""+ops;
if (ops == SelectionKey.OP_READ) {
@@ -186,8 +172,8 @@
}
throw new SocketTimeoutException(timeout + " millis timeout while " +
- "waiting for " + channelStr +
- " to be ready for " + waitingFor);
+ "waiting for channel to be ready for "
+ + waitingFor + ". ch : " + channel);
}
// otherwise the socket should be ready for io.
}
@@ -245,11 +231,29 @@
SelectorInfo info = get(channel);
SelectionKey key = null;
- int ret = -1;
+ int ret = 0;
try {
- key = channel.register(info.selector, ops);
- ret = info.selector.select(timeout);
+ while (true) {
+ long start = (timeout == 0) ? 0 : System.currentTimeMillis();
+
+ key = channel.register(info.selector, ops);
+ ret = info.selector.select(timeout);
+
+ if (ret != 0) {
+ return ret;
+ }
+
+ /* Sometimes select() returns 0 much before timeout for
+ * unknown reasons. So select again if required.
+ */
+ if (timeout > 0) {
+ timeout -= System.currentTimeMillis() - start;
+ if (timeout <= 0) {
+ return 0;
+ }
+ }
+ }
} finally {
if (key != null) {
key.cancel();
@@ -268,8 +272,6 @@
release(info);
}
-
- return ret;
}
/**