libwebsockets new features

March 6, 2011

More platforms

In addition to Linux, there are now users of libwebsockets on win32, OSX and iOS that have contributed patches now in git at http://git.warmcat.com/cgi-bin/cgit/libwebsockets OSX wasn't too hard thanks to some patches from Darin Willits, win32 was a bit tougher despite a big patch from Peter Hinz, I was really surprised to find the the Microsoft compiler doesn't support simple C99 features like named member initialization of structs. Anyway after dumbing down the few structs that used it, and adapting a few other things it's now possible to use libwebsockets on win32 thanks to Peter's work.

v05 and v06 protocol support

Both v05 and v06 support was added within 12 hours of the spec being released, at the time of writing v06 is the current version. I also added v00 client support by request from a developer using the socket.io server library which doesn't support anything except 76 / 00. That means that in libwebsockets, both server and client support now covers all combinations of v00. v04, v05 and v06.

Extensions and deflate-stream

There's a new extension support infrastructure added, including an implementation of zlib compression to provide the standardized "deflate-stream" extension. The benefit of running with compression depends a lot on the payload size and content; in order to reduce latency the compression buffers are partially flushed every frame. But it is an important part of the websockets standard that libwebsockets now supports.

Integration with external poll arrays

Libwebsockets is being integrated into a fork of ircd, the daemon which runs the IRC network. The challenge there is to interoperate will the existing single poll() loop in a way that maximizes blocking and maintains serialization of poll service in a single thread to avoid the need for locking. In addition to its default private poll array management libwebsockets now provides poll array callbacks into the user code which enables integration of websocket event loop functionality into an existing, master poll() array. Callbacks occur into user code when file descriptors must be added, removed or have their event masks changed. There are hash tables implemented in libwebsockets to allow everything to remain opaque to the host code using just the file descriptor as an index. With this technique, it has been possible to integrate websocket functionality into an existing irc server while keeping all details about websocket functionality and protocol versioning in the library.