当前位置: 首页>>代码示例>>Java>>正文


Java SocketImpl类代码示例

本文整理汇总了Java中java.net.SocketImpl的典型用法代码示例。如果您正苦于以下问题:Java SocketImpl类的具体用法?Java SocketImpl怎么用?Java SocketImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SocketImpl类属于java.net包,在下文中一共展示了SocketImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printSockets

import java.net.SocketImpl; //导入依赖的package包/类
@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"));
	}
}
 
开发者ID:aragozin,项目名称:heapunit,代码行数:25,代码来源:DumpSocketsExample.java

示例2: accept

import java.net.SocketImpl; //导入依赖的package包/类
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();
        }
    }

}
 
开发者ID:TeamThresh,项目名称:Lantern-sdk,代码行数:17,代码来源:LanternSocketImpl.java

示例3: accept

import java.net.SocketImpl; //导入依赖的package包/类
/**
 * 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));

}
 
开发者ID:vilie,项目名称:javify,代码行数:24,代码来源:PlainSocketImpl.java

示例4: accept

import java.net.SocketImpl; //导入依赖的package包/类
/**
 * 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));

}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:24,代码来源:PlainSocketImpl.java

示例5: accept

import java.net.SocketImpl; //导入依赖的package包/类
@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
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:PlainSocketImpl.java

示例6: createSocketImpl

import java.net.SocketImpl; //导入依赖的package包/类
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;
}
 
开发者ID:kkkon,项目名称:java-socketimpl-hook,代码行数:18,代码来源:SocketImplHookFactory.java

示例7: createSocketImpl

import java.net.SocketImpl; //导入依赖的package包/类
@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();
        }
    }
}
 
开发者ID:sniffy,项目名称:sniffy,代码行数:27,代码来源:SnifferSocketImplFactoryTest.java

示例8: testSetSocketImpl

import java.net.SocketImpl; //导入依赖的package包/类
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);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:19,代码来源:TestSocketServlet.java

示例9: add

import java.net.SocketImpl; //导入依赖的package包/类
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);
}
 
开发者ID:ShiftMediaProject,项目名称:libbluray,代码行数:23,代码来源:BDJSockets.java

示例10: closeAll

import java.net.SocketImpl; //导入依赖的package包/类
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);
            }
        }
    }
}
 
开发者ID:ShiftMediaProject,项目名称:libbluray,代码行数:17,代码来源:BDJSockets.java

示例11: newSocket

import java.net.SocketImpl; //导入依赖的package包/类
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());
    }
}
 
开发者ID:ShiftMediaProject,项目名称:libbluray,代码行数:17,代码来源:BDJSocketFactory.java

示例12: createSocketImpl

import java.net.SocketImpl; //导入依赖的package包/类
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;
    }
 
开发者ID:ShiftMediaProject,项目名称:libbluray,代码行数:18,代码来源:BDJSocketFactory.java

示例13: test_setKeepAliveZ

import java.net.SocketImpl; //导入依赖的package包/类
/**
 * @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);
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:21,代码来源:SocketTest.java

示例14: boot

import java.net.SocketImpl; //导入依赖的package包/类
/**
 * 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");
  }
}
 
开发者ID:rmcilroy,项目名称:HeraJVM,代码行数:21,代码来源:JikesRVMSocketImpl.java

示例15: createSocketImpl

import java.net.SocketImpl; //导入依赖的package包/类
@Override
public SocketImpl createSocketImpl() {

    Logger.d("Socket Factory", "create");
    LanternSocketImpl socket = new LanternSocketImpl();
    _openSockets.add(socket);
    return socket;
}
 
开发者ID:TeamThresh,项目名称:Lantern-sdk,代码行数:9,代码来源:LanternSocketFactory.java


注:本文中的java.net.SocketImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。