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 gBadRequests = {};
|
||||
|
||||
const kRequestTimeout = 15000;
|
||||
|
||||
function logError(error) {
|
||||
print("ERROR " + error);
|
||||
if (error.stackTrace) {
|
||||
@ -394,6 +396,17 @@ function handleConnection(client) {
|
||||
var lineByLine = true;
|
||||
var bodyToRead = -1;
|
||||
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() {
|
||||
inputBuffer = new Uint8Array(0);
|
||||
@ -402,6 +415,7 @@ function handleConnection(client) {
|
||||
lineByLine = true;
|
||||
bodyToRead = -1;
|
||||
body = undefined;
|
||||
resetTimeout(++requestCount);
|
||||
}
|
||||
|
||||
function finish() {
|
||||
|
Loading…
Reference in New Issue
Block a user