Sandra Schreiner
2016-02-03 13:22:27 UTC
Hello,
I really would like to close the connection between client and server and reopen it afterwards. After I tried out various approaches, it seems i can't get a proper solution without any error message to work.
Beside different other solutions I tried checked out this post http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error and tested the following variations of the accepted answer:
A) PartyA initiates shutdown() and waits for PartyB to respond with a shutdown()
B) PartyA initiates shutdown() but does not wait for PartyB to respond
In case (A), if I use shutdown on client and session side, I get the mentioned EoF error. But without any possibility to fetch the error, because the only available socket.shutdown() does have void as return value and does not take any parameters. Im using asio standalone version 1.10.6.
In case (B) the callback for the write operation is never called. Therefore the program just hangs.
Server accept start
Server accept success
Session start
Server accept start
Client connect success
Session handshake success
Client handshake success
Client initiateDisconnect enter
Session Read failed
Session shutdown
The code is the following (in first run I would like to cancel the connection by client):
Client (io_service is used with asio::work)
---------------------------------------------
void close(const asio::error_code &err){
std::cout << "Client close enter" << "\n";
}
void initiateDisconnect(){
std::cout << "Client initiateDisconnect enter" << "\n";
socket_.async_shutdown(std::bind(&client::close, this, std::placeholders::_1));
std::string dummy = "s";
asio::async_write(socket_,
asio::buffer(dummy, dummy.size()),
std::bind(&client::handle_write, this,
std::placeholders::_1,
std::placeholders::_2));
}
void handle_write(const asio::error_code& error, size_t bytes_transferred){
std::cout << "Client handle_write";
//... check error
}
Session (waits in handle_read)
---------------------
void handleShutdown(){
if(!isDown){
std::cout << " Session shutdown "<< "\n";
socket_.shutdown();
isDown = true;
delete this;
}
}
void handle_read(const asio::error_code& error,
size_t bytes_transferred) {
if (!error) {
std::cout << " Session Read success "<< "\n";
asio::async_write(socket_,
asio::buffer(data_, bytes_transferred),
std::bind(&session::handle_write, this,
std::placeholders::_1));
}
else {
std::cout << " Session Read failed "<< "\n";
handleShutdown();
}
}
How is a proper connection close done?
Many thanks for any help in advance,
Best regards
Sandra
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
I really would like to close the connection between client and server and reopen it afterwards. After I tried out various approaches, it seems i can't get a proper solution without any error message to work.
Beside different other solutions I tried checked out this post http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error and tested the following variations of the accepted answer:
A) PartyA initiates shutdown() and waits for PartyB to respond with a shutdown()
B) PartyA initiates shutdown() but does not wait for PartyB to respond
In case (A), if I use shutdown on client and session side, I get the mentioned EoF error. But without any possibility to fetch the error, because the only available socket.shutdown() does have void as return value and does not take any parameters. Im using asio standalone version 1.10.6.
In case (B) the callback for the write operation is never called. Therefore the program just hangs.
Server accept start
Server accept success
Session start
Server accept start
Client connect success
Session handshake success
Client handshake success
Client initiateDisconnect enter
Session Read failed
Session shutdown
The code is the following (in first run I would like to cancel the connection by client):
Client (io_service is used with asio::work)
---------------------------------------------
void close(const asio::error_code &err){
std::cout << "Client close enter" << "\n";
}
void initiateDisconnect(){
std::cout << "Client initiateDisconnect enter" << "\n";
socket_.async_shutdown(std::bind(&client::close, this, std::placeholders::_1));
std::string dummy = "s";
asio::async_write(socket_,
asio::buffer(dummy, dummy.size()),
std::bind(&client::handle_write, this,
std::placeholders::_1,
std::placeholders::_2));
}
void handle_write(const asio::error_code& error, size_t bytes_transferred){
std::cout << "Client handle_write";
//... check error
}
Session (waits in handle_read)
---------------------
void handleShutdown(){
if(!isDown){
std::cout << " Session shutdown "<< "\n";
socket_.shutdown();
isDown = true;
delete this;
}
}
void handle_read(const asio::error_code& error,
size_t bytes_transferred) {
if (!error) {
std::cout << " Session Read success "<< "\n";
asio::async_write(socket_,
asio::buffer(data_, bytes_transferred),
std::bind(&session::handle_write, this,
std::placeholders::_1));
}
else {
std::cout << " Session Read failed "<< "\n";
handleShutdown();
}
}
How is a proper connection close done?
Many thanks for any help in advance,
Best regards
Sandra
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio