[英]boost asio,how to cancel an asynchronous operation
我編寫了一個使用boost asio的代理服務程序,該代理服務器有兩個套接字(client_socket_,server_socket_),如果其中一個套接字被斷開,另一個套接字保持活動狀態。例如,如果從client_socket_讀取錯誤,我將關閉client_socket_,然后等待客戶端重新連接,客戶端重新連接后,我從一個套接字讀取並寫入另一個套接字。
問題是,當我關閉client_socket_時,如何取消server_socket_中的異步操作? 如果我不這樣做,客戶端連接后將執行以前的異步操作。 接下來是處理程序跟蹤,需要取消處理程序19。
E:\code\vdoctor-r\code\dnc\Debug>forwardserver.exe
@asio|1337591080.941830|0*1|socket@0012FA58.async_accept
@asio|1337591107.009440|>1|ec=system:0
@asio|1337591107.009440|1*2|strand@003E8340.dispatch
@asio|1337591107.009440|>2|
@asio|1337591107.009440|2*3|socket@0012FAB0.async_connect
@asio|1337591107.025059|2*4|socket@0012FA58.async_accept
@asio|1337591107.025059|<2|
@asio|1337591107.025059|<1|
@asio|1337591107.025059|>3|ec=system:0
@asio|1337591107.025059|3*5|strand@003E8340.dispatch
@asio|1337591107.025059|>5|
2012-May-21 17:05:07 [info]-[e:\code\vdoctor-r\code\dnc\forwardserver\forward_se
rver.cpp(114):forward_server::handle_connect_to_server] connect to server succes
sful, start to receive data from both sides
@asio|1337591107.040678|5*6|socket@003E83D4.async_receive
@asio|1337591107.040678|5*7|socket@0012FAB0.async_receive
@asio|1337591107.040678|<5|
@asio|1337591107.040678|<3|
@asio|1337591107.040678|>6|ec=system:0,bytes_transferred=20
@asio|1337591107.040678|6*8|strand@003E8340.dispatch
@asio|1337591107.040678|>8|
@asio|1337591107.040678|8*9|socket@003E83D4.async_receive
@asio|1337591107.040678|<8|
@asio|1337591107.040678|<6|
@asio|1337591107.040678|>9|ec=system:0,bytes_transferred=17
@asio|1337591107.040678|9*10|strand@003E8340.dispatch
@asio|1337591107.040678|>10|
@asio|1337591107.040678|10*11|socket@0012FAB0.async_send
@asio|1337591107.056296|<10|
@asio|1337591107.056296|<9|
@asio|1337591107.056296|>11|ec=system:0,bytes_transferred=37
@asio|1337591107.056296|11*12|strand@003E8340.dispatch
@asio|1337591107.056296|>12|
@asio|1337591107.056296|12*13|socket@003E83D4.async_receive
@asio|1337591107.056296|<12|
@asio|1337591107.056296|<11|
@asio|1337591107.071915|>7|ec=system:0,bytes_transferred=20
@asio|1337591107.071915|7*14|strand@003E8340.dispatch
@asio|1337591107.071915|>14|
@asio|1337591107.071915|14*15|socket@0012FAB0.async_receive
@asio|1337591107.071915|<14|
@asio|1337591107.071915|<7|
@asio|1337591107.071915|>15|ec=system:0,bytes_transferred=18
@asio|1337591107.071915|15*16|strand@003E8340.dispatch
@asio|1337591107.071915|>16|
@asio|1337591107.071915|16*17|socket@003E83D4.async_send
@asio|1337591107.071915|<16|
@asio|1337591107.071915|<15|
@asio|1337591107.087534|>17|ec=system:0,bytes_transferred=38
@asio|1337591107.087534|17*18|strand@003E8340.dispatch
@asio|1337591107.087534|>18|
@asio|1337591107.087534|18*19|socket@0012FAB0.async_receive
@asio|1337591107.087534|<18|
@asio|1337591107.087534|<17|
@asio|1337591107.884087|>13|ec=asio.misc:2,bytes_transferred=0
@asio|1337591107.884087|13*20|strand@003E8340.dispatch
@asio|1337591107.884087|>20|
2012-May-21 17:05:07 [error]-[e:\code\vdoctor-r\code\dnc\forwardserver\forward_s
erver.cpp(273):forward_server::handle_read_header_from_client] read header from
client error,End of file
@asio|1337591107.884087|20|socket@003E83D4.close
@asio|1337591107.884087|<20|
@asio|1337591107.884087|<13|
@asio|1337591222.813720|>4|ec=system:0
@asio|1337591222.813720|4*21|strand@003E8340.dispatch
@asio|1337591222.813720|>21|
@asio|1337591222.813720|21*22|socket@003ECF2C.async_receive
@asio|1337591222.813720|21*23|socket@0012FAB0.async_receive
@asio|1337591222.813720|21*24|socket@0012FA58.async_accept
@asio|1337591222.813720|<21|
@asio|1337591222.813720|<4|
@asio|1337591222.813720|>22|ec=system:0,bytes_transferred=20
@asio|1337591222.813720|22*25|strand@003E8340.dispatch
@asio|1337591222.813720|>25|
@asio|1337591222.813720|25*26|socket@003ECF2C.async_receive
@asio|1337591222.813720|<25|
@asio|1337591222.813720|<22|
@asio|1337591222.813720|>26|ec=system:0,bytes_transferred=17
@asio|1337591222.813720|26*27|strand@003E8340.dispatch
@asio|1337591222.813720|>27|
@asio|1337591222.813720|27*28|socket@0012FAB0.async_send
@asio|1337591222.813720|<27|
@asio|1337591222.813720|<26|
@asio|1337591222.813720|>28|ec=system:0,bytes_transferred=37
@asio|1337591222.813720|28*29|strand@003E8340.dispatch
@asio|1337591222.813720|>29|
@asio|1337591222.813720|29*30|socket@003ECF2C.async_receive
@asio|1337591222.813720|<29|
@asio|1337591222.813720|<28|
@asio|1337591222.813720|>19|ec=system:0,bytes_transferred=20
@asio|1337591222.813720|19*31|strand@003E8340.dispatch
@asio|1337591222.813720|>31|
@asio|1337591222.813720|31*32|socket@0012FAB0.async_receive
@asio|1337591222.813720|<31|
@asio|1337591222.813720|<19|
@asio|1337591222.813720|>23|ec=system:0,bytes_transferred=18
@asio|1337591222.813720|23*33|strand@003E8340.dispatch
@asio|1337591222.829340|>33|
@asio|1337591222.829340|33*34|socket@0012FAB0.async_receive
@asio|1337591222.829340|<33|
@asio|1337591222.829340|<23|
取消server_socket_上的async.operation的唯一可移植且可靠的方法是關閉它。 有關詳細信息,請參見以下鏈接 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.