fukamachi / woo

A fast non-blocking HTTP server on top of libev
http://ultra.wikia.com/wiki/Woo_(kaiju)
MIT License
1.27k stars 96 forks source link

Socket output buffer not allocated static & null errno values on LispWorks. #110

Closed julian-baldwin closed 7 months ago

julian-baldwin commented 7 months ago

These are the two fixes required to get Woo running on LispWorks.

Firstly, the output buffer obtained from finish-output-buffer in woo.ev.socket:flush-buffer is not allocated in a static segment, which is required for the LispWorks FLI to pin the array during the subsequent cffi:with-pointer-to-vector-data form. This results in a '#(...) cannot be converted to foreign type "Statically allocated or pinned (LISP-ARRAY NIL)"' error when sending a response. The fix is to use (make-output-buffer :output :static) when initialising the buffer in the socket structure definition.

Woo also doesn't know how to get errno values on LispWorks. This results in random failures trying to compare numeric constants with nil in event loop callbacks. The fix is to add a call to lw:errno-value to the definition in syscall/main.lisp.

With these two fixes Woo loads and runs on LispWorks 8.01 (Intel macOS 13.6.1) and has no problems with a benchmark using wrk or a browser. I have a commit julian-baldwin/woo@81e6ae2 that fixes both of these and permits the server to run, which I am happy to submit as a PR. There is also another (more serious) issue where Woo interferes with LispWorks' signal handling I'll report separately, but this is the bare minimum required to get it to serve requests.

fukamachi commented 7 months ago

Sounds good unless anything doesn't affect other systems. I'm waiting for your PR. It must be hard to investigate, huh? Thank you for your effort.

julian-baldwin commented 7 months ago

Done. I've also added support for LispWorks' file-size to avoid opening files to get their length as an additional obvious optimisation. I've written quite a bit of LispWorks FLI code in my main projects, so have seen this problem plenty of times before, but I spent a bit of time looking through fast-io's code to find exactly where that buffer gets allocated and how to make it static.