Bug 1010748 - Detect that the socket closed.

This work around a hang (infinite loop) when b2g crashes.
Merge pull request #16 from hfiguiere/bug1010748

Bug 1010748 - Detect that the socket closed.