Increase line buffer space in examples and add explicit error message.
This commit is contained in:
parent
8b2c178651
commit
b1663cc472
|
@ -150,6 +150,7 @@ struct StreamConnectionImpl {
|
||||||
|
|
||||||
auto idx = m_readBuffer[0 .. m_readBufferFill].countUntil(cast(const(ubyte)[])"\r\n");
|
auto idx = m_readBuffer[0 .. m_readBufferFill].countUntil(cast(const(ubyte)[])"\r\n");
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
|
assert(m_readBufferFill + idx <= m_readBuffer.length, "Not enough space to buffer the incoming line.");
|
||||||
m_readBuffer[m_readBufferFill .. m_readBufferFill + idx] = m_readBuffer[0 .. idx];
|
m_readBuffer[m_readBufferFill .. m_readBufferFill + idx] = m_readBuffer[0 .. idx];
|
||||||
foreach (i; 0 .. m_readBufferFill - idx - 2)
|
foreach (i; 0 .. m_readBufferFill - idx - 2)
|
||||||
m_readBuffer[i] = m_readBuffer[idx+2+i];
|
m_readBuffer[i] = m_readBuffer[idx+2+i];
|
||||||
|
@ -204,7 +205,7 @@ struct ClientHandler {
|
||||||
|
|
||||||
void handleConnection()
|
void handleConnection()
|
||||||
@trusted {
|
@trusted {
|
||||||
ubyte[512] linebuf = void;
|
ubyte[1024] linebuf = void;
|
||||||
auto reply = cast(const(ubyte)[])"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 13\r\nKeep-Alive: timeout=10\r\n\r\nHello, World!";
|
auto reply = cast(const(ubyte)[])"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 13\r\nKeep-Alive: timeout=10\r\n\r\nHello, World!";
|
||||||
|
|
||||||
auto conn = StreamConnection(client, linebuf);
|
auto conn = StreamConnection(client, linebuf);
|
||||||
|
|
|
@ -31,7 +31,7 @@ struct ClientHandler {
|
||||||
alias LineCallback = void delegate(ubyte[]);
|
alias LineCallback = void delegate(ubyte[]);
|
||||||
|
|
||||||
StreamSocketFD client;
|
StreamSocketFD client;
|
||||||
ubyte[512] linebuf = void;
|
ubyte[1024] linebuf = void;
|
||||||
size_t linefill = 0;
|
size_t linefill = 0;
|
||||||
LineCallback onLine;
|
LineCallback onLine;
|
||||||
|
|
||||||
|
@ -94,6 +94,7 @@ struct ClientHandler {
|
||||||
|
|
||||||
auto idx = linebuf[0 .. linefill].countUntil(cast(const(ubyte)[])"\r\n");
|
auto idx = linebuf[0 .. linefill].countUntil(cast(const(ubyte)[])"\r\n");
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
|
assert(linefill + idx <= linebuf.length, "Not enough space to buffer the incoming line.");
|
||||||
linebuf[linefill .. linefill + idx] = linebuf[0 .. idx];
|
linebuf[linefill .. linefill + idx] = linebuf[0 .. idx];
|
||||||
foreach (i; 0 .. linefill - idx - 2)
|
foreach (i; 0 .. linefill - idx - 2)
|
||||||
linebuf[i] = linebuf[idx+2+i];
|
linebuf[i] = linebuf[idx+2+i];
|
||||||
|
|
Loading…
Reference in a new issue