DomainSocket implements Closeable { public void shutdown() throws IOException { refCount.reference(); boolean exc = true; try { shutdown0(fd); exc = false; } finally { unreference(exc); } } private  DomainSocket(String path, int fd); static String getLoadingFailureReason(); @VisibleForTesting static void disableBindPathValidation(); static String getEffectivePath(String path, int port); static DomainSocket bindAndListen(String path); static DomainSocket[] socketpair(); DomainSocket accept(); static DomainSocket connect(String path); boolean isOpen(); String getPath(); DomainInputStream getInputStream(); DomainOutputStream getOutputStream(); DomainChannel getChannel(); void setAttribute(int type, int size); int getAttribute(int type); @Override void close(); void shutdown(); void sendFileDescriptors(FileDescriptor descriptors[],
      byte jbuf[], int offset, int length); int recvFileInputStreams(FileInputStream[] streams, byte buf[],
        int offset, int length); @Override String toString(); static final int SEND_BUFFER_SIZE; static final int RECEIVE_BUFFER_SIZE; static final int SEND_TIMEOUT; static final int RECEIVE_TIMEOUT; }
@Test(timeout=180000) public void testShutdown() throws Exception { final AtomicInteger bytesRead = new AtomicInteger(0); final AtomicBoolean failed = new AtomicBoolean(false); final DomainSocket[] socks = DomainSocket.socketpair(); Runnable reader = new Runnable() { @Override public void run() { while (true) { try { int ret = socks[1].getInputStream().read(); if (ret == -1) return; bytesRead.addAndGet(1); } catch (IOException e) { DomainSocket.LOG.error("reader error", e); failed.set(true); return; } } } }; Thread readerThread = new Thread(reader); readerThread.start(); socks[0].getOutputStream().write(1); socks[0].getOutputStream().write(2); socks[0].getOutputStream().write(3); Assert.assertTrue(readerThread.isAlive()); socks[0].shutdown(); readerThread.join(); Assert.assertFalse(failed.get()); Assert.assertEquals(3, bytesRead.get()); IOUtils.cleanup(null, socks); }