Fix closing handshake and loss of received data

Fix #419 by supporting closing handshake properly.

http://tools.ietf.org/html/rfc6455#section-1.4