日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Android應(yīng)用程序進(jìn)程啟動(dòng)過程的源代碼分析(五)

上文中的Socket由frameworks/base/core/java/com/Android/internal/os/ZygoteInit.java文件中的ZygoteInit類在runSelectLoopMode函數(shù)偵聽的。

Step 5. ZygoteInit.runSelectLoopMode

這個(gè)函數(shù)定義在frameworks/base/core/java/com/android/internal/os/ZygoteInit.java文件中:

 
 
  1. [java] view plaincopypublic class ZygoteInit { 
  2.   ...... 
  3.   /** 
  4.   * Runs the zygote process's select loop. Accepts new connections as 
  5.   * they happen, and reads commands from connections one spawn-request's 
  6.   * worth at a time. 
  7.   * 
  8.   * @throws MethodAndArgsCaller in a child process when a main() should 
  9.   * be executed. 
  10.   */ 
  11.   private static void runSelectLoopMode() throws MethodAndArgsCaller { 
  12.   ArrayList fds = new ArrayList(); 
  13.   ArrayList peers = new ArrayList(); 
  14.   FileDescriptor[] fdArray = new FileDescriptor[4]; 
  15.   fds.add(sServerSocket.getFileDescriptor()); 
  16.   peers.add(null); 
  17.   int loopCount = GC_LOOP_COUNT; 
  18.   while (true) { 
  19.   int index; 
  20.   /* 
  21.   * Call gc() before we block in select(). 
  22.   * It's work that has to be done anyway, and it's better 
  23.   * to avoid making every child do it. It will also 
  24.   * madvise() any free memory as a side-effect. 
  25.   * 
  26.   * Don't call it every time, because walking the entire 
  27.   * heap is a lot of overhead to free a few hundred bytes. 
  28.   */ 
  29.   if (loopCount <= 0) { 
  30.   gc(); 
  31.   loopCount = GC_LOOP_COUNT; 
  32.   } else { 
  33.   loopCount--; 
  34.   } 
  35.   try { 
  36.   fdArray = fds.toArray(fdArray); 
  37.   index = selectReadable(fdArray); 
  38.   } catch (IOException ex) { 
  39.   throw new RuntimeException("Error in select()", ex); 
  40.   } 
  41.   if (index < 0) { 
  42.   throw new RuntimeException("Error in select()"); 
  43.   } else if (index == 0) { 
  44.   ZygoteConnection newPeer = acceptCommandPeer(); 
  45.   peers.add(newPeer); 
  46.   fds.add(newPeer.getFileDesciptor()); 
  47.   } else { 
  48.   boolean done; 
  49.   done = peers.get(index).runOnce(); 
  50.   if (done) { 
  51.   peers.remove(index); 
  52.   fds.remove(index); 
  53.   } 
  54.   } 
  55.   } 
  56.   } 
  57.   ...... 
  58.   } 

當(dāng)Step 4將數(shù)據(jù)通過Socket接口發(fā)送出去后,就會(huì)下面這個(gè)語(yǔ)句:

 
 
  1. [java] view plaincopydone = peers.get(index).runOnce(); 

這里從peers.get(index)得到的是一個(gè)ZygoteConnection對(duì)象,表示一個(gè)Socket連接,因此,接下來就是調(diào)用ZygoteConnection.runOnce函數(shù)進(jìn)一步處理了。


標(biāo)題名稱:Android應(yīng)用程序進(jìn)程啟動(dòng)過程的源代碼分析(五)
網(wǎng)站鏈接:http://www.dlmjj.cn/article/dpddpii.html