asio的事件投递主要由aico完成,除了accept只需要一次投递,永久有效外,其他事件投递都是一次性的,每次投递后,回调处理完,根据返回的状态,来判断是否需要继续投递。

    1. /*! init the aico
    2. *
    3. * @param aicp the aicp
    4. *
    5. * @return the aico
    6. */
    7. tb_aico_ref_t tb_aico_init(tb_aicp_ref_t aicp);
    8.  
    9. /*! open the sock aico
    10. *
    11. * @param aicp the aicp
    12. * @param sock the socket
    13. *
    14. * @return tb_true or tb_false
    15. */
    16. tb_bool_t tb_aico_open_sock(tb_aico_ref_t aico, tb_socket_ref_t sock);
    17.  
    18. /*! open the sock aico from the socket type
    19. *
    20. * @param aicp the aicp
    21. * @param type the socket type
    22. *
    23. * @return tb_true or tb_false
    24. */
    25. tb_bool_t tb_aico_open_sock_from_type(tb_aico_ref_t aico, tb_size_t type);
    26.  
    27. /*! open the file aico
    28. *
    29. * @param aicp the aicp
    30. * @param file the file
    31. *
    32. * @return tb_true or tb_false
    33. */
    34. tb_bool_t tb_aico_open_file(tb_aico_ref_t aico, tb_file_ref_t file);
    35.  
    36. /*! open the file aico from path
    37. *
    38. * @param aicp the aicp
    39. * @param path the file path
    40. * @param mode the file mode
    41. *
    42. * @return tb_true or tb_false
    43. */
    44. tb_bool_t tb_aico_open_file_from_path(tb_aico_ref_t aico, tb_char_t const* path, tb_size_t mode);
    45.  
    46. /*! open the task aico
    47. *
    48. * @param aicp the aicp
    49. * @param ltimer is the lower precision timer?
    50. *
    51. * @return tb_true or tb_false
    52. */
    53. tb_bool_t tb_aico_open_task(tb_aico_ref_t aico, tb_bool_t ltimer);
    54.  
    55. /*! kill the aico
    56. *
    57. * @param aico the aico
    58. */
    59. tb_void_t tb_aico_kill(tb_aico_ref_t aico);
    60.  
    61. /*! exit the aico
    62. *
    63. * @param aico the aico
    64. */
    65. tb_void_t tb_aico_exit(tb_aico_ref_t aico);
    66.  
    67. /*! the aico aicp
    68. *
    69. * @param aico the aico
    70. *
    71. * @return the aico aicp
    72. */
    73. tb_aicp_ref_t tb_aico_aicp(tb_aico_ref_t aico);
    74.  
    75. /*! the aico type
    76. *
    77. * @param aico the aico
    78. *
    79. * @return the aico type
    80. */
    81. tb_size_t tb_aico_type(tb_aico_ref_t aico);
    82.  
    83. /*! get the socket if the aico is socket type
    84. *
    85. * @param aico the aico
    86. *
    87. * @return the socket
    88. */
    89. tb_socket_ref_t tb_aico_sock(tb_aico_ref_t aico);
    90.  
    91. /*! get the file if the aico is file type
    92. *
    93. * @param aico the aico
    94. *
    95. * @return the file
    96. */
    97. tb_file_ref_t tb_aico_file(tb_aico_ref_t aico);
    98.  
    99. /*! try to close it
    100. *
    101. * @param aico the aico
    102. *
    103. * @return tb_true or tb_false
    104. */
    105. tb_bool_t tb_aico_clos_try(tb_aico_ref_t aico);
    106.  
    107. /*! the aico timeout
    108. *
    109. * @param aico the aico
    110. * @param type the timeout type
    111. *
    112. * @return the timeout
    113. */
    114. tb_long_t tb_aico_timeout(tb_aico_ref_t aico, tb_size_t type);
    115.  
    116. /*! set the aico timeout
    117. *
    118. * @param aico the aico
    119. * @param type the timeout type
    120. * @param timeout the timeout
    121. */
    122. tb_void_t tb_aico_timeout_set(tb_aico_ref_t aico, tb_size_t type, tb_long_t timeout);
    123.  
    124. /*! post the clos
    125. *
    126. * @param aicp the aicp
    127. * @param func the func
    128. * @param priv the func private data
    129. *
    130. * @return tb_true or tb_false
    131. */
    132. tb_bool_t tb_aico_clos(tb_aico_ref_t aico, tb_aico_func_t func, tb_cpointer_t priv);
    133.  
    134. /*! post the acpt
    135. *
    136. * @param aico the aico
    137. * @param func the callback func
    138. * @param priv the callback data
    139. *
    140. * @return tb_true or tb_false
    141. */
    142. tb_bool_t tb_aico_acpt(tb_aico_ref_t aico, tb_aico_func_t func, tb_cpointer_t priv);
    143.  
    144. /*! post the conn
    145. *
    146. * @param aico the aico
    147. * @param addr the addr
    148. * @param port the port
    149. * @param func the callback func
    150. * @param priv the callback data
    151. *
    152. * @return tb_true or tb_false
    153. */
    154. tb_bool_t tb_aico_conn(tb_aico_ref_t aico, tb_ipv4_t const* addr, tb_uint16_t port, tb_aico_func_t func, tb_cpointer_t priv);
    155.  
    156. /*! post the recv for sock
    157. *
    158. * @param aico the aico
    159. * @param data the data
    160. * @param size the size
    161. * @param func the callback func
    162. * @param priv the callback data
    163. *
    164. * @return tb_true or tb_false
    165. */
    166. tb_bool_t tb_aico_recv(tb_aico_ref_t aico, tb_byte_t* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    167.  
    168. /*! post the send for sock
    169. *
    170. * @param aico the aico
    171. * @param data the data
    172. * @param size the size, send the left file data if size == 0
    173. * @param func the callback func
    174. * @param priv the callback data
    175. *
    176. * @return tb_true or tb_false
    177. */
    178. tb_bool_t tb_aico_send(tb_aico_ref_t aico, tb_byte_t const* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    179.  
    180. /*! post the urecv for sock
    181. *
    182. * @param aico the aico
    183. * @param addr the addr
    184. * @param port the port
    185. * @param data the data
    186. * @param size the size
    187. * @param func the callback func
    188. * @param priv the callback data
    189. *
    190. * @return tb_true or tb_false
    191. */
    192. tb_bool_t tb_aico_urecv(tb_aico_ref_t aico, tb_ipv4_t const* addr, tb_uint16_t port, tb_byte_t* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    193.  
    194. /*! post the usend for sock
    195. *
    196. * @param aico the aico
    197. * @param addr the addr
    198. * @param port the port
    199. * @param data the data
    200. * @param size the size, send the left file data if size == 0
    201. * @param func the callback func
    202. * @param priv the callback data
    203. *
    204. * @return tb_true or tb_false
    205. */
    206. tb_bool_t tb_aico_usend(tb_aico_ref_t aico, tb_ipv4_t const* addr, tb_uint16_t port, tb_byte_t const* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    207.  
    208. /*! post the recvv for sock
    209. *
    210. * @param aico the aico
    211. * @param list the list
    212. * @param size the size
    213. * @param func the callback func
    214. * @param priv the callback data
    215. *
    216. * @return tb_true or tb_false
    217. */
    218. tb_bool_t tb_aico_recvv(tb_aico_ref_t aico, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    219.  
    220. /*! post the sendv for sock
    221. *
    222. * @param aico the aico
    223. * @param list the list
    224. * @param size the size
    225. * @param func the callback func
    226. * @param priv the callback data
    227. *
    228. * @return tb_true or tb_false
    229. */
    230. tb_bool_t tb_aico_sendv(tb_aico_ref_t aico, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    231.  
    232. /*! post the urecvv for sock
    233. *
    234. * @param aico the aico
    235. * @param addr the addr
    236. * @param port the port
    237. * @param list the list
    238. * @param size the size
    239. * @param func the callback func
    240. * @param priv the callback data
    241. *
    242. * @return tb_true or tb_false
    243. */
    244. tb_bool_t tb_aico_urecvv(tb_aico_ref_t aico, tb_ipv4_t const* addr, tb_uint16_t port, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    245.  
    246. /*! post the usendv for sock
    247. *
    248. * @param aico the aico
    249. * @param addr the addr
    250. * @param port the port
    251. * @param list the list
    252. * @param size the size
    253. * @param func the callback func
    254. * @param priv the callback data
    255. *
    256. * @return tb_true or tb_false
    257. */
    258. tb_bool_t tb_aico_usendv(tb_aico_ref_t aico, tb_ipv4_t const* addr, tb_uint16_t port, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    259.  
    260. /*! post the sendfile for sock
    261. *
    262. * @param aico the aico
    263. * @param file the file handle
    264. * @param seek the seek
    265. * @param size the size, send the left data if size == 0
    266. * @param func the callback func
    267. * @param priv the callback data
    268. *
    269. * @return tb_true or tb_false
    270. */
    271. tb_bool_t tb_aico_sendf(tb_aico_ref_t aico, tb_file_ref_t file, tb_hize_t seek, tb_hize_t size, tb_aico_func_t func, tb_cpointer_t priv);
    272.  
    273. /*! post the read for file
    274. *
    275. * @param aico the aico
    276. * @param seek the seek
    277. * @param data the data
    278. * @param size the size
    279. * @param func the callback func
    280. * @param priv the callback data
    281. *
    282. * @return tb_true or tb_false
    283. */
    284. tb_bool_t tb_aico_read(tb_aico_ref_t aico, tb_hize_t seek, tb_byte_t* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    285.  
    286. /*! post the writ for file
    287. *
    288. * @param aico the aico
    289. * @param seek the seek
    290. * @param data the data
    291. * @param size the size
    292. * @param func the callback func
    293. * @param priv the callback data
    294. *
    295. * @return tb_true or tb_false
    296. */
    297. tb_bool_t tb_aico_writ(tb_aico_ref_t aico, tb_hize_t seek, tb_byte_t const* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    298.  
    299. /*! post the readv for file
    300. *
    301. * @param aico the aico
    302. * @param seek the seek
    303. * @param list the list
    304. * @param size the size
    305. * @param func the callback func
    306. * @param priv the callback data
    307. *
    308. * @return tb_true or tb_false
    309. */
    310. tb_bool_t tb_aico_readv(tb_aico_ref_t aico, tb_hize_t seek, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    311.  
    312. /*! post the writv for file
    313. *
    314. * @param aico the aico
    315. * @param seek the seek
    316. * @param list the list
    317. * @param size the size
    318. * @param func the callback func
    319. * @param priv the callback data
    320. *
    321. * @return tb_true or tb_false
    322. */
    323. tb_bool_t tb_aico_writv(tb_aico_ref_t aico, tb_hize_t seek, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    324.  
    325. /*! post the fsync for file
    326. *
    327. * @param aico the aico
    328. * @param func the callback func
    329. * @param priv the callback data
    330. *
    331. * @return tb_true or tb_false
    332. */
    333. tb_bool_t tb_aico_fsync(tb_aico_ref_t aico, tb_aico_func_t func, tb_cpointer_t priv);
    334.  
    335. /*! post the clos after the delay time
    336. *
    337. * @param aico the aico
    338. * @param delay the delay time, ms
    339. * @param func the callback func
    340. * @param priv the callback data
    341. *
    342. * @return tb_true or tb_false
    343. */
    344. tb_bool_t tb_aico_clos_after(tb_aico_ref_t aico, tb_size_t delay, tb_aico_func_t func, tb_cpointer_t priv);
    345.  
    346. /*! post the acpt after the delay time
    347. *
    348. * @param aico the aico
    349. * @param delay the delay time, ms
    350. * @param func the callback func
    351. * @param priv the callback data
    352. *
    353. * @return tb_true or tb_false
    354. */
    355. tb_bool_t tb_aico_acpt_after(tb_aico_ref_t aico, tb_size_t delay, tb_aico_func_t func, tb_cpointer_t priv);
    356.  
    357. /*! post the conn after the delay time
    358. *
    359. * @param aico the aico
    360. * @param delay the delay time, ms
    361. * @param addr the addr
    362. * @param port the port
    363. * @param func the callback func
    364. * @param priv the callback data
    365. *
    366. * @return tb_true or tb_false
    367. */
    368. tb_bool_t tb_aico_conn_after(tb_aico_ref_t aico, tb_size_t delay, tb_ipv4_t const* addr, tb_uint16_t port, tb_aico_func_t func, tb_cpointer_t priv);
    369.  
    370. /*! post the recv for sock after the delay time
    371. *
    372. * @param aico the aico
    373. * @param delay the delay time, ms
    374. * @param data the data
    375. * @param size the size
    376. * @param func the callback func
    377. * @param priv the callback data
    378. *
    379. * @return tb_true or tb_false
    380. */
    381. tb_bool_t tb_aico_recv_after(tb_aico_ref_t aico, tb_size_t delay, tb_byte_t* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    382.  
    383. /*! post the send for sock after the delay time
    384. *
    385. * @param aico the aico
    386. * @param delay the delay time, ms
    387. * @param data the data
    388. * @param size the size, send the left file data if size == 0
    389. * @param func the callback func
    390. * @param priv the callback data
    391. *
    392. * @return tb_true or tb_false
    393. */
    394. tb_bool_t tb_aico_send_after(tb_aico_ref_t aico, tb_size_t delay, tb_byte_t const* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    395.  
    396. /*! post the urecv for sock after the delay time
    397. *
    398. * @param aico the aico
    399. * @param delay the delay time, ms
    400. * @param addr the addr
    401. * @param port the port
    402. * @param data the data
    403. * @param size the size
    404. * @param func the callback func
    405. * @param priv the callback data
    406. *
    407. * @return tb_true or tb_false
    408. */
    409. tb_bool_t tb_aico_urecv_after(tb_aico_ref_t aico, tb_size_t delay, tb_ipv4_t const* addr, tb_uint16_t port, tb_byte_t* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    410.  
    411. /*! post the usend for sock after the delay time
    412. *
    413. * @param aico the aico
    414. * @param delay the delay time, ms
    415. * @param addr the addr
    416. * @param port the port
    417. * @param data the data
    418. * @param size the size, send the left file data if size == 0
    419. * @param func the callback func
    420. * @param priv the callback data
    421. *
    422. * @return tb_true or tb_false
    423. */
    424. tb_bool_t tb_aico_usend_after(tb_aico_ref_t aico, tb_size_t delay, tb_ipv4_t const* addr, tb_uint16_t port, tb_byte_t const* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    425.  
    426. /*! post the recvv for sock after the delay time
    427. *
    428. * @param aico the aico
    429. * @param delay the delay time, ms
    430. * @param list the list
    431. * @param size the size
    432. * @param func the callback func
    433. * @param priv the callback data
    434. *
    435. * @return tb_true or tb_false
    436. */
    437. tb_bool_t tb_aico_recvv_after(tb_aico_ref_t aico, tb_size_t delay, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    438.  
    439. /*! post the sendv for sock after the delay time
    440. *
    441. * @param aico the aico
    442. * @param delay the delay time, ms
    443. * @param list the list
    444. * @param size the size
    445. * @param func the callback func
    446. * @param priv the callback data
    447. *
    448. * @return tb_true or tb_false
    449. */
    450. tb_bool_t tb_aico_sendv_after(tb_aico_ref_t aico, tb_size_t delay, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    451.  
    452. /*! post the urecvv for sock after the delay time
    453. *
    454. * @param aico the aico
    455. * @param delay the delay time, ms
    456. * @param addr the addr
    457. * @param port the port
    458. * @param list the list
    459. * @param size the size
    460. * @param func the callback func
    461. * @param priv the callback data
    462. *
    463. * @return tb_true or tb_false
    464. */
    465. tb_bool_t tb_aico_urecvv_after(tb_aico_ref_t aico, tb_size_t delay, tb_ipv4_t const* addr, tb_uint16_t port, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    466.  
    467. /*! post the usendv for sock after the delay time
    468. *
    469. * @param aico the aico
    470. * @param delay the delay time, ms
    471. * @param addr the addr
    472. * @param port the port
    473. * @param list the list
    474. * @param size the size
    475. * @param func the callback func
    476. * @param priv the callback data
    477. *
    478. * @return tb_true or tb_false
    479. */
    480. tb_bool_t tb_aico_usendv_after(tb_aico_ref_t aico, tb_size_t delay, tb_ipv4_t const* addr, tb_uint16_t port, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    481.  
    482. /*! post the sendfile for sock after the delay time
    483. *
    484. * @param aico the aico
    485. * @param delay the delay time, ms
    486. * @param file the file handle
    487. * @param seek the seek
    488. * @param size the size, send the left data if size == 0
    489. * @param func the callback func
    490. * @param priv the callback data
    491. *
    492. * @return tb_true or tb_false
    493. */
    494. tb_bool_t tb_aico_sendf_after(tb_aico_ref_t aico, tb_size_t delay, tb_file_ref_t file, tb_hize_t seek, tb_hize_t size, tb_aico_func_t func, tb_cpointer_t priv);
    495.  
    496. /*! post the read for file after the delay time
    497. *
    498. * @param aico the aico
    499. * @param delay the delay time, ms
    500. * @param seek the seek
    501. * @param data the data
    502. * @param size the size
    503. * @param func the callback func
    504. * @param priv the callback data
    505. *
    506. * @return tb_true or tb_false
    507. */
    508. tb_bool_t tb_aico_read_after(tb_aico_ref_t aico, tb_size_t delay, tb_hize_t seek, tb_byte_t* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    509.  
    510. /*! post the writ for file after the delay time
    511. *
    512. * @param aico the aico
    513. * @param delay the delay time, ms
    514. * @param seek the seek
    515. * @param data the data
    516. * @param size the size
    517. * @param func the callback func
    518. * @param priv the callback data
    519. *
    520. * @return tb_true or tb_false
    521. */
    522. tb_bool_t tb_aico_writ_after(tb_aico_ref_t aico, tb_size_t delay, tb_hize_t seek, tb_byte_t const* data, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    523.  
    524. /*! post the readv for file after the delay time
    525. *
    526. * @param aico the aico
    527. * @param delay the delay time, ms
    528. * @param seek the seek
    529. * @param list the list
    530. * @param size the size
    531. * @param func the callback func
    532. * @param priv the callback data
    533. *
    534. * @return tb_true or tb_false
    535. */
    536. tb_bool_t tb_aico_readv_after(tb_aico_ref_t aico, tb_size_t delay, tb_hize_t seek, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    537.  
    538. /*! post the writv for file after the delay time
    539. *
    540. * @param aico the aico
    541. * @param delay the delay time, ms
    542. * @param seek the seek
    543. * @param list the list
    544. * @param size the size
    545. * @param func the callback func
    546. * @param priv the callback data
    547. *
    548. * @return tb_true or tb_false
    549. */
    550. tb_bool_t tb_aico_writv_after(tb_aico_ref_t aico, tb_size_t delay, tb_hize_t seek, tb_iovec_t const* list, tb_size_t size, tb_aico_func_t func, tb_cpointer_t priv);
    551.  
    552. /*! post the fsync for file after the delay time
    553. *
    554. * @param aico the aico
    555. * @param delay the delay time, ms
    556. * @param func the callback func
    557. * @param priv the callback data
    558. *
    559. * @return tb_true or tb_false
    560. */
    561. tb_bool_t tb_aico_fsync_after(tb_aico_ref_t aico, tb_size_t delay, tb_aico_func_t func, tb_cpointer_t priv);
    562.  
    563. /*! run aico task after timeout and will be auto-remove it after be expired
    564. *
    565. * only once, need continue to call it again if want to repeat task
    566. *
    567. * @param aico the aico
    568. * @param delay the delay time, ms
    569. * @param func the callback func
    570. * @param priv the callback data
    571. *
    572. * @return tb_true or tb_false
    573. */
    574. tb_bool_t tb_aico_task_run(tb_aico_ref_t aico, tb_size_t delay, tb_aico_func_t func, tb_cpointer_t priv);