The fixes for broken pipe and get the status in lua side when connect event happens

I created an issue about broken pipe, I came out one solution for me.  But the solution is bad, so please help to review and get one good solution.

The status code may needed for handling the event correctly.