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 2005/10/16 16:49:50 UTC
svn commit: r322476 - in
/jakarta/httpclient/trunk/http-common/src/java/org/apache/http:
HttpConnection.java impl/AbstractHttpConnection.java
Author: olegk
Date: Sun Oct 16 07:49:44 2005
New Revision: 322476
URL: http://svn.apache.org/viewcvs?rev=322476&view=rev
Log:
* AbstractHttpConnection#close() reworked one more time
* AbstractHttpConnection#close() no longer attempt to synchronize access volatile data
* AbstractHttpConnection#shutdown() should be called to terminate the connection from a different thread
Modified:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpConnection.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/AbstractHttpConnection.java
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpConnection.java?rev=322476&r1=322475&r2=322476&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpConnection.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpConnection.java Sun Oct 16 07:49:44 2005
@@ -48,4 +48,5 @@
boolean isStale();
+ void shutdown() throws IOException;
}
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/AbstractHttpConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/AbstractHttpConnection.java?rev=322476&r1=322475&r2=322476&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/AbstractHttpConnection.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/AbstractHttpConnection.java Sun Oct 16 07:49:44 2005
@@ -106,25 +106,25 @@
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
- assertNotOpen();
- this.open = true;
- this.socket = socket;
- this.socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
- this.socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
+ socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
+ socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
int linger = HttpConnectionParams.getLinger(params);
if (linger >= 0) {
- this.socket.setSoLinger(linger > 0, linger);
+ socket.setSoLinger(linger > 0, linger);
}
int sndBufSize = HttpConnectionParams.getSendBufferSize(params);
if (sndBufSize >= 0) {
- this.socket.setSendBufferSize(sndBufSize);
+ socket.setSendBufferSize(sndBufSize);
}
int rcvBufSize = HttpConnectionParams.getReceiveBufferSize(params);
if (rcvBufSize >= 0) {
- this.socket.setReceiveBufferSize(rcvBufSize);
+ socket.setReceiveBufferSize(rcvBufSize);
}
+ assertNotOpen();
+ this.open = true;
+ this.socket = socket;
if (this.trxfactory != null) {
this.datatransmitter = this.trxfactory.create(this.socket);
} else {
@@ -140,30 +140,43 @@
public boolean isOpen() {
return this.open;
}
+
+ /**
+ * This is the only method, which may be called from a different thread to
+ * force shutdown the connection. This method will not attempt to flush the
+ * transmitter's internal buffer prior to closing the underlying socket.
+ */
+ public void shutdown() throws IOException {
+ this.open = false;
+ Socket tmpsocket = this.socket;
+ if (tmpsocket != null) {
+ tmpsocket.close();
+ }
+ }
+ /**
+ * This method will gracefully close the connection. It will attempt to
+ * flush the transmitter's internal buffer prior to closing the underlying
+ * socket. This method MAY NOT be called from a different thread to force
+ * shutdonw the connection. Use #shutdown() instead.
+ *
+ * @see #shutdown()
+ */
public void close() throws IOException {
+ if (!this.open) {
+ return;
+ }
this.open = false;
- synchronized (this) {
- HttpDataTransmitter tmptransmitter = this.datatransmitter;
- Socket tmpsocket = this.socket;
- this.datareceiver = null;
- this.datatransmitter = null;
- this.socket = null;
- if (tmptransmitter != null) {
- tmptransmitter.flush();
- }
- if (tmpsocket != null) {
- try {
- tmpsocket.shutdownOutput();
- } catch (IOException ignore) {
- }
- try {
- tmpsocket.shutdownInput();
- } catch (IOException ignore) {
- }
- tmpsocket.close();
- }
+ this.datatransmitter.flush();
+ try {
+ this.socket.shutdownOutput();
+ } catch (IOException ignore) {
+ }
+ try {
+ this.socket.shutdownInput();
+ } catch (IOException ignore) {
}
+ this.socket.close();
}
public boolean isStale() {