forked from cory/tildefriends
Time out connections that don't send a request in time.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3895 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
a8ced8757c
commit
ae894eaa9d
@ -4,6 +4,8 @@ var gHandlers = [];
|
|||||||
var gSocketHandlers = [];
|
var gSocketHandlers = [];
|
||||||
var gBadRequests = {};
|
var gBadRequests = {};
|
||||||
|
|
||||||
|
const kRequestTimeout = 15000;
|
||||||
|
|
||||||
function logError(error) {
|
function logError(error) {
|
||||||
print("ERROR " + error);
|
print("ERROR " + error);
|
||||||
if (error.stackTrace) {
|
if (error.stackTrace) {
|
||||||
@ -394,6 +396,17 @@ function handleConnection(client) {
|
|||||||
var lineByLine = true;
|
var lineByLine = true;
|
||||||
var bodyToRead = -1;
|
var bodyToRead = -1;
|
||||||
var body;
|
var body;
|
||||||
|
var requestCount = -1;
|
||||||
|
|
||||||
|
function resetTimeout(requestIndex) {
|
||||||
|
setTimeout(function() {
|
||||||
|
if (bodyToRead == -1 && requestCount == requestIndex) {
|
||||||
|
badRequest(client, 'Timed out waiting for request.');
|
||||||
|
}
|
||||||
|
}, kRequestTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
resetTimeout(++requestCount);
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
inputBuffer = new Uint8Array(0);
|
inputBuffer = new Uint8Array(0);
|
||||||
@ -402,6 +415,7 @@ function handleConnection(client) {
|
|||||||
lineByLine = true;
|
lineByLine = true;
|
||||||
bodyToRead = -1;
|
bodyToRead = -1;
|
||||||
body = undefined;
|
body = undefined;
|
||||||
|
resetTimeout(++requestCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function finish() {
|
function finish() {
|
||||||
|
Loading…
Reference in New Issue
Block a user