Updated to explicitly use sigaction and BSD-style signal handlers, needed to properly deal with SIGPIPE when closing connections