新聞中心
這里有您想知道的互聯(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文件中:
- [java] view plaincopypublic class ZygoteInit {
- ......
- /**
- * Runs the zygote process's select loop. Accepts new connections as
- * they happen, and reads commands from connections one spawn-request's
- * worth at a time.
- *
- * @throws MethodAndArgsCaller in a child process when a main() should
- * be executed.
- */
- private static void runSelectLoopMode() throws MethodAndArgsCaller {
- ArrayList fds = new ArrayList();
- ArrayList peers = new ArrayList();
- FileDescriptor[] fdArray = new FileDescriptor[4];
- fds.add(sServerSocket.getFileDescriptor());
- peers.add(null);
- int loopCount = GC_LOOP_COUNT;
- while (true) {
- int index;
- /*
- * Call gc() before we block in select().
- * It's work that has to be done anyway, and it's better
- * to avoid making every child do it. It will also
- * madvise() any free memory as a side-effect.
- *
- * Don't call it every time, because walking the entire
- * heap is a lot of overhead to free a few hundred bytes.
- */
- if (loopCount <= 0) {
- gc();
- loopCount = GC_LOOP_COUNT;
- } else {
- loopCount--;
- }
- try {
- fdArray = fds.toArray(fdArray);
- index = selectReadable(fdArray);
- } catch (IOException ex) {
- throw new RuntimeException("Error in select()", ex);
- }
- if (index < 0) {
- throw new RuntimeException("Error in select()");
- } else if (index == 0) {
- ZygoteConnection newPeer = acceptCommandPeer();
- peers.add(newPeer);
- fds.add(newPeer.getFileDesciptor());
- } else {
- boolean done;
- done = peers.get(index).runOnce();
- if (done) {
- peers.remove(index);
- fds.remove(index);
- }
- }
- }
- }
- ......
- }
當(dāng)Step 4將數(shù)據(jù)通過Socket接口發(fā)送出去后,就會(huì)下面這個(gè)語(yǔ)句:
- [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


咨詢
建站咨詢
