本文整理汇总了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"));
}
}
示例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();
}
}
}
示例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));
}
示例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));
}
示例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
}
}
示例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;
}
示例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();
}
}
}
示例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);
}
示例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);
}
示例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);
}
}
}
}
示例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());
}
}
示例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;
}
示例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);
}
示例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");
}
}
示例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;
}