WebSocket close will automatically drain (API Change):

fix #642

* Calls to stream::close and stream::async_close will
  automatically perform the required read operations

Actions Required:

* Remove calling code which drains the connection after
  calling stream::close or stream::async_close
This commit is contained in:
Vinnie Falco
2017-08-04 19:02:13 -07:00
parent dc6a08d10a
commit 64327739f0
14 changed files with 1233 additions and 898 deletions
@@ -90,7 +90,7 @@ int main()
if(ec)
return fail("read", ec);
// Send a "close" frame to the other end, this is a websocket thing
// Close the WebSocket connection
ws.close(websocket::close_code::normal, ec);
if(ec)
return fail("close", ec);
@@ -98,24 +98,5 @@ int main()
// The buffers() function helps print a ConstBufferSequence
std::cout << boost::beast::buffers(b.data()) << std::endl;
// WebSocket says that to close a connection you have
// to keep reading messages until you receive a close frame.
// Beast delivers the close frame as an error from read.
//
boost::beast::drain_buffer drain; // Throws everything away efficiently
for(;;)
{
// Keep reading messages...
ws.read(drain, ec);
// ...until we get the special error code
if(ec == websocket::error::closed)
break;
// Some other error occurred, report it and exit.
if(ec)
return fail("close", ec);
}
return EXIT_SUCCESS;
}