[prev in list] [next in list] [prev in thread] [next in thread]
List: httpcomponents-commits
Subject: svn commit: r322473 -
From: olegk () apache ! org
Date: 2005-10-16 13:56:36
Message-ID: 20051016135637.56986.qmail () minotaur ! apache ! org
[Download RAW message or body]
Author: olegk
Date: Sun Oct 16 06:56:31 2005
New Revision: 322473
URL: http://svn.apache.org/viewcvs?rev=322473&view=rev
Log:
Reworked AbstractHttpConnection#close() to ensure proper synchronization to volatile \
data (such as transmitter's internal buffer)
Modified:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/AbstractHttpConnection.java
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/a \
pache/http/impl/AbstractHttpConnection.java?rev=322473&r1=322472&r2=322473&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 06:56:31 2005 @@ -53,9 +53,15 @@
*/
abstract class AbstractHttpConnection implements HttpConnection {
- protected volatile Socket socket = null;
- protected volatile HttpDataTransmitter datatransmitter = null;
- protected volatile HttpDataReceiver datareceiver = null;
+ /*
+ * I/O operations may not be performed if this flag is set to false
+ * All methods must call #assertOpen() to ensure the connection
+ * is open prior to performing any I/O
+ */
+ protected volatile boolean open;
+ protected Socket socket = null;
+ protected HttpDataTransmitter datatransmitter = null;
+ protected HttpDataReceiver datareceiver = null;
/*
* Dependent interfaces
@@ -82,13 +88,13 @@
}
protected void assertNotOpen() {
- if (this.socket != null) {
+ if (this.open) {
throw new IllegalStateException("Connection is already open");
}
}
protected void assertOpen() {
- if (this.socket == null) {
+ if (!this.open) {
throw new IllegalStateException("Connection is not open");
}
}
@@ -101,6 +107,7 @@
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));
@@ -131,28 +138,31 @@
}
public boolean isOpen() {
- return this.socket != null;
+ return this.open;
}
public void close() throws IOException {
- HttpDataTransmitter tmptransmitter = this.datatransmitter;
- if (tmptransmitter != null) {
- tmptransmitter.flush();
- }
- this.datareceiver = null;
- this.datatransmitter = null;
- Socket tmpsocket = this.socket;
- this.socket = null;
- if (tmpsocket != null) {
- try {
- tmpsocket.shutdownOutput();
- } catch (IOException ignore) {
- }
- try {
- tmpsocket.shutdownInput();
- } catch (IOException ignore) {
- }
- tmpsocket.close();
+ 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();
+ }
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic