java类java.net.SocketImpl的实例源码

LanternSocketImpl.java 文件源码 项目:Lantern-sdk 阅读 22 收藏 0 点赞 0 评论 0
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();
        }
    }

}
DumpSocketsExample.java 文件源码 项目:heapunit 阅读 21 收藏 0 点赞 0 评论 0
@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"));
    }
}
PlainSocketImpl.java 文件源码 项目:javify 阅读 17 收藏 0 点赞 0 评论 0
/**
 * 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));

}
PlainSocketImpl.java 文件源码 项目:jvm-stm 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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));

}
PlainSocketImpl.java 文件源码 项目:In-the-Box-Fork 阅读 20 收藏 0 点赞 0 评论 0
@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
    }
}
SocketImplHookFactory.java 文件源码 项目:java-socketimpl-hook 阅读 18 收藏 0 点赞 0 评论 0
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;
}
SnifferSocketImplFactoryTest.java 文件源码 项目:sniffy 阅读 20 收藏 0 点赞 0 评论 0
@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();
        }
    }
}
PlainSocketImpl.java 文件源码 项目:JamVM-PH 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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));

}
TestSocketServlet.java 文件源码 项目:appengine-java-vm-runtime 阅读 23 收藏 0 点赞 0 评论 0
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);
}
BDJSockets.java 文件源码 项目:libbluray 阅读 21 收藏 0 点赞 0 评论 0
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);
}
BDJSockets.java 文件源码 项目:libbluray 阅读 21 收藏 0 点赞 0 评论 0
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);
            }
        }
    }
}
BDJSocketFactory.java 文件源码 项目:libbluray 阅读 19 收藏 0 点赞 0 评论 0
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());
    }
}
BDJSocketFactory.java 文件源码 项目:libbluray 阅读 20 收藏 0 点赞 0 评论 0
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;
    }
PlainSocketImpl.java 文件源码 项目:classpath 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 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));

}
SocketTest.java 文件源码 项目:freeVM 阅读 26 收藏 0 点赞 0 评论 0
/**
 * @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);
}
JikesRVMSocketImpl.java 文件源码 项目:HeraJVM 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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");
  }
}
LanternSocketFactory.java 文件源码 项目:Lantern-sdk 阅读 20 收藏 0 点赞 0 评论 0
@Override
public SocketImpl createSocketImpl() {

    Logger.d("Socket Factory", "create");
    LanternSocketImpl socket = new LanternSocketImpl();
    _openSockets.add(socket);
    return socket;
}
LanternSocketImpl.java 文件源码 项目:Lantern-sdk 阅读 23 收藏 0 点赞 0 评论 0
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)
                );
            }
        }
    };
}
NetlibSocketImplFactory.java 文件源码 项目:silvertunnel-ng 阅读 22 收藏 0 点赞 0 评论 0
@Override
public synchronized SocketImpl createSocketImpl()
{
    if (netLayer != null)
    {
        return new NetSocket2SocketImpl(netLayer);
    }
    else
    {
        // prevent network access
        return new InvalidSocketImpl();
    }
}
Platform.java 文件源码 项目:conscrypt 阅读 30 收藏 0 点赞 0 评论 0
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);
    }
}
Platform.java 文件源码 项目:conscrypt 阅读 29 收藏 0 点赞 0 评论 0
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);
    }
}
LocalSocketImpl.java 文件源码 项目:javify 阅读 21 收藏 0 点赞 0 评论 0
protected void accept (SocketImpl impl) throws IOException
{
  if (! (impl instanceof LocalSocketImpl))
    {
      throw new IllegalArgumentException ("not a local socket");
    }
  accept ((LocalSocketImpl) impl);
}
LocalSocketImpl.java 文件源码 项目:jvm-stm 阅读 19 收藏 0 点赞 0 评论 0
protected void accept (SocketImpl impl) throws IOException
{
  if (! (impl instanceof LocalSocketImpl))
    {
      throw new IllegalArgumentException ("not a local socket");
    }
  accept ((LocalSocketImpl) impl);
}
PlainSocketImpl.java 文件源码 项目:j2objc 阅读 20 收藏 0 点赞 0 评论 0
@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);
}
MySocketImplFactory.java 文件源码 项目:mobac 阅读 19 收藏 0 点赞 0 评论 0
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);
}
MySocketImplFactory.java 文件源码 项目:mobac 阅读 20 收藏 0 点赞 0 评论 0
public SocketImpl createSocketImpl() {
    try {
        return new MySocketImpl();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
MySocketImplFactory.java 文件源码 项目:mobac 阅读 18 收藏 0 点赞 0 评论 0
@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);
    }
}
NetlibSocketImplFactory.java 文件源码 项目:silvertunnel-monteux 阅读 20 收藏 0 点赞 0 评论 0
@Override
public synchronized SocketImpl createSocketImpl()
{
    if (netLayer != null)
    {
        return new NetSocket2SocketImpl(netLayer);
    }
    else
    {
        // prevent network access
        return new InvalidSocketImpl();
    }
}
ProcessInfo.java 文件源码 项目:reflow 阅读 19 收藏 0 点赞 0 评论 0
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();
    }
}
ProcessInfo.java 文件源码 项目:reflow 阅读 21 收藏 0 点赞 0 评论 0
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!");
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号