One of the decisions I took early on while writing Lwan was to only support Linux, and think about portability later; this decision was influenced by the way the OpenBSD project approaches portability. Published June, 28, 2018
A pretty common mistake that happens when programming things in C is to allocate less memory than necessary to hold a structure: Published May, 01, 2015
I've been thinking for a while on how to reduce the overhead in Lwan's string buffer, when the strings are small. There are a number of ways of accomplishing this. Published November, 02, 2014
When learning a new programming language, I tend to write two things with it: a language interpreter (usually a FORTH-like language or Brainfuck if I'm feeling lazy), and a HTTP server. Sometimes, just as a challenge or a way to quench my boredom, I do… Published October, 06, 2014
There are various ways to convert integers to their string representation. These conversions are rarely a bottleneck, but they often show up while profiling certain applications. For instance, they're very common in Lwan while building the response… Published June, 23, 2014
When I wrote about lwan's templating engine on a blog post last year, I purposedly ommitted the fact that it didn't support sequences. Took me almost a year, but I've finally implemented it this week. (Lwan is usually a low priority weekend project. Maybe… Published September, 26, 2013
There are some functions in the standard C library that takes a function pointer to be used as a callback later on. Examples include atexit() and signal(). However, these functions can't receive an arbitrary pointer (which could hold some important… Published July, 20, 2013
Generating textual output is a lot easier with templates than it is with handcrafted functions. And it is a lot easier in languages such as Python, where things like introspection are easy and cheap. But that doesn’t necessarily mean we can’t do that in C… Published November, 11, 2012
Previously, I’ve improved file serving performance in lwan by dramatially cutting down on the number of system calls performed to serve a file. However, for small files (< 16KiB), the throughput drop from the hello handler (which merely responds “Hello,… Published October, 14, 2012
Writing asynchronous I/O code in C is kind of tedious, and often leads to a callback hell. But it doesn’t have to be this way; if you have a main loop, it’s quite simple to use coroutines and write code in a soothing, old school, synchronous way. Published September, 29, 2012
When I first wrote lwan, file serving was not a primary goal. I’ve added this capability later, never giving much thought to the number of system calls required to serve one file. As a result, static file serving was quite slow compared to “hello world”… Published August, 12, 2012
Golang has a lot of nice features – and one I found pretty interesting is called deferred statements. This can be implemented in C++ pretty easily through RAII, but in C we’re pretty much out of luck. Or are we? Published August, 11, 2012
C’s switch statement is very powerful. However, it can’t be used with strings, only with constant integral types. This is understandable, since strings in C are merely arrays – they’re not first-class citizens. Published August, 09, 2012