Cherry-picking from TTimo/nanomsg 0.4-beta tag (https://github.com/TTimo/nanomsg)
Adding more stderr and stdout debug messages to test