简体   繁体   English

boost :: asio :: ip :: tcp :: socket :: cancel和socket :: close之间有什么区别

[英]what is different between boost::asio::ip::tcp::socket::cancel and socket::close

According to boost documentation, when socket::close() is invoked, asynchronous send, receive or connect operations will be cancelled immediately, and will complete with the boost::asio::error::operation_aborted error. 根据boost文档,当调用socket::close() ,异步发送,接收或连接操作将立即被取消,并完成boost::asio::error::operation_aborted错误。

socket::cancel causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the boost::asio::error::operation_aborted error. socket::cancel会使所有未完成的异步连接,发送和接收操作立即完成,并且取消操作的处理程序将传递给boost::asio::error::operation_aborted错误。

Is there some difference between them? 它们之间有区别吗?

When I want to finish one socket connection, which one should I call such that their callback handler will be invoked with boost::asio::error::operation_aborted error? 当我想完成一个套接字连接时,应该调用哪个套接字连接,以便使用boost::asio::error::operation_aborted错误调用它们的回调处理程序?

Is there some difference between them? 它们之间有区别吗?

Yes. 是。 The close() method closes the socket, while the cancel() method cancels outstanding asynchonous operations. close()方法关闭套接字,而cancel()方法取消未完成的异步操作。 Using cancel() does not close the socket. 使用cancel()不会关闭套接字。

When I want to finish one socket connection, which one I should to call? 当我想完成一个套接字连接时,应该给哪一个打电话?

You should use cancel() to stop any outstanding asynchronous operations. 您应该使用cancel()停止任何未完成的异步操作。 The socket will be closed by its destructor. 套接字将被其析构函数关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM