o The write() method now throws an IoException
o Called the closeNow() method instead of close(true)
o Called the removeNow() method instead of destroy() when we get an
exception while writing a buffer

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/0aefa807
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/0aefa807
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/0aefa807

Branch: refs/heads/2.0
Commit: 0aefa80711be8d078eb57d10f446e256120c31fd
Parents: e5d3a64
Author: Emmanuel Lécharny <elecha...@symas.com>
Authored: Thu Aug 11 17:13:58 2016 +0200
Committer: Emmanuel Lécharny <elecha...@symas.com>
Committed: Thu Aug 11 17:13:58 2016 +0200

----------------------------------------------------------------------
 .../polling/AbstractPollingIoProcessor.java     | 65 ++++++++++----------
 .../socket/nio/PollingIoProcessorTest.java      |  2 +-
 .../transport/socket/apr/AprIoProcessor.java    |  2 +-
 3 files changed, 34 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/0aefa807/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
----------------------------------------------------------------------
diff --git 
a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
 
b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
index 310a7ae..48604c8 100644
--- 
a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
+++ 
b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoProcessor.java
@@ -341,7 +341,7 @@ public abstract class AbstractPollingIoProcessor<S extends 
AbstractIoSession> im
      * @return the number of byte written
      * @throws Exception any exception thrown by the underlying system calls
      */
-    protected abstract int write(S session, IoBuffer buf, int length) throws 
Exception;
+    protected abstract int write(S session, IoBuffer buf, int length) throws 
IOException;
 
     /**
      * Write a part of a file to a {@link IoSession}, if the underlying API
@@ -757,36 +757,36 @@ public abstract class AbstractPollingIoProcessor<S 
extends AbstractIoSession> im
             SessionState state = getState(session);
 
             switch (state) {
-            case OPENED:
-                try {
-                    boolean flushedAll = flushNow(session, currentTime);
-
-                    if (flushedAll && 
!session.getWriteRequestQueue().isEmpty(session)
-                            && !session.isScheduledForFlush()) {
-                        scheduleFlush(session);
+                case OPENED:
+                    try {
+                        boolean flushedAll = flushNow(session, currentTime);
+    
+                        if (flushedAll && 
!session.getWriteRequestQueue().isEmpty(session)
+                                && !session.isScheduledForFlush()) {
+                            scheduleFlush(session);
+                        }
+                    } catch (Exception e) {
+                        scheduleRemove(session);
+                        session.close(true);
+                        IoFilterChain filterChain = session.getFilterChain();
+                        filterChain.fireExceptionCaught(e);
                     }
-                } catch (Exception e) {
-                    scheduleRemove(session);
-                    session.close(true);
-                    IoFilterChain filterChain = session.getFilterChain();
-                    filterChain.fireExceptionCaught(e);
-                }
-
-                break;
-
-            case CLOSING:
-                // Skip if the channel is already closed.
-                break;
-
-            case OPENING:
-                // Retry later if session is not yet fully initialized.
-                // (In case that Session.write() is called before addSession()
-                // is processed)
-                scheduleFlush(session);
-                return;
-
-            default:
-                throw new IllegalStateException(String.valueOf(state));
+    
+                    break;
+    
+                case CLOSING:
+                    // Skip if the channel is already closed.
+                    break;
+    
+                case OPENING:
+                    // Retry later if session is not yet fully initialized.
+                    // (In case that Session.write() is called before 
addSession()
+                    // is processed)
+                    scheduleFlush(session);
+                    return;
+    
+                default:
+                    throw new IllegalStateException(String.valueOf(state));
             }
 
         } while (!flushingSessions.isEmpty());
@@ -911,12 +911,11 @@ public abstract class AbstractPollingIoProcessor<S 
extends AbstractIoSession> im
                 // We have had an issue while trying to send data to the
                 // peer : let's close the session.
                 buf.free();
-                session.close(true);
-                destroy(session);
+                session.closeNow();
+                removeNow(session);
 
                 return 0;
             }
-
         }
 
         session.increaseWrittenBytes(localWrittenBytes, currentTime);

http://git-wip-us.apache.org/repos/asf/mina/blob/0aefa807/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java
 
b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java
index f65e512..379f55b 100644
--- 
a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java
+++ 
b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/PollingIoProcessorTest.java
@@ -148,7 +148,7 @@ public class PollingIoProcessorTest {
             }
 
             @Override
-            protected int write(NioSession session, IoBuffer buf, int length) 
throws Exception {
+            protected int write(NioSession session, IoBuffer buf, int length) 
throws IOException {
                 throw new NoRouteToHostException("No Route To Host Test");
             }
 

http://git-wip-us.apache.org/repos/asf/mina/blob/0aefa807/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java
----------------------------------------------------------------------
diff --git 
a/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java
 
b/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java
index 6a85d02..79fe741 100644
--- 
a/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java
+++ 
b/mina-transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprIoProcessor.java
@@ -420,7 +420,7 @@ public final class AprIoProcessor extends 
AbstractPollingIoProcessor<AprSession>
      * {@inheritDoc}
      */
     @Override
-    protected int write(AprSession session, IoBuffer buf, int length) throws 
Exception {
+    protected int write(AprSession session, IoBuffer buf, int length) throws 
IOException {
         int writtenBytes;
         if (buf.isDirect()) {
             writtenBytes = Socket.sendb(session.getDescriptor(), buf.buf(), 
buf.position(), length);

Reply via email to