Java 类java.net.SocketImpl 实例源码

项目:Lantern-sdk    文件:LanternSocketImpl.java   
protected void accept(SocketImpl newSocket) throws IOException {
    try {
        this.delegator.invoke(new Object[]{newSocket});
    } catch (Exception var5) {
        Exception e = var5;
        if(var5 instanceof IOException) {
            throw (IOException)var5;
        }
        try {
            throw e.getCause();
        } catch (Throwable var4) {
            var4.printStackTrace();
        }
    }

}
项目:heapunit    文件:DumpSocketsExample.java   
@Test
public void printSockets() throws IOException {

    ServerSocket ss = new ServerSocket();
    ss.bind(sock(5000));

    Socket s1 = new Socket();
    Socket s2 = new Socket();

    s1.connect(sock(5000));
    s2.connect(sock(5000));

    ss.close();
    s1.close();
    // s2 remains unclosed

    HeapImage hi = HeapUnit.captureHeap();

    for(HeapInstance i: hi.instances(SocketImpl.class)) {
        // fd field in SocketImpl class is nullified when socket gets closed
        boolean open = i.value("fd") != null;
        System.out.println(i.rehydrate() + (open ? " - open" : " - closed"));
    }
}
项目:javify    文件:PlainSocketImpl.java   
/**
 * Accepts a new connection on this socket and returns in in the
 * passed in SocketImpl.
 *
 * @param impl The SocketImpl object to accept this connection.
 */
protected synchronized void accept(SocketImpl impl)
  throws IOException
{
  if (channel == null)
      create(true);
  if (!(impl instanceof PlainSocketImpl))
    throw new IOException("incompatible SocketImpl: "
                          + impl.getClass().getName());
  PlainSocketImpl that = (PlainSocketImpl) impl;
  VMChannel c = channel.getVMChannel().accept();
  that.impl.getState().setChannelFD(c.getState());
  that.channel = new SocketChannelImpl(c);
  that.setOption(SO_REUSEADDR, Boolean.TRUE);
  // Reset the inherited timeout.
  that.setOption(SO_TIMEOUT, Integer.valueOf(0));

}
项目:jvm-stm    文件:PlainSocketImpl.java   
/**
 * Accepts a new connection on this socket and returns in in the 
 * passed in SocketImpl.
 *
 * @param impl The SocketImpl object to accept this connection.
 */
protected synchronized void accept(SocketImpl impl)
  throws IOException
{
  if (channel == null)
      create(true);
  if (!(impl instanceof PlainSocketImpl))
    throw new IOException("incompatible SocketImpl: "
                          + impl.getClass().getName());
  PlainSocketImpl that = (PlainSocketImpl) impl;
  VMChannel c = channel.getVMChannel().accept();
  that.impl.getState().setChannelFD(c.getState());
  that.channel = new SocketChannelImpl(c);
  that.setOption(SO_REUSEADDR, Boolean.TRUE);
  // Reset the inherited timeout.
  that.setOption(SO_TIMEOUT, Integer.valueOf(0));

}
项目:In-the-Box-Fork    文件:PlainSocketImpl.java   
@Override
protected void accept(SocketImpl newImpl) throws IOException {
    if (usingSocks()) {
        ((PlainSocketImpl) newImpl).socksBind();
        ((PlainSocketImpl) newImpl).socksAccept();
        return;
    }

    try {
        if (newImpl instanceof PlainSocketImpl) {
            PlainSocketImpl newPlainSocketImpl = (PlainSocketImpl) newImpl;
            netImpl.accept(fd, newImpl, newPlainSocketImpl.getFileDescriptor());
        } else {
            // if newImpl is not an instance of PlainSocketImpl, use
            // reflection to get/set protected fields.
            if (fdField == null) {
                fdField = getSocketImplField("fd");
            }
            FileDescriptor newFd = (FileDescriptor) fdField.get(newImpl);
            netImpl.accept(fd, newImpl, newFd);
        }
    } catch (IllegalAccessException e) {
        // empty
    }
}
项目:java-socketimpl-hook    文件:SocketImplHookFactory.java   
public SocketImpl createSocketImpl() {
    final SocketImpl socketImpl;
    if ( null != clazz )
    {
        try
        {
            socketImpl = (java.net.SocketImpl) clazz.newInstance();
            return new SocketImplHook( socketImpl );
        }
        catch ( Exception e )
        {

        }
    }

    return null;
}
项目:sniffy    文件:SnifferSocketImplFactoryTest.java   
@Override
public SocketImpl createSocketImpl() {
    try {
        return SnifferSocketImplFactory.defaultSocketImplClassConstructor.newInstance();
    } catch (Exception e) {
        ExceptionUtil.throwException(e);
        return null;
    } finally {

        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

        boolean serverSocket = false;

        if (null != stackTrace) {
            for (StackTraceElement ste : stackTrace) {
                if (ste.getClassName().startsWith("java.net.ServerSocket")) {
                    serverSocket = true;
                }
            }
        }

        if (!serverSocket) {
            invocationCounter.incrementAndGet();
        }
    }
}
项目:JamVM-PH    文件:PlainSocketImpl.java   
/**
 * Accepts a new connection on this socket and returns in in the 
 * passed in SocketImpl.
 *
 * @param impl The SocketImpl object to accept this connection.
 */
