- Make short timeouts for UPnP HTTP POST so we don't hang when
the UPnP device goes away - Fix a bug in UPnP HTTP Server, but we don't use it anyway
This commit is contained in:
@ -52,6 +52,8 @@ package org.cybergarage.http;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.cybergarage.util.Debug;
|
||||||
|
|
||||||
public class HTTPRequest extends HTTPPacket
|
public class HTTPRequest extends HTTPPacket
|
||||||
{
|
{
|
||||||
@ -378,9 +380,21 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (postSocket == null)
|
if (postSocket == null) {
|
||||||
postSocket = new Socket(host, port);
|
// Mod for I2P
|
||||||
|
// We can't handle the default system soTimeout of 3 minutes or so
|
||||||
|
// as when the device goes away, this hangs the display of peers.jsp
|
||||||
|
// and who knows what else.
|
||||||
|
// Set the timeout to be nice and short, the device should be local and fast.
|
||||||
|
// If he can't get back to us in 2 seconds, forget it.
|
||||||
|
// And set the soTimeout to 1 second (for reads).
|
||||||
|
//postSocket = new Socket(host, port);
|
||||||
|
postSocket = new Socket();
|
||||||
|
postSocket.setSoTimeout(1000);
|
||||||
|
SocketAddress sa = new InetSocketAddress(host, port);
|
||||||
|
postSocket.connect(sa, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
out = postSocket.getOutputStream();
|
out = postSocket.getOutputStream();
|
||||||
PrintStream pout = new PrintStream(out);
|
PrintStream pout = new PrintStream(out);
|
||||||
pout.print(getHeader());
|
pout.print(getHeader());
|
||||||
@ -416,6 +430,8 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR);
|
httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
// I2P addition
|
||||||
|
Debug.warning(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (isKeepAlive == false) {
|
if (isKeepAlive == false) {
|
||||||
try {
|
try {
|
||||||
|
@ -119,7 +119,7 @@ public class HTTPServer implements Runnable
|
|||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
Socket sock = serverSock.accept();
|
Socket sock = serverSock.accept();
|
||||||
sock.setSoTimeout(HTTP.DEFAULT_PORT * 1000);
|
sock.setSoTimeout(HTTP.DEFAULT_TIMEOUT * 1000);
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
Reference in New Issue
Block a user