Move io related stuff in io.c
Add protocol negotiation, including compression, ssl pending