public static void releaseLocalSocket() { Log.i(Global.TAG, " --------------releaseLocalSocket start!"); try { if (videoReceiverLocalSocket != null) { videoReceiverLocalSocket.close(); videoReceiverLocalSocket = null; } if (videoSenderLocalSocket != null) { videoSenderLocalSocket.close(); videoSenderLocalSocket = null; } if (videoLocalServerSocket != null) { videoLocalServerSocket.close(); videoLocalServerSocket = null; } if (audioReceiverLocalSocket != null) { audioReceiverLocalSocket.close(); audioReceiverLocalSocket = null; } if (audioSenderLocalSocket != null) { audioSenderLocalSocket.close(); audioSenderLocalSocket = null; } if (audioLocalServerSocket != null) { audioLocalServerSocket.close(); audioLocalServerSocket = null; } } catch (Exception e) { e.printStackTrace(); } Log.i(Global.TAG, " --------------releaseLocalSocket end!"); }
/** * Runs the zygote in accept-and-fork mode. In this mode, each peer gets its own zygote spawner * process. This code is retained for reference only. * * @throws MethodAndArgsCaller in a child process when a main() should be executed. */ private static void runForkMode() throws MethodAndArgsCaller { while (true) { ZygoteConnection peer = acceptCommandPeer(); int pid; pid = Zygote.fork(); if (pid == 0) { // The child process should handle the peer requests // The child does not accept any more connections try { sServerSocket.close(); } catch (IOException ex) { Log.e(TAG, "Zygote Child: error closing sockets", ex); } finally { sServerSocket = null; } peer.run(); break; } else if (pid > 0) { peer.closeSocket(); } else { throw new RuntimeException("Error invoking fork()"); } } }
@Override public void onDestroy() { super.onDestroy(); Log.i(TAG, "Stopping service"); stopForeground(true); if (acceptor != null) { try { acceptor.close(); } catch (IOException e) { // We don't care } } try { executor.shutdownNow(); executor.awaitTermination(10, TimeUnit.SECONDS); } catch (InterruptedException e) { // Too bad } finally { started = false; // Unfortunately, we have no way to clean up some Binder-based callbacks // (namely IRotationWatcher) on lower API levels without killing the process, // which will allow DeathRecipient to handle it on their side. Process.killProcess(Process.myPid()); } }
private void listenFdServerSocket(final ParcelFileDescriptor tunPFD) throws Exception { final LocalServerSocket fdServerSocket = new LocalServerSocket("fdsock"); try { ExecutorService executorService = Executors.newFixedThreadPool(16); while (isRunning()) { try { final LocalSocket fdSocket = fdServerSocket.accept(); executorService.submit( new Runnable() { @Override public void run() { try { passFileDescriptor(fdSocket, tunPFD.getFileDescriptor()); } catch (Exception e) { LogUtils.e("failed to handle fdsock", e); } } }); } catch (Exception e) { LogUtils.e("failed to handle fdsock", e); } } executorService.shutdown(); } finally { fdServerSocket.close(); } }
public void release() { stop(); try { lss.close(); } catch (Exception ignore) { } super.release(); }
@Override public void interrupt() { super.interrupt(); try { acceptor.close(); } catch (IOException e) { e.printStackTrace(); } }
/** Close and clean up zygote sockets. Called on shutdown and on the child's exit path. */ static void closeServerSocket() { try { if (sServerSocket != null) { sServerSocket.close(); } } catch (IOException ex) { Log.e(TAG, "Zygote: error closing sockets", ex); } sServerSocket = null; }
/** Close and clean up zygote sockets. Called on shutdown and on the child's exit path. */ static void closeServerSocket() { try { if (sServerSocket != null) { FileDescriptor fd = sServerSocket.getFileDescriptor(); sServerSocket.close(); if (fd != null) { Os.close(fd); } } } catch (IOException ex) { Log.e(TAG, "Zygote: error closing sockets", ex); } catch (ErrnoException ex) { Log.e(TAG, "Zygote: error closing descriptor", ex); } sServerSocket = null; }
public void close() { if (localReceiver != null) { try { localReceiver.close(); } catch (IOException e) { } } if (localSender != null) { try { localSender.close(); } catch (IOException e) { } } if (localLoop != null) { try { localLoop.close(); } catch (IOException e) { } } }
@Override public void run() { String socketName = acceptor.getLocalSocketAddress().getName(); Log.i(TAG, String.format("Server listening on @%s", socketName)); try { while (!isInterrupted()) { Connection conn = new Connection(acceptor.accept()); executor.submit(conn); } } catch (IOException e) { } finally { Log.i(TAG, "Server stopping"); try { acceptor.close(); } catch (IOException e) { } stopSelf(); } }