directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r158883 - directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java
Date Thu, 24 Mar 2005 05:59:06 GMT
Author: trustin
Date: Wed Mar 23 21:59:05 2005
New Revision: 158883

URL: http://svn.apache.org/viewcvs?view=rev&rev=158883
Log:
* Reduced default size of socket session read buffer to 1024.
* Added SocketSessionConfig.sessionReceiveBufferSize property to let users adjust default
read buffer size.

Modified:
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?view=diff&r1=158882&r2=158883
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java Wed
Mar 23 21:59:05 2005
@@ -235,6 +235,9 @@
         ByteBuffer buf = session.getReadBuffer();
         SocketChannel ch = session.getChannel();
 
+        // Acquire buffer to prevent buffer is released by
+        // SocketSession.setReadBuffer()
+        buf.acquire(); 
         try
         {
             int readBytes = 0;
@@ -277,6 +280,10 @@
             if( e instanceof IOException )
                 scheduleRemove( session );
             session.getFilters().exceptionCaught( null, session, e );
+        }
+        finally
+        {
+            buf.release();
         }
     }
 

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java?view=diff&r1=158882&r2=158883
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java Wed Mar
23 21:59:05 2005
@@ -39,7 +39,7 @@
  */
 class SocketSession implements IoSession
 {
-    private static final int READ_BUFFER_SIZE = 8192;
+    private static final int DEFAULT_READ_BUFFER_SIZE = 1024;
 
     private final IoHandlerFilterChain filters;
 
@@ -47,7 +47,7 @@
 
     private final SocketSessionConfig config;
 
-    private final ByteBuffer readBuf;
+    private ByteBuffer readBuf;
 
     private final Queue writeBufferQueue;
 
@@ -83,12 +83,12 @@
      * Creates a new instance.
      */
     SocketSession( IoHandlerFilterChain filters, SocketChannel ch,
-                  IoHandler defaultHandler )
+                   IoHandler defaultHandler )
     {
         this.filters = filters;
         this.ch = ch;
-        this.config = new SocketSessionConfig( ch );
-        this.readBuf = ByteBuffer.allocate( READ_BUFFER_SIZE ).limit( 0 );
+        this.config = new SocketSessionConfig( this );
+        this.readBuf = ByteBuffer.allocate( DEFAULT_READ_BUFFER_SIZE ).limit( 0 );
         this.writeBufferQueue = new Queue();
         this.writeMarkerQueue = new Queue();
         this.handler = defaultHandler;
@@ -149,6 +149,12 @@
     ByteBuffer getReadBuffer()
     {
         return readBuf;
+    }
+    
+    synchronized void setReadBuffer( ByteBuffer readBuf )
+    {
+        this.readBuf.release(); // release old buffer
+        this.readBuf = readBuf;
     }
 
     Queue getWriteBufferQueue()

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java?view=diff&r1=158882&r2=158883
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java Wed
Mar 23 21:59:05 2005
@@ -19,8 +19,8 @@
 package org.apache.mina.io.socket;
 
 import java.net.SocketException;
-import java.nio.channels.SocketChannel;
 
+import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.util.BasicSessionConfig;
 
@@ -32,90 +32,100 @@
  */
 public class SocketSessionConfig extends BasicSessionConfig
 {
-    private final SocketChannel ch;
+    private final SocketSession session;
 
-    SocketSessionConfig( SocketChannel ch )
+    SocketSessionConfig( SocketSession session )
     {
-        this.ch = ch;
+        this.session = session;
     }
 
     public boolean getKeepAlive() throws SocketException
     {
-        return ch.socket().getKeepAlive();
+        return session.getChannel().socket().getKeepAlive();
     }
 
     public void setKeepAlive( boolean on ) throws SocketException
     {
-        ch.socket().setKeepAlive( on );
+        session.getChannel().socket().setKeepAlive( on );
     }
 
     public boolean getOOBInline() throws SocketException
     {
-        return ch.socket().getOOBInline();
+        return session.getChannel().socket().getOOBInline();
     }
 
     public void setOOBInline( boolean on ) throws SocketException
     {
-        ch.socket().setOOBInline( on );
+        session.getChannel().socket().setOOBInline( on );
     }
 
     public boolean getReuseAddress() throws SocketException
     {
-        return ch.socket().getReuseAddress();
+        return session.getChannel().socket().getReuseAddress();
     }
 
     public void setReuseAddress( boolean on ) throws SocketException
     {
-        ch.socket().setReuseAddress( on );
+        session.getChannel().socket().setReuseAddress( on );
     }
 
     public int getSoLinger() throws SocketException
     {
-        return ch.socket().getSoLinger();
+        return session.getChannel().socket().getSoLinger();
     }
 
     public void setSoLinger( boolean on, int linger ) throws SocketException
     {
-        ch.socket().setSoLinger( on, linger );
+        session.getChannel().socket().setSoLinger( on, linger );
     }
 
     public boolean getTcpNoDelay() throws SocketException
     {
-        return ch.socket().getTcpNoDelay();
+        return session.getChannel().socket().getTcpNoDelay();
     }
 
     public void setTcpNoDelay( boolean on ) throws SocketException
     {
-        ch.socket().setTcpNoDelay( on );
+        session.getChannel().socket().setTcpNoDelay( on );
     }
 
     public int getTrafficClass() throws SocketException
     {
-        return ch.socket().getTrafficClass();
+        return session.getChannel().socket().getTrafficClass();
     }
 
     public void setTrafficClass( int tc ) throws SocketException
     {
-        ch.socket().setTrafficClass( tc );
+        session.getChannel().socket().setTrafficClass( tc );
     }
 
     public int getSendBufferSize() throws SocketException
     {
-        return ch.socket().getSendBufferSize();
+        return session.getChannel().socket().getSendBufferSize();
     }
 
     public void setSendBufferSize( int size ) throws SocketException
     {
-        ch.socket().setSendBufferSize( size );
+        session.getChannel().socket().setSendBufferSize( size );
     }
 
     public int getReceiveBufferSize() throws SocketException
     {
-        return ch.socket().getReceiveBufferSize();
+        return session.getChannel().socket().getReceiveBufferSize();
     }
 
     public void setReceiveBufferSize( int size ) throws SocketException
     {
-        ch.socket().setReceiveBufferSize( size );
+        session.getChannel().socket().setReceiveBufferSize( size );
+    }
+    
+    public void getSessionReceiveBufferSize()
+    {
+        session.getReadBuffer().capacity();
+    }
+    
+    public void setSessionReceiveBufferSize( int size )
+    {
+        session.setReadBuffer( ByteBuffer.allocate( size ).limit( 0 ) );
     }
 }



Mime
View raw message