Fix race condition between closing usock and removing pipe

Added USOCK_SHUTDOWN event at which sent to owner, makes owner to stop the pipe and nn_sock_rm() it.

This patch is relies very much on the internals of the event processing in nn_ctx_leave() to deliver USOCK_SHUTDOWN before executing task_stop. If you're not ok with that, I can fix it, but it probably means I must add another state in every object that just ignores USOCK_SHUTDOWN event now.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Refactored sinproc shutdown code (fixes #31)

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
changed nn_chunk_addref parameter n from type int to more consistent type uint32_t

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>