[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] storm/org/nongnu/storm/http HTTPSendableMessage...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] storm/org/nongnu/storm/http HTTPSendableMessage... |
Date: |
Thu, 24 Apr 2003 13:42:19 -0400 |
CVSROOT: /cvsroot/storm
Module name: storm
Changes by: Benja Fallenstein <address@hidden> 03/04/24 13:42:19
Modified files:
org/nongnu/storm/http: HTTPSendableMessage.java
Log message:
Apply ibid's patch
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/http/HTTPSendableMessage.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: storm/org/nongnu/storm/http/HTTPSendableMessage.java
diff -u storm/org/nongnu/storm/http/HTTPSendableMessage.java:1.1
storm/org/nongnu/storm/http/HTTPSendableMessage.java:1.2
--- storm/org/nongnu/storm/http/HTTPSendableMessage.java:1.1 Sat Apr 19
08:20:29 2003
+++ storm/org/nongnu/storm/http/HTTPSendableMessage.java Thu Apr 24
13:42:19 2003
@@ -41,10 +41,15 @@
* @param chunked Should the body use HTTP chunked mode?
* @param suppressBody Should the response not contain a body?
*/
- public HTTPSendableMessage(OutputStream os, boolean chunked,
+ public HTTPSendableMessage(final OutputStream os, boolean chunked,
String startLine,
boolean suppressBody) throws IOException {
- this.os = os;
+ this.os = new OutputStream() {
+ public void write(int b) throws IOException {
+ os.write(b);
+ if (dbg) System.out.write(b);
+ }
+ };
this.startLine = startLine + "\r\n";
OutputStream s = new IdentityOutputStream();
if (suppressBody) {
@@ -52,8 +57,8 @@
s = new NullOutputStream();
} else if (chunked) {
p("chunked");
- s = TransferEncodingHandler.get("chunked").encode(s);
setField("Transfer-Encoding", "chunked");
+ s = TransferEncodingHandler.get("chunked").encode(s);
this.chunked = true;
} else {
p("identity");
@@ -75,8 +80,9 @@
* @throws IOException There was a problem in sending data to the
* network.
*/
- public void commit() throws IOException {
- if (!startCommit()) return;
+ public synchronized void commit() throws IOException {
+ if (closed) throw new Error("AARGH!");
+ if (committed || !startCommit()) return;
byte[] ba = new byte[startLine.length()];
for (int i = 0; i < ba.length; i++) ba[i] = (byte)startLine.charAt(i);
os.write(ba);
@@ -121,6 +127,7 @@
* network
*/
public synchronized void close() throws IOException {
+ if (closed) return;
commit();
bos.close();
endCommit();
@@ -151,7 +158,7 @@
/** Get the output stream to the body of this message.
* @return An output stream to the body of this message.
*/
- public OutputStream getOutputStream() { return bos; }
+ public OutputStream getOutputStream() { return bos; }
/** Get a writer to the body of this message.
* @return An UTF-8 writer that writes to the body of
@@ -163,12 +170,15 @@
}
protected synchronized void commit(String name) throws IOException {
+ if (closed) throw new Error("AARGH!");
Object o = header.get(name.toLowerCase());
if (o == null) return;
FieldData fd = (FieldData)o;
if (fd.committed) return;
fd.committed = true;
- os.write(formatField(fd.name + ": " + fd.body));
+ byte[] formatted = formatField(fd.name + ": " + fd.body);
+ //if (dbg) System.out.write(formatted);
+ os.write(formatted);
os.flush();
}
@@ -190,12 +200,12 @@
private HashMap header = new HashMap();
private final OutputStream os;
private final OutputStream bos;
- private boolean hasBody = false;
private static final byte[] crlf = new byte[] { 13, 10 };
private boolean committed = false;
private boolean chunked;
+ private boolean closed = false;
- private void assertFieldNotCommitted(String name) {
+ private synchronized void assertFieldNotCommitted(String name) {
if (committed && !chunked) throw new CommittedError();
Object o = header.get(name.toLowerCase());
if (o == null) return;
@@ -212,26 +222,24 @@
private final class IdentityOutputStream extends OutputStream {
private boolean closed = false;
public synchronized void write(int b) throws IOException {
- startWrite();
- p("write " + b);
+ commit();
//Thread.currentThread().dumpStack();
os.write(b);
}
public void write(byte ba[]) throws IOException {
- startWrite();
+ commit();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(ba);
- p("write " + baos);
//Thread.currentThread().dumpStack();
os.write(ba);
}
public void write(byte ba[],
int off,
int len) throws IOException {
- startWrite();
+ commit();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(ba);
- p("write " + baos + "[" + off + " " + len + "]");
+ //p("write " + baos + "[" + off + " " + len + "]");
//Thread.currentThread().dumpStack();
os.write(ba, off, len);
}
@@ -247,13 +255,6 @@
endCommit();
}
-
- private void startWrite() throws IOException {
- if (!hasBody) {
- commit();
- }
- hasBody = true;
- }
}
private static final class TextPlainWriter extends Writer {
@@ -293,6 +294,7 @@
private synchronized void commitFields() throws IOException {
//Thread.currentThread().dumpStack();
+ if (closed) throw new Error("AARGH!");
startCommit();
// general headers
commit("Cache-Control");
@@ -354,7 +356,10 @@
}
private void endCommit() {
- active.remove(os);
+ closed = true;
+ synchronized (active) {
+ active.remove(os);
+ }
}
private static HashMap active = new HashMap();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] storm/org/nongnu/storm/http HTTPSendableMessage...,
Benja Fallenstein <=