有求必应之等待请求——runSelectLoop
zygote从startSystemServer返回后,将进入第四个关键的函数:runSelectLoop。我们来看一下这个函数的实现:
- static final int GC_LOOP_COUNT = 10; private static void runSelectLoop() throws MethodAndArgsCaller {
- ArrayList<FileDescriptor> fds = new ArrayList<FileDescriptor>(); ArrayList<ZygoteConnection> peers = new ArrayList<ZygoteConnection>();
- FileDescriptor[] fdArray = new FileDescriptor[4];
- fds.add(sServerSocket.getFileDescriptor()); peers.add(null);
- int loopCount = GC_LOOP_COUNT;
- while (true) { int index;
- 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); }
- } }