protected synchronized void accept(SocketImpl impl)
  throws IOException
{
  if (channel == null)
      create(true);
  if (!(impl instanceof PlainSocketImpl))
    throw new IOException("incompatible SocketImpl: "
                          + impl.getClass().getName());
  PlainSocketImpl that = (PlainSocketImpl) impl;
  VMChannel c = channel.getVMChannel().accept();
  that.impl.getState().setChannelFD(c.getState());
  that.channel = new SocketChannelImpl(c);
  that.setOption(SO_REUSEADDR, Boolean.TRUE);
  // Reset the inherited timeout.
  that.setOption(SO_TIMEOUT, Integer.valueOf(0));

}
项目:appengine-java-vm-runtime    文件:TestSocketServlet.java   
private void testSetSocketImpl(HttpServletResponse response)
    throws IOException, AssertionFailedException {
  SocketImplFactory mockFactory =
      new SocketImplFactory() {
        @Override
        public SocketImpl createSocketImpl() {
          return null;
        }
      };

  SocketException caught = null;
  try {
    Socket.setSocketImplFactory(mockFactory);
  } catch (SocketException e) {
    caught = e;
  }
  assertNotNull("caught", caught, response);
}
项目:libbluray    文件:BDJSockets.java   
protected synchronized void add(Object obj) {
    if (!(obj instanceof SocketImpl)) {
        logger.error("expected SocketImpl, got " + obj);
        throw new Error("expected SocketImpl");
    }

    if (closed) {
        logger.error("Terminated Xlet tried to create socket at " + Logger.dumpStack());
        throw new Error("Terminated Xlet can not create sockets");
    }

    /* drop closed sockets */
    for (Iterator it = sockets.iterator(); it.hasNext(); ) {
        SocketImpl socketImpl = (SocketImpl)it.next();
        Socket     socket = getSocket(socketImpl);
        if (socket != null && socket.isClosed()) {
            it.remove();
        }
    }

    sockets.addLast(obj);
}
项目:libbluray    文件:BDJSockets.java   
protected synchronized void closeAll() {
    closed = true;

    while (!sockets.isEmpty()) {
        SocketImpl socketImpl = (SocketImpl)sockets.removeFirst();
        Socket socket = getSocket(socketImpl);
        if (socket != null && !socket.isClosed()) {
            logger.warning("Closing " + socket);
            try {
                socket.close();
            } catch (Exception e) {
                logger.error("Failed to close socket: " + e);
            }
        }
    }
}
项目:libbluray    文件:BDJSocketFactory.java   
private SocketImpl newSocket() {
    try {
        return (SocketImpl)AccessController.doPrivileged(
            new PrivilegedExceptionAction() {
                public Object run() throws Exception {
                    Class defaultSocketImpl = Class.forName("java.net.SocksSocketImpl");
                    Constructor constructor = defaultSocketImpl.getDeclaredConstructor/*s*/(new Class[0])/*[0]*/;
                    constructor.setAccessible(true);
                    return constructor.newInstance(new Object[0]);
                }
            });
    } catch (PrivilegedActionException e) {
        logger.error("Failed to create socket: " + e.getException() + " at " + Logger.dumpStack());
        throw new RuntimeException(e.getException());
    }
}
项目:libbluray    文件:BDJSocketFactory.java   
public SocketImpl createSocketImpl() {

        if (server) {
            logger.error("Xlet tried to create server socket");
            throw new RuntimeException("server sockets disabled");
        }

        SocketImpl socket = newSocket();
        BDJXletContext ctx = BDJXletContext.getCurrentContext();
        if (ctx != null) {
            logger.info("Xlet " + ctx + " created new socket");
            ctx.addSocket(socket);
        } else {
            logger.error("New socket created outside of Xlet context: " + Logger.dumpStack());
        }
        return socket;
    }
项目:classpath    文件:PlainSocketImpl.java   
/**
 * Accepts a new connection on this socket and returns in in the
 * passed in SocketImpl.
 *
 * @param impl The SocketImpl object to accept this connection.
 */
protected synchronized void accept(SocketImpl impl)
  throws IOException
{
  if (channel == null)
      create(true);
  if (!(impl instanceof PlainSocketImpl))
    throw new IOException("incompatible SocketImpl: "
                          + impl.getClass().getName());
  PlainSocketImpl that = (PlainSocketImpl) impl;
  VMChannel c = channel.getVMChannel().accept();
  that.impl.getState().setChannelFD(c.getState());
  that.channel = new SocketChannelImpl(c);
  that.setOption(SO_REUSEADDR, Boolean.TRUE);
  // Reset the inherited timeout.
  that.setOption(SO_TIMEOUT, Integer.valueOf(0));

}
项目:freeVM    文件:SocketTest.java   
/**
 * @tests java.net.Socket#setKeepAlive(boolean)
 */
public void test_setKeepAliveZ() throws Exception {
    // There is not really a good test for this as it is there to detect
    // crashed machines. Just make sure we can set it
    try {
        int sport = startServer("SServer setKeepAlive");
        int portNumber = Support_PortManager.getNextPort();
        Socket theSocket = new Socket(InetAddress.getLocalHost(), sport,
                null, portNumber);
        theSocket.setKeepAlive(true);
        theSocket.setKeepAlive(false);
        ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_KEEPALIVE);
    } catch (Exception e) {
        handleException(e, SO_KEEPALIVE);
    }
       // regression test for HARMONY-1136
    new testSocket((SocketImpl) null).setKeepAlive(true);
}
项目:HeraJVM    文件:JikesRVMSocketImpl.java   
/**
 * Set up socket factories to use JikesRVMSocketImpl
 */
public static void boot() {
  try {
    Socket.setSocketImplFactory(new SocketImplFactory() {
      public SocketImpl createSocketImpl() { return new JikesRVMSocketImpl(); }
    });
    ServerSocket.setSocketFactory(new SocketImplFactory() {
      public SocketImpl createSocketImpl() { return new JikesRVMSocketImpl(); }
    });
    DatagramSocket.setDatagramSocketImplFactory(new DatagramSocketImplFactory() {
      public DatagramSocketImpl createDatagramSocketImpl() {
        throw new VM_UnimplementedError("Need to implement JikesRVMDatagramSocketImpl");
      }
    });
  } catch (java.io.IOException e) {
    VM.sysFail("trouble setting socket impl factories");
  }
}
项目:Lantern-sdk    文件:LanternSocketFactory.java   
@Override
public SocketImpl createSocketImpl() {

    Logger.d("Socket Factory", "create");
    LanternSocketImpl socket = new LanternSocketImpl();
    _openSockets.add(socket);
    return socket;
}
项目:Lantern-sdk    文件:LanternSocketImpl.java   
public LanternSocketImpl() {
    this.delegator = new Delegator(this, SocketImpl.class, "java.net.PlainSocketImpl");

    networkCallback = new NetworkCallback() {
        @Override
        public void complete(Message msg) {
            switch (msg.what) {
                case CLOSE_MSG:
                    NetworkCallbackData closeCallbackData = (NetworkCallbackData) msg.obj;
                    if (networkCallbackData == null) {
                        networkCallbackData = closeCallbackData ;
                    } else {
                        networkCallbackData.setHostName(closeCallbackData.getHostName());
                        networkCallbackData.setStartTime(closeCallbackData.getStartTime());
                        networkCallbackData.setEndTime(closeCallbackData.getEndTime());
                    }
                    break;
                case STATUS_MSG:
                    NetworkCallbackData statusCallbackData = (NetworkCallbackData) msg.obj;
                    if (networkCallbackData == null) {
                        networkCallbackData = statusCallbackData ;
                    } else {
                        networkCallbackData.setStatus(statusCallbackData.getStatus());
                    }
                    break;
            }

            if (networkCallbackData.isComplete()) {
                DumpFileManager.getInstance(RYLA.getInstance().getContext()).saveDumpData(
                        new NetworkResponseData(networkCallbackData)
                );
            }
        }
    };
}
项目:silvertunnel-ng    文件:NetlibSocketImplFactory.java   
@Override
public synchronized SocketImpl createSocketImpl()
{
    if (netLayer != null)
    {
        return new NetSocket2SocketImpl(netLayer);
    }
    else
    {
        // prevent network access
        return new InvalidSocketImpl();
    }
}
项目:conscrypt    文件:Platform.java   
static FileDescriptor getFileDescriptorFromSSLSocket(AbstractConscryptSocket socket) {
    try {
        Field f_impl = Socket.class.getDeclaredField("impl");
        f_impl.setAccessible(true);
        Object socketImpl = f_impl.get(socket);
        Field f_fd = SocketImpl.class.getDeclaredField("fd");
        f_fd.setAccessible(true);
        return (FileDescriptor) f_fd.get(socketImpl);
    } catch (Exception e) {
        throw new RuntimeException("Can't get FileDescriptor from socket", e);
    }
}
项目:conscrypt    文件:Platform.java   
public static FileDescriptor getFileDescriptor(Socket s) {
    try {
        Field f_impl = Socket.class.getDeclaredField("impl");
        f_impl.setAccessible(true);
        Object socketImpl = f_impl.get(s);
        Field f_fd = SocketImpl.class.getDeclaredField("fd");
        f_fd.setAccessible(true);
        return (FileDescriptor) f_fd.get(socketImpl);
    } catch (Exception e) {
        throw new RuntimeException("Can't get FileDescriptor from socket", e);
    }
}
项目:javify    文件:LocalSocketImpl.java   
protected void accept (SocketImpl impl) throws IOException
{
  if (! (impl instanceof LocalSocketImpl))
    {
      throw new IllegalArgumentException ("not a local socket");
    }
  accept ((LocalSocketImpl) impl);
}
项目:jvm-stm    文件:LocalSocketImpl.java   
protected void accept (SocketImpl impl) throws IOException
{
  if (! (impl instanceof LocalSocketImpl))
    {
      throw new IllegalArgumentException ("not a local socket");
    }
  accept ((LocalSocketImpl) impl);
}
项目:j2objc    文件:PlainSocketImpl.java   
@Override
protected void accept(SocketImpl newImpl) throws IOException {
    if (usingSocks()) {
        ((PlainSocketImpl) newImpl).socksBind();
        ((PlainSocketImpl) newImpl).socksAccept();
        return;
    }

    try {
        InetSocketAddress peerAddress = new InetSocketAddress();
        FileDescriptor clientFd = Libcore.os.accept(fd, peerAddress);

        // TODO: we can't just set newImpl.fd to clientFd because a nio SocketChannel may
        newImpl.fd.setInt$(clientFd.getInt$());

        newImpl.address = peerAddress.getAddress();
        newImpl.port = peerAddress.getPort();
    } catch (ErrnoException errnoException) {
        if (errnoException.errno == EAGAIN) {
            throw new SocketTimeoutException(errnoException);
        }
        throw errnoException.rethrowAsSocketException();
    }

    // Reset the client's inherited read timeout to the Java-specified default of 0.
    newImpl.setOption(SocketOptions.SO_TIMEOUT, Integer.valueOf(0));

    newImpl.localport = IoBridge.getSocketLocalPort(newImpl.fd);
}
项目:mobac    文件:MySocketImplFactory.java   
public MySocketImplFactory() throws ClassNotFoundException, SecurityException,
        NoSuchMethodException {
    super();
    Class<?> c = Class.forName("java.net.PlainSocketImpl");
    constructor = c.getDeclaredConstructor();
    constructor.setAccessible(true);
    accept = c.getDeclaredMethod("accept", SocketImpl.class);
    accept.setAccessible(true);
    bind = c.getDeclaredMethod("bind", InetAddress.class, Integer.TYPE);
    bind.setAccessible(true);
    available = c.getDeclaredMethod("available");
    available.setAccessible(true);
    create = c.getDeclaredMethod("create", Boolean.TYPE);
    create.setAccessible(true);
    connect1 = c.getDeclaredMethod("connect", InetAddress.class, Integer.TYPE);
    connect1.setAccessible(true);
    connect2 = c.getDeclaredMethod("connect", SocketAddress.class, Integer.TYPE);
    connect2.setAccessible(true);
    connect3 = c.getDeclaredMethod("connect", String.class, Integer.TYPE);
    connect3.setAccessible(true);
    getInputStream = c.getDeclaredMethod("getInputStream");
    getInputStream.setAccessible(true);
    getOutputStream = c.getDeclaredMethod("getOutputStream");
    getOutputStream.setAccessible(true);
    close = c.getDeclaredMethod("close");
    close.setAccessible(true);
    sendUrgentData = c.getDeclaredMethod("sendUrgentData", Integer.TYPE);
    sendUrgentData.setAccessible(true);
    listen = c.getDeclaredMethod("listen", Integer.TYPE);
    listen.setAccessible(true);
}
项目:mobac    文件:MySocketImplFactory.java   
public SocketImpl createSocketImpl() {
    try {
        return new MySocketImpl();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:mobac    文件:MySocketImplFactory.java   
@Override
protected void accept(SocketImpl s) throws IOException {
    log.trace("[" + socketId + "] accept(...)");
    try {
        accept.invoke(si, s);
    } catch (Exception e) {
        if (e instanceof IOException)
            throw (IOException) e;
        throw new RuntimeException(e);
    }
}
项目:silvertunnel-monteux    文件:NetlibSocketImplFactory.java   
@Override
public synchronized SocketImpl createSocketImpl()
{
    if (netLayer != null)
    {
        return new NetSocket2SocketImpl(netLayer);
    }
    else
    {
        // prevent network access
        return new InvalidSocketImpl();
    }
}
项目:reflow    文件:ProcessInfo.java   
private ProcessInfo(){
    try {
        fd_getint = FileDescriptor.class.getDeclaredMethod("getInt$");
        socket_get_fd = SocketImpl.class.getDeclaredMethod("getFileDescriptor");
        socket_get_fd.setAccessible(true); // it's protected, or rather it was protected :)


    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
}
项目:reflow    文件:ProcessInfo.java   
public synchronized void handlePlainSocketClose(SocketImpl s){
    FileDescriptor fdo = getSocketFileDescriptor(s);
    int fd = getFD(fdo);
    if (known_connections_.containsKey(fd)) {
        sendMessage(MSG_DISCONNECT, fdo, null, 0, 0);
        known_connections_.remove(fd);
    }
    else
    {
      //  XposedBridge.log("Close for socket that we did not know anything about!");
    }
}
项目:evosuite    文件:EvoSuiteSocket.java   
@Override
protected void accept(SocketImpl s) throws IOException {

    if(!(s instanceof EvoSuiteSocket)) {
        throw new IOException("Can only handle mocked sockets");
    }

    EvoSuiteSocket mock = (EvoSuiteSocket) s;

    /*
     * If the test case has set up an incoming connection, then
     * simulate an immediate connection.
     * If not, there is no point in blocking the SUT for
     * a connection that will never arrive: just throw an exception
     */

    InetAddress localHost = (InetAddress) options.get(SocketOptions.SO_BINDADDR); 
    NativeTcp tcp = VirtualNetwork.getInstance().pullTcpConnection(localHost.getHostAddress(),localport);

    if(tcp == null) {
        throw new IOException("Simulated exception on waiting server");
    } else {
        mock.openedConnection = tcp;
        mock.setOption(SocketOptions.SO_BINDADDR, localHost);       
        mock.setLocalPort(localport);
        mock.setRemoteAddress(InetAddress.getByName(tcp.getRemoteEndPoint().getHost()));
        mock.setRemotePort(tcp.getRemoteEndPoint().getPort());
    }
}
项目:In-the-Box-Fork    文件:NativeCrypto.java   
/**
 * Return the FileDescriptor associated with the provided socket.
 */
public static FileDescriptor getFileDescriptor(Socket socket) {
    try {
        SocketImpl socketImpl = (SocketImpl) JAVA_NET_SOCKET_IMPL.get(socket);
        FileDescriptor fd = (FileDescriptor) JAVA_NET_SOCKETIMPL_FD.get(socketImpl);
        return fd;
    } catch (IllegalAccessException e) {
        throw new AssertionError(e);
    }
}
项目:In-the-Box-Fork    文件:PlainSocketImpl.java   
/**
 * gets SocketImpl field by reflection.
 */
private Field getSocketImplField(final String fieldName) {
    return AccessController.doPrivileged(new PrivilegedAction<Field>() {
        public Field run() {
            Field field = null;
            try {
                field = SocketImpl.class.getDeclaredField(fieldName);
                field.setAccessible(true);
            } catch (NoSuchFieldException e) {
                throw new Error(e);
            }
            return field;
        }
    });
}
项目:o5logon-fetch    文件:MitMSocketImplFactory.java   
@Override
public SocketImpl createSocketImpl() {
    try {
        return new MitMSocketImpl(
                (SocketImpl) plainSocketImplConstructor.newInstance(),
                this
                );
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    return null;
}
项目:sette-tool    文件:TestSuiteRunnerHelper.java   
private static SocketImpl newSocketImpl() {
    try {
        Class<?> defaultSocketImpl = Class.forName("java.net.SocksSocketImpl");
        Constructor<?> ctor = defaultSocketImpl.getDeclaredConstructor();
        ctor.setAccessible(true);
        return (SocketImpl) ctor.newInstance();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
项目:java-socketimpl-hook    文件:SocketImplHook.java   
public SocketImplHook(SocketImpl socketImpl) {

        boolean reflected = true;

        if ( null != socketImpl )
        {
            try
            {
                final Class<?>  clazz = this.socketImpl.getClass();

                _create = clazz.getDeclaredMethod( "create", new Class<?>[]{ boolean.class } );
                _connectHostPort = clazz.getDeclaredMethod( "connect", new Class<?>[]{ String.class, int.class } );
                _connectInetAddrPort = clazz.getDeclaredMethod( "connect", new Class<?>[]{ InetAddress.class, int.class } );
                _connectSocketAddrPort = clazz.getDeclaredMethod( "connect", new Class<?>[]{ SocketAddress.class, int.class } );
                _bind = clazz.getDeclaredMethod( "bind", new Class<?>[]{ InetAddress.class, int.class } );
                _listen = clazz.getDeclaredMethod( "listen", new Class<?>[]{ int.class } );
                _accept = clazz.getDeclaredMethod( "accept", new Class<?>[]{ SocketImpl.class } );
                _getInputStream = clazz.getDeclaredMethod( "getInputStream", new Class<?>[]{  } );
                _getOutputStream = clazz.getDeclaredMethod( "getOutputStream", new Class<?>[]{  } );
                _available = clazz.getDeclaredMethod( "available", new Class<?>[]{ } );
                _close = clazz.getDeclaredMethod( "close", new Class<?>[]{ } );
                _sendUrgantData = clazz.getDeclaredMethod( "sendUrgantData", new Class<?>[]{ int.class } );
            }
            catch ( Exception e )
            {
                reflected = false;
            }
        }

        if ( reflected )
        {
            this.socketImpl = socketImpl;
        }
        else
        {
            this.socketImpl = null;
        }
    }
项目:sniffy    文件:SnifferSocketImplFactory.java   
private static SocketImpl newSocketImpl() {

        if (null != previousSocketImplFactory) {
            return previousSocketImplFactory.createSocketImpl();
        } else {
            try {
                return null == defaultSocketImplClassConstructor ? null :
                        defaultSocketImplClassConstructor.newInstance();
            } catch (Exception e) {
                ExceptionUtil.throwException(e);
                return null;
            }
        }

    }
项目:cn1    文件:PlainSocketImpl.java   
/**
 * gets SocketImpl field by reflection.
 */
private Field getSocketImplField(final String fieldName) {
    return AccessController.doPrivileged(new PrivilegedAction<Field>() {
        public Field run() {
            Field field = null;
            try {
                field = SocketImpl.class.getDeclaredField(fieldName);
                field.setAccessible(true);
            } catch (NoSuchFieldException e) {
                throw new Error(e);
            }
            return field;
        }
    });
}
项目:cn1    文件:SocketTest.java   
/**
 * @tests java.net.Socket#setKeepAlive(boolean)
 */
public void test_setKeepAliveZ() throws IOException {

    class TestSocket extends Socket {
        public TestSocket(SocketImpl impl) throws SocketException {
            super(impl);
        }
    }

    // There is not really a good test for this as it is there to detect
    // crashed machines. Just make sure we can set it
    ServerSocket server = new ServerSocket(0);
    Socket client = new Socket(InetAddress.getLocalHost(), server
            .getLocalPort());

    try {
        client.setKeepAlive(true);
        client.setKeepAlive(false);
        ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_KEEPALIVE);
    } catch (Exception e) {
        handleException(e, SO_KEEPALIVE);
    } finally {
        client.close();
        server.close();
    }

    // Regression test for HARMONY-1136
    new TestSocket((SocketImpl) null).setKeepAlive(true);
}
项目:JamVM-PH    文件:LocalSocketImpl.java   
protected void accept (SocketImpl impl) throws IOException
{
  if (! (impl instanceof LocalSocketImpl))
    {
      throw new IllegalArgumentException ("not a local socket");
    }
  accept ((LocalSocketImpl) impl);
}