void init_transport_registration(void)
{
adb_socketpair(s) //创建socket pair用于处理异步注册事件
transport_registration_send = s[0];
transport_registration_recv = s[1];
// 在transport_registration_recv上安装一个transport_registration_func异步事情回调函数
fdevent_install(&transport_registration_fde,
transport_registration_recv,
transport_registration_func,
0);
...
}
异步如何触发的呢?
register_transport
-->transport_write_action(transport_registration_send, &m)
remove_transport
-->transport_write_action(transport_registration_send, &m)
此时会将事件写入socket pair的写入端,而接收端:
void fdevent_loop()
{
...
for(;;) {
while((fde = fdevent_plist_dequeue())) {
unsigned events = fde->events;
fde->events = 0;
fde->state &= (~FDE_PENDING);
dump_fde(fde, "callback");
//这个回调函数是在:fdevent_install 函数中注册的:fde->func = func;
fde->func(fde->fd, events, fde->arg);
}
}
}
然后利用transport_read_action读取异步事情,那么数据处理在哪里呢?
transport_registration_func
-->
/* don't create transport threads for inaccessible devices */
if (t->connection_state != CS_NOPERM) {
if(adb_thread_create(&input_thread_ptr, input_thread, t)){
fatal_errno("cannot create input thread");
}
if(adb_thread_create(&output_thread_ptr, output_thread, t)){
fatal_errno("cannot create output thread");
}
}
在这里会创建两个线程 output thread和 input thread用于做异步 IO,