mirror of https://github.com/adamdruppe/arsd.git
handle some disconnects more gracefully
This commit is contained in:
parent
c20375a8df
commit
43fb4119f4
12
cgi.d
12
cgi.d
|
@ -4116,6 +4116,9 @@ void doThreadHttpConnectionGuts(CustomCgi, alias fun, bool alwaysCloseConnection
|
||||||
try {
|
try {
|
||||||
cgi = new CustomCgi(ir, &closeConnection);
|
cgi = new CustomCgi(ir, &closeConnection);
|
||||||
cgi._outputFileHandle = connection.handle;
|
cgi._outputFileHandle = connection.handle;
|
||||||
|
} catch(ConnectionClosedException ce) {
|
||||||
|
closeConnection = true;
|
||||||
|
break;
|
||||||
} catch(ConnectionException ce) {
|
} catch(ConnectionException ce) {
|
||||||
// broken pipe or something, just abort the connection
|
// broken pipe or something, just abort the connection
|
||||||
closeConnection = true;
|
closeConnection = true;
|
||||||
|
@ -4145,6 +4148,9 @@ void doThreadHttpConnectionGuts(CustomCgi, alias fun, bool alwaysCloseConnection
|
||||||
} catch(ConnectionException ce) {
|
} catch(ConnectionException ce) {
|
||||||
// broken pipe or something, just abort the connection
|
// broken pipe or something, just abort the connection
|
||||||
closeConnection = true;
|
closeConnection = true;
|
||||||
|
} catch(ConnectionClosedException ce) {
|
||||||
|
// broken pipe or something, just abort the connection
|
||||||
|
closeConnection = true;
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
// a processing error can be recovered from
|
// a processing error can be recovered from
|
||||||
version(CRuntime_Musl) {} else
|
version(CRuntime_Musl) {} else
|
||||||
|
@ -4154,6 +4160,7 @@ void doThreadHttpConnectionGuts(CustomCgi, alias fun, bool alwaysCloseConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
if(closeConnection || alwaysCloseConnection) {
|
if(closeConnection || alwaysCloseConnection) {
|
||||||
|
connection.shutdown(SocketShutdown.BOTH);
|
||||||
connection.close();
|
connection.close();
|
||||||
ir.dispose();
|
ir.dispose();
|
||||||
closeConnection = false; // don't reclose after loop
|
closeConnection = false; // don't reclose after loop
|
||||||
|
@ -4162,6 +4169,7 @@ void doThreadHttpConnectionGuts(CustomCgi, alias fun, bool alwaysCloseConnection
|
||||||
if(ir.front.length) {
|
if(ir.front.length) {
|
||||||
ir.popFront(); // we can't just discard the buffer, so get the next bit and keep chugging along
|
ir.popFront(); // we can't just discard the buffer, so get the next bit and keep chugging along
|
||||||
} else if(ir.sourceClosed) {
|
} else if(ir.sourceClosed) {
|
||||||
|
ir.source.shutdown(SocketShutdown.BOTH);
|
||||||
ir.source.close();
|
ir.source.close();
|
||||||
ir.dispose();
|
ir.dispose();
|
||||||
closeConnection = false;
|
closeConnection = false;
|
||||||
|
@ -4173,6 +4181,7 @@ void doThreadHttpConnectionGuts(CustomCgi, alias fun, bool alwaysCloseConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
if(closeConnection) {
|
if(closeConnection) {
|
||||||
|
connection.shutdown(SocketShutdown.BOTH);
|
||||||
connection.close();
|
connection.close();
|
||||||
ir.dispose();
|
ir.dispose();
|
||||||
}
|
}
|
||||||
|
@ -4989,6 +4998,9 @@ class ConnectionThread : Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+/
|
+/
|
||||||
|
} catch(ConnectionClosedException e) {
|
||||||
|
// can just ignore this, it is fairly normal
|
||||||
|
socket.close();
|
||||||
} catch(Throwable e) {
|
} catch(Throwable e) {
|
||||||
import std.stdio; stderr.rawWrite(e.toString); stderr.rawWrite("\n");
|
import std.stdio; stderr.rawWrite(e.toString); stderr.rawWrite("\n");
|
||||||
socket.close();
|
socket.close();
|
||||||
|
|
Loading…
Reference in New Issue