You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/03/14 18:07:48 UTC
svn commit: r1300643 - in
/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http:
impl/nio/NHttpConnectionBase.java impl/nio/reactor/IOSessionImpl.java
nio/reactor/SocketAccessor.java nio/reactor/ssl/SSLIOSession.java
Author: olegk
Date: Wed Mar 14 17:07:48 2012
New Revision: 1300643
URL: http://svn.apache.org/viewvc?rev=1300643&view=rev
Log:
HTTPCORE-295, HTTPCORE-288: provided direct access to the underlying socket of non-blocking HTTP connection to allow modification of socket level settings such as TCP_NODELAY, SO_KEEPALIVE, TrafficClass, etc at execution time.
Contributed by Jørgen Nordmoen <nordmoen90 at gmail.com>
Added:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SocketAccessor.java (with props)
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=1300643&r1=1300642&r2=1300643&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java Wed Mar 14 17:07:48 2012
@@ -30,6 +30,7 @@ package org.apache.http.impl.nio;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.Socket;
import java.net.SocketAddress;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
@@ -67,6 +68,7 @@ import org.apache.http.nio.reactor.IOSes
import org.apache.http.nio.reactor.SessionBufferStatus;
import org.apache.http.nio.reactor.SessionInputBuffer;
import org.apache.http.nio.reactor.SessionOutputBuffer;
+import org.apache.http.nio.reactor.SocketAccessor;
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
@@ -89,7 +91,7 @@ import org.apache.http.protocol.HttpCont
*/
@NotThreadSafe
public class NHttpConnectionBase
- implements NHttpConnection, HttpInetConnection, SessionBufferStatus {
+ implements NHttpConnection, HttpInetConnection, SessionBufferStatus, SocketAccessor {
protected final ContentLengthStrategy incomingContentStrategy;
protected final ContentLengthStrategy outgoingContentStrategy;
@@ -466,5 +468,13 @@ public class NHttpConnectionBase
buffer.append("]");
return buffer.toString();
}
+
+ public Socket getSocket() {
+ if (this.session instanceof SocketAccessor) {
+ return ((SocketAccessor) this.session).getSocket();
+ } else {
+ return null;
+ }
+ }
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java?rev=1300643&r1=1300642&r2=1300643&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java Wed Mar 14 17:07:48 2012
@@ -29,6 +29,7 @@ package org.apache.http.impl.nio.reactor
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.net.Socket;
import java.net.SocketAddress;
import java.nio.channels.ByteChannel;
import java.nio.channels.Channel;
@@ -41,6 +42,7 @@ import java.util.Map;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.SessionBufferStatus;
+import org.apache.http.nio.reactor.SocketAccessor;
/**
* Default implementation of {@link IOSession}.
@@ -48,7 +50,7 @@ import org.apache.http.nio.reactor.Sessi
* @since 4.0
*/
@ThreadSafe
-public class IOSessionImpl implements IOSession {
+public class IOSessionImpl implements IOSession, SocketAccessor {
private final SelectionKey key;
private final ByteChannel channel;
@@ -352,5 +354,14 @@ public class IOSessionImpl implements IO
buffer.append("]");
return buffer.toString();
}
+
+ public Socket getSocket() {
+ Channel channel = this.channel;
+ if (channel instanceof SocketChannel) {
+ return ((SocketChannel) channel).socket();
+ } else {
+ return null;
+ }
+ }
}
Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SocketAccessor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SocketAccessor.java?rev=1300643&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SocketAccessor.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SocketAccessor.java Wed Mar 14 17:07:48 2012
@@ -0,0 +1,46 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.nio.reactor;
+
+import java.net.Socket;
+
+/**
+ * Provides access to the underlying Socket.
+ * <p/>
+ * Remark: this interface will be removed in the next major release.
+ */
+public interface SocketAccessor {
+
+ /**
+ * Return the underlying socket
+ *
+ * @return - the underlying Socket, may be <code>null</code>.
+ */
+ Socket getSocket();
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SocketAccessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SocketAccessor.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SocketAccessor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java?rev=1300643&r1=1300642&r2=1300643&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java Wed Mar 14 17:07:48 2012
@@ -30,6 +30,7 @@ package org.apache.http.nio.reactor.ssl;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.nio.reactor.EventMask;
import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.reactor.SocketAccessor;
import org.apache.http.nio.reactor.SessionBufferStatus;
import javax.net.ssl.SSLContext;
@@ -41,6 +42,7 @@ import javax.net.ssl.SSLEngineResult.Sta
import javax.net.ssl.SSLException;
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.net.Socket;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
@@ -64,7 +66,7 @@ import java.nio.channels.SelectionKey;
* @since 4.2
*/
@ThreadSafe
-public class SSLIOSession implements IOSession, SessionBufferStatus {
+public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAccessor {
/**
* Name of the context attribute key, which can be used to obtain the
@@ -588,6 +590,14 @@ public class SSLIOSession implements IOS
buffer.append("]");
return buffer.toString();
}
+
+ public Socket getSocket(){
+ if (this.session instanceof SocketAccessor){
+ return ((SocketAccessor) this.session).getSocket();
+ } else {
+ return null;
+ }
+ }
private class InternalByteChannel implements ByteChannel {