Backport evbuffer_readln(). This is necessary because it is not actually possible to use evbuffer_readline() safely: it will treat "A\r\n" as 'A' EOL if it reads it all at once, and as 'A' EOL EOL if there is a delay between reading the \r and the \n. Nicholas Marriott's comments on this patch: Gilles is too busy so I've had a go at this, please see the diff below. Rather than try to backport directly from 2.0 where the evbuffer code is quite different, I've backported the _readln function from when it was initially added in buffer.c r550. I can't see any relevant bug fixes after this point so the function is pretty much just copied in directly from that revision.