forked from I2P_Developers/i2p.i2p
* i2ptunnel: Reduce buffer size and use cache in HTTPServer
* Jetty: Increase maxIdleTime
This commit is contained in:
@@ -21,7 +21,9 @@ import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import net.i2p.client.streaming.I2PSocket;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.ByteCache;
|
||||
import net.i2p.util.EventDispatcher;
|
||||
import net.i2p.util.I2PAppThread;
|
||||
import net.i2p.util.Log;
|
||||
@@ -221,7 +223,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
|
||||
// shadows _log in super()
|
||||
private final Log _log;
|
||||
|
||||
private static final int BUF_SIZE = 16*1024;
|
||||
private static final int BUF_SIZE = 8*1024;
|
||||
|
||||
public CompressedRequestor(Socket webserver, I2PSocket browser, String headers, I2PAppContext ctx, Log log) {
|
||||
_webserver = webserver;
|
||||
@@ -245,6 +247,9 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
|
||||
_log.info("request headers: " + _headers);
|
||||
serverout.write(_headers.getBytes());
|
||||
browserin = _browser.getInputStream();
|
||||
// TODO don't spin off a thread for this except for POSTs
|
||||
// beware interference with Tahoe-LAFS, Shoutcast, etc.?
|
||||
// if (browserin.available() == 0) ?
|
||||
I2PAppThread sender = new I2PAppThread(new Sender(serverout, browserin, "server: browser to server", _log), Thread.currentThread().getName() + "hcs");
|
||||
sender.start();
|
||||
|
||||
@@ -300,6 +305,8 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
|
||||
private final String _name;
|
||||
// shadows _log in super()
|
||||
private final Log _log;
|
||||
private static final int BUF_SIZE = 8*1024;
|
||||
private static final ByteCache _cache = ByteCache.getInstance(16, BUF_SIZE);
|
||||
|
||||
public Sender(OutputStream out, InputStream in, String name, Log log) {
|
||||
_out = out;
|
||||
@@ -311,10 +318,11 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
|
||||
public void run() {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info(_name + ": Begin sending");
|
||||
ByteArray ba = _cache.acquire();
|
||||
try {
|
||||
byte buf[] = new byte[16*1024];
|
||||
byte buf[] = ba.getData();
|
||||
int read = 0;
|
||||
int total = 0;
|
||||
long total = 0;
|
||||
while ( (read = _in.read(buf)) != -1) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info(_name + ": read " + read + " and sending through the stream");
|
||||
@@ -328,6 +336,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Error sending", ioe);
|
||||
} finally {
|
||||
_cache.release(ba);
|
||||
if (_out != null) try { _out.close(); } catch (IOException ioe) {}
|
||||
if (_in != null) try { _in.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user