如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
再次浅析adbshell,pcdaemon和手机daemon三者之间的数据交互流程再次浅析adbshell,pcdaemon和手机daemon三者之间的数据交互流程HYPERLINK"http://blog.chinaunix.net/u1/38994/showart_1807376.html"\t"_blank"《浅析linux开发工具adb具体实现》HYPERLINK"http://blog.chinaunix.net/u1/38994/showart_1907747.html"\t"_blank"《浅析adb创建流程》###################adbshellinteractive_shel==>fd=socket_loopback_client(ADB_PORT,SOCK_STREAM);向该fd发送"shell:"字符串,之后本地的daemon程序接收到来自loopback,ADB_PORT端口数据,然后交由local_socket_event_func函数处理,intinteractive_shell(void){adb_thread_tthr;intfdi,fd;int*fds;fd=adb_connect("shell:");//和pcdaemon建立的socket连接句柄fdif(fd<0){fprintf(stderr,"error:%s\n",adb_error());return1;}fdi=0;//dup(0);fds=malloc(sizeof(int)*2);fds[0]=fd;fds[1]=fdi;#ifdefHAVE_TERMIO_Hstdin_raw_init(fdi);#endif//单独创建一个thread等待stdin键盘输入,//然后将键盘输入的数据发送给fd,也就是发送给//在本地与pcdaemon建立的socket[luther.gliethttp]adb_thread_create(&thr,stdin_read_thread,fds);read_and_dump(fd);//回显pcdaemon穿过来的数据#ifdefHAVE_TERMIO_Hstdin_raw_restore(fdi);#endifreturn0;}staticvoidread_and_dump(intfd){charbuf[4096];intlen;while(fd>=0){len=adb_read(fd,buf,4096);//读取和pcdaemon建立的socket,然后将接收到的数据打印到stdout显示if(len==0){break;}if(len<0){if(errno==EINTR)continue;break;}/*wewanttooutputtostdout,sonoadb_writehere!!*/unix_write(1,buf,len);}}###################pc上的daemonss_listener_event_func//等待连接==>s=create_local_socket(fd);//为新来的一个连接建立socket,并安装处理该socket的handler--local_socket_event_func==>create_local_socket==>install_local_socket==>s->id=local_socket_next_id++;//该socket在daemon的id标识s->enqueue=local_socket_enqueue;然后在output_thread线程handler中会调用到local_socket_enqueue==>t->read_from_remote(p,t)==>write_packet(t->fd,&p)==>transport_socket_events==>handle_packetcaseA_WRTE:if(t->connection_state!=CS_OFFLINE){if((s=find_local_socket(p->msg.arg1))){//根据s->id查找本地daemon[手机或pc]管理的相应socket处理函数unsignedrid=p->msg.arg0;p->len=p->msg.data_length;if(s->enqueue(s,p)==0){//调用local的数据处理函数,处理来自remote端的数据,也就是local_socket_enqueue处理函数D("Enqueuethesocket\n");send_ready(s->id,rid,t);}return;}}break;==>local_socket_enqueue