Fixes to address bnoordhuis comments

- Fix poll events handling
- Only emit connect when necessary
- A couple of style fixes
Only check errno if sendmsg returned -1
Add connect test
Update test script