自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android應用程序進程啟動過程的源代碼分析(五)

移動開發(fā) Android
ZygoteInit.runSelectLoopMode這個函數定義在frameworks/base/core/java/com/android/internal/os/ZygoteInit.java文件中。

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

Step 5. ZygoteInit.runSelectLoopMode

這個函數定義在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.   } 

當Step 4將數據通過Socket接口發(fā)送出去后,就會下面這個語句:

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

這里從peers.get(index)得到的是一個ZygoteConnection對象,表示一個Socket連接,因此,接下來就是調用ZygoteConnection.runOnce函數進一步處理了。

責任編輯:閆佳明 來源: bbs.9ria
相關推薦

2014-06-20 11:20:37

Android應用程序進程啟動

2014-06-19 14:30:28

Android應用程序進程啟動

2014-06-19 14:59:40

Android應用程序進程啟動

2014-06-19 14:54:11

Android應用程序進程啟動

2014-06-20 11:09:35

Android應用程序進程啟動

2014-06-19 14:25:04

Android應用程序進程啟動

2014-06-20 11:24:34

Android應用程序進程啟動

2012-02-20 14:47:08

JavaPlay

2014-05-22 15:00:16

Android消息處理機制Looper

2011-08-17 16:16:29

iPhone應用程序啟動過程

2011-07-28 10:34:38

Cocoa 程序 啟動

2014-06-23 10:31:09

Android啟動過程

2011-06-28 13:27:13

ARM Linux

2014-07-31 10:06:01

谷歌Google應用

2012-08-16 09:07:57

Erlang

2018-03-13 13:00:03

Linux運維啟動分析

2024-09-11 09:25:03

Tomcat組件PREP

2022-08-29 17:34:05

鴻蒙操作系統

2014-05-22 15:45:58

Android消息處理機制Looper

2009-08-14 17:57:43

ASP.NET MVC
點贊
收藏

51CTO技術棧公眾號