mirror of https://github.com/adamdruppe/arsd.git
more relaibility under crappy connections
This commit is contained in:
parent
fcb59c4c55
commit
c8c61150d5
16
cgi.d
16
cgi.d
|
@ -2649,8 +2649,12 @@ mixin template CustomCgiMainImpl(CustomCgi, alias fun, long maxContentLength = d
|
||||||
i = addr.sizeof;
|
i = addr.sizeof;
|
||||||
int s = accept(sock, &addr, &i);
|
int s = accept(sock, &addr, &i);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
if(s == -1)
|
if(s == -1)
|
||||||
throw new Exception("accept");
|
throw new Exception("accept");
|
||||||
|
|
||||||
|
scope(failure) close(s);
|
||||||
//ubyte[__traits(classInstanceSize, BufferedInputRange)] bufferedRangeContainer;
|
//ubyte[__traits(classInstanceSize, BufferedInputRange)] bufferedRangeContainer;
|
||||||
auto ir = new BufferedInputRange(s);
|
auto ir = new BufferedInputRange(s);
|
||||||
//auto ir = emplace!BufferedInputRange(bufferedRangeContainer, s, backingBuffer);
|
//auto ir = emplace!BufferedInputRange(bufferedRangeContainer, s, backingBuffer);
|
||||||
|
@ -2699,6 +2703,10 @@ mixin template CustomCgiMainImpl(CustomCgi, alias fun, long maxContentLength = d
|
||||||
}
|
}
|
||||||
|
|
||||||
ir.source.close();
|
ir.source.close();
|
||||||
|
} catch(Throwable t) {
|
||||||
|
debug writeln(t);
|
||||||
|
// most likely cause is a timeout
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
processCount++;
|
processCount++;
|
||||||
|
@ -3138,6 +3146,9 @@ class BufferedInputRange {
|
||||||
}
|
}
|
||||||
|
|
||||||
this(Socket source, ubyte[] buffer = null) {
|
this(Socket source, ubyte[] buffer = null) {
|
||||||
|
// if they connect but never send stuff to us, we don't want it wasting the process
|
||||||
|
// so setting a time out
|
||||||
|
source.setOption(SocketOptionLevel.SOCKET, SocketOption.RCVTIMEO, dur!"seconds"(3));
|
||||||
this.source = source;
|
this.source = source;
|
||||||
if(buffer is null) {
|
if(buffer is null) {
|
||||||
underlyingBuffer = new ubyte[4096];
|
underlyingBuffer = new ubyte[4096];
|
||||||
|
@ -3194,10 +3205,11 @@ class BufferedInputRange {
|
||||||
if(ret == Socket.ERROR) {
|
if(ret == Socket.ERROR) {
|
||||||
version(Posix) {
|
version(Posix) {
|
||||||
import core.stdc.errno;
|
import core.stdc.errno;
|
||||||
if(errno == EINTR)
|
if(errno == EINTR) {
|
||||||
goto try_again;
|
goto try_again;
|
||||||
}
|
}
|
||||||
throw new Exception("uh oh " ~ lastSocketError); // FIXME
|
}
|
||||||
|
throw new Exception(lastSocketError); // FIXME
|
||||||
}
|
}
|
||||||
if(ret == 0) {
|
if(ret == 0) {
|
||||||
sourceClosed = true;
|
sourceClosed = true;
|
||||||
|
|
Loading…
Reference in New Issue