Echoing close frame; Closing client connection

Still not perfect as following calls to recv() and epoll_ctl() fail with entry in error log.
But according to http://tools.ietf.org/html/rfc6455#section-7 the server should close the connection.
What is the correct way?