Fix assorted bugs and return packet kind (#8) * add connection state * improve error handling * fix segmentation fault while attempting to close closed socket * implement auto-close * remove gcsafe requirement from onAutoClose callback * remove auto-close * return packet kind * remove auto-close unit test * make interface more consistent * omit double copy