Author: trustin
Date: Sat Dec  4 04:48:12 2004
New Revision: 109796

URL: http://svn.apache.org/viewcvs?view=rev&rev=109796
Log:
 * Fixed: 100% CPU consumption
 * examples.echo.server.Main prints out the port number now.
Modified:
   
incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echo/server/Main.java
   
incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java

Modified: 
incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echo/server/Main.java
Url: 
http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echo/server/Main.java?view=diff&rev=109796&p1=incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echo/server/Main.java&r1=109795&p2=incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echo/server/Main.java&r2=109796
==============================================================================
--- 
incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echo/server/Main.java
      (original)
+++ 
incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echo/server/Main.java
      Sat Dec  4 04:48:12 2004
@@ -15,8 +15,11 @@
  * @version $Rev$, $Date$, 
  */
 public class Main {
+       private static final int PORT = 8080;
+
        public static void main(String[] args) throws Exception {
                Acceptor acceptor = new TcpAcceptor();
-               acceptor.bind(new InetSocketAddress(8080), new 
EchoServerSessionHandler());
+               acceptor.bind(new InetSocketAddress(PORT), new 
EchoServerSessionHandler());
+               System.out.println("Listening on port " + PORT);
        }
 }

Modified: 
incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java
Url: 
http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java?view=diff&rev=109796&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java&r1=109795&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java&r2=109796
==============================================================================
--- 
incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java
 (original)
+++ 
incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java
 Sat Dec  4 04:48:12 2004
@@ -166,6 +166,7 @@
                Iterator it = selectedKeys.iterator();
                while (it.hasNext()) {
                        SelectionKey key = (SelectionKey) it.next();
+                       it.remove();
                        TcpSession session = (TcpSession) key.attachment();
                        if (key.isReadable()) {
                                read(session);
@@ -173,6 +174,7 @@
                                scheduleFlush(session);
                        }
                }
+               selectedKeys.clear();
        }
        
        private void read(TcpSession session) {
@@ -196,14 +198,18 @@
                        }
                        
                        if (ret < 0) {
-                               synchronized (removingSessions) {
-                                       removingSessions.add(session);
-                               }
+                               scheduleRemove(session);
                        }
                } catch (IOException e) {
                        fireExceptionCaught(session, e);
                }
        }
+       
+       private void scheduleRemove(TcpSession session) {
+               synchronized (removingSessions) {
+                       removingSessions.add(session);
+               }
+       }
 
        private void scheduleFlush(TcpSession session) {
                session.getSelectionKey().interestOps(SelectionKey.OP_READ);
@@ -238,8 +244,6 @@
                        synchronized (writeBuf) {
                                writeBuf.flip();
                                int nBytes = ch.write(writeBuf);
-                               writeBuf.compact();
-                               
                                if (nBytes > 0)
                                        session.increaseWrittenBytes(nBytes);
 
@@ -248,6 +252,8 @@
                                        // Kernel buffer is full
                                        
session.getSelectionKey().interestOps(SelectionKey.OP_READ | 
SelectionKey.OP_WRITE);
                                }
+
+                               writeBuf.compact();
                        }
                } catch (IOException e) {
                        fireExceptionCaught(session, e);
@@ -281,6 +287,9 @@
        private void fireExceptionCaught(TcpSession session, Throwable cause) {
                try {
                        session.getHandler().exceptionCaught(session, cause);
+                       if (cause instanceof IOException) {
+                               scheduleRemove(session);
+                       }
                } catch (Throwable t) {
                        log.error("Exception from excaptionCaught.", t);
                }

Reply via email to