Increase line buffer space in examples and add explicit error message.

This commit is contained in:
Sönke Ludwig 2016-10-05 12:40:28 +02:00
parent 8b2c178651
commit b1663cc472
2 changed files with 4 additions and 2 deletions

View file

@ -150,6 +150,7 @@ struct StreamConnectionImpl {
auto idx = m_readBuffer[0 .. m_readBufferFill].countUntil(cast(const(ubyte)[])"\r\n");
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];
foreach (i; 0 .. m_readBufferFill - idx - 2)
m_readBuffer[i] = m_readBuffer[idx+2+i];
@ -204,7 +205,7 @@ struct ClientHandler {
void handleConnection()
@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 conn = StreamConnection(client, linebuf);

View file

@ -31,7 +31,7 @@ struct ClientHandler {
alias LineCallback = void delegate(ubyte[]);
StreamSocketFD client;
ubyte[512] linebuf = void;
ubyte[1024] linebuf = void;
size_t linefill = 0;
LineCallback onLine;
@ -94,6 +94,7 @@ struct ClientHandler {
auto idx = linebuf[0 .. linefill].countUntil(cast(const(ubyte)[])"\r\n");
if (idx >= 0) {
assert(linefill + idx <= linebuf.length, "Not enough space to buffer the incoming line.");
linebuf[linefill .. linefill + idx] = linebuf[0 .. idx];
foreach (i; 0 .. linefill - idx - 2)
linebuf[i] = linebuf[idx+2+i];