Java Code Examples for java.net.SocketImpl

The following are top voted examples for showing how to use java.net.SocketImpl. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: heapunit   File: DumpSocketsExample.java   Source Code and License 7 votes vote down vote up
@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"));
	}
}
 
Example 2
Project: Lantern-sdk   File: LanternSocketImpl.java   Source Code and License 6 votes vote down vote up
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();
        }
    }

}
 
Example 3
Project: javify   File: PlainSocketImpl.java   Source Code and License 6 votes vote down vote up
/**
 * 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));

}
 
Example 4
Project: jvm-stm   File: PlainSocketImpl.java   Source Code and License 6 votes vote down vote up
/**
 * 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));

}
 
Example 5
Project: In-the-Box-Fork   File: PlainSocketImpl.java   Source Code and License 6 votes vote down vote up
@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
    }
}
 
Example 6
Project: java-socketimpl-hook   File: SocketImplHookFactory.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 7
Project: sniffy   File: SnifferSocketImplFactoryTest.java   Source Code and License 6 votes vote down vote up
@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();
        }
    }
}
 
Example 8
Project: JamVM-PH   File: PlainSocketImpl.java   Source Code and License 6 votes vote down vote up
/**
 * 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));

}
 
Example 9
Project: appengine-java-vm-runtime   File: TestSocketServlet.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 10
Project: libbluray   File: BDJSockets.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 11
Project: libbluray   File: BDJSockets.java   Source Code and License 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example 12
Project: libbluray   File: BDJSocketFactory.java   Source Code and License 6 votes vote down vote up
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());
    }
}
 
Example 13
Project: libbluray   File: BDJSocketFactory.java   Source Code and License 6 votes vote down vote up
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;
    }
 
Example 14
Project: classpath   File: PlainSocketImpl.java   Source Code and License 6 votes vote down vote up
/**
 * 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));

}
 
Example 15
Project: freeVM   File: SocketTest.java   Source Code and License 6 votes vote down vote up
/**
 * @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);
}
 
Example 16
Project: HeraJVM   File: JikesRVMSocketImpl.java   Source Code and License 6 votes vote down vote up
/**
 * 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");
  }
}
 
Example 17
Project: Lantern-sdk   File: LanternSocketFactory.java   Source Code and License 5 votes vote down vote up
@Override
public SocketImpl createSocketImpl() {

    Logger.d("Socket Factory", "create");
    LanternSocketImpl socket = new LanternSocketImpl();
    _openSockets.add(socket);
    return socket;
}
 
Example 18
Project: Lantern-sdk   File: LanternSocketImpl.java   Source Code and License 5 votes vote down vote up
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)
                );
            }
        }
    };
}
 
Example 19
Project: silvertunnel-ng   File: NetlibSocketImplFactory.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized SocketImpl createSocketImpl()
{
	if (netLayer != null)
	{
		return new NetSocket2SocketImpl(netLayer);
	}
	else
	{
		// prevent network access
		return new InvalidSocketImpl();
	}
}
 
Example 20
Project: conscrypt   File: Platform.java   Source Code and License 5 votes vote down vote up
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);
    }
}
 
Example 21
Project: conscrypt   File: Platform.java   Source Code and License 5 votes vote down vote up
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);
    }
}
 
Example 22
Project: javify   File: LocalSocketImpl.java   Source Code and License 5 votes vote down vote up
protected void accept (SocketImpl impl) throws IOException
{
  if (! (impl instanceof LocalSocketImpl))
    {
      throw new IllegalArgumentException ("not a local socket");
    }
  accept ((LocalSocketImpl) impl);
}
 
Example 23
Project: jvm-stm   File: LocalSocketImpl.java   Source Code and License 5 votes vote down vote up
protected void accept (SocketImpl impl) throws IOException
{
  if (! (impl instanceof LocalSocketImpl))
    {
      throw new IllegalArgumentException ("not a local socket");
    }
  accept ((LocalSocketImpl) impl);
}
 
Example 24
Project: j2objc   File: PlainSocketImpl.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 25
Project: mobac   File: MySocketImplFactory.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 26
Project: mobac   File: MySocketImplFactory.java   Source Code and License 5 votes vote down vote up
public SocketImpl createSocketImpl() {
	try {
		return new MySocketImpl();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 27
Project: mobac   File: MySocketImplFactory.java   Source Code and License 5 votes vote down vote up
@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);
	}
}
 
Example 28
Project: silvertunnel-monteux   File: NetlibSocketImplFactory.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized SocketImpl createSocketImpl()
{
	if (netLayer != null)
	{
		return new NetSocket2SocketImpl(netLayer);
	}
	else
	{
		// prevent network access
		return new InvalidSocketImpl();
	}
}
 
Example 29
Project: reflow   File: ProcessInfo.java   Source Code and License 5 votes vote down vote up
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();
    }
}
 
Example 30
Project: reflow   File: ProcessInfo.java   Source Code and License 5 votes vote down vote up
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!");
    }
}
 
Example 31
Project: evosuite   File: EvoSuiteSocket.java   Source Code and License 5 votes vote down vote up
@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());
	}
}
 
Example 32
Project: In-the-Box-Fork   File: NativeCrypto.java   Source Code and License 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 33
Project: In-the-Box-Fork   File: PlainSocketImpl.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
        }
    });
}
 
Example 34
Project: o5logon-fetch   File: MitMSocketImplFactory.java   Source Code and License 5 votes vote down vote up
@Override
public SocketImpl createSocketImpl() {
	try {
		return new MitMSocketImpl(
				(SocketImpl) plainSocketImplConstructor.newInstance(),
				this
				);
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(1);
	}
	
	return null;
}
 
Example 35
Project: sette-tool   File: TestSuiteRunnerHelper.java   Source Code and License 5 votes vote down vote up
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);
    }
}
 
Example 36
Project: java-socketimpl-hook   File: SocketImplHook.java   Source Code and License 5 votes vote down vote up
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;
        }
    }
 
Example 37
Project: sniffy   File: SnifferSocketImplFactory.java   Source Code and License 5 votes vote down vote up
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;
            }
        }

    }
 
Example 38
Project: cn1   File: PlainSocketImpl.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
        }
    });
}
 
Example 39
Project: cn1   File: SocketTest.java   Source Code and License 5 votes vote down vote up
/**
 * @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);
}
 
Example 40
Project: JamVM-PH   File: LocalSocketImpl.java   Source Code and License 5 votes vote down vote up
protected void accept (SocketImpl impl) throws IOException
{
  if (! (impl instanceof LocalSocketImpl))
    {
      throw new IllegalArgumentException ("not a local socket");
    }
  accept ((LocalSocketImpl) impl);
}
 
Example 41
Project: silvertunnel-monteux   File: NetlibSocketImplFactory.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized SocketImpl createSocketImpl()
{
	if (netLayer != null)
	{
		return new NetSocket2SocketImpl(netLayer);
	}
	else
	{
		// prevent network access
		return new InvalidSocketImpl();
	}
}
 
Example 42
Project: docker-java   File: AFUNIXSocketImpl.java   Source Code and License 5 votes vote down vote up
@Override
protected void accept(SocketImpl socket) throws IOException {
  final AFUNIXSocketImpl si = (AFUNIXSocketImpl) socket;
  NativeUnixSocket.accept(socketFile, fd, si.fd);
  si.socketFile = socketFile;
  si.connected = true;
}
 
Example 43
Project: classpath   File: LocalSocketImpl.java   Source Code and License 5 votes vote down vote up
protected void accept (SocketImpl impl) throws IOException
{
  if (! (impl instanceof LocalSocketImpl))
    {
      throw new IllegalArgumentException ("not a local socket");
    }
  accept ((LocalSocketImpl) impl);
}
 
Example 44
Project: freeVM   File: PlainSocketImpl.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
        }
    });
}
 
Example 45
Project: freeVM   File: PlainSocketImpl.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
        }
    });
}
 
Example 46
Project: freeVM   File: SocketTest.java   Source Code and License 5 votes vote down vote up
/**
 * @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);
}
 
Example 47
Project: netlib   File: NetlibSocketImplFactory.java   Source Code and License 5 votes vote down vote up
public synchronized SocketImpl createSocketImpl() {
    if (netLayer!=null) {
        return new NetSocket2SocketImpl(netLayer);
    } else {
        // prevent network access
        return new InvalidSocketImpl();
    }
}
 
Example 48
Project: cyberduck   File: HttpProxyAwareSocket.java   Source Code and License 4 votes vote down vote up
public HttpProxyAwareSocket(final SocketImpl impl, final Proxy proxy) throws SocketException {
    super(impl);
    this.proxy = proxy;
}
 
Example 49
Project: OpenJSharp   File: Sdp.java   Source Code and License 4 votes vote down vote up
SdpSocket(SocketImpl impl) throws SocketException {
    super(impl);
}
 
Example 50
Project: jdk8u-jdk   File: Sdp.java   Source Code and License 4 votes vote down vote up
SdpSocket(SocketImpl impl) throws SocketException {
    super(impl);
}
 
Example 51
Project: silvertunnel-ng   File: ExtendedSocket.java   Source Code and License 4 votes vote down vote up
/**
 * @param socketImpl
 * @throws SocketException
 */
public ExtendedSocket(final SocketImpl socketImpl) throws SocketException
{
	super(socketImpl);
}
 
Example 52
Project: silvertunnel-ng   File: SocketGlobalUtil.java   Source Code and License 4 votes vote down vote up
/**
 * Create a new Socket with the JDK built-in SocketImpl.
 * <br>
 * The result does not use/depend on a SocketImplFactory set in class
 * Socket.
 *
 * @return a new (Extended)Socket, as it would be created with new Socket()
 * with unset SocketImplFactory
 * @throws RuntimeException if the socket could not be created
 */
@SuppressWarnings("unchecked")
public static ExtendedSocket createOriginalSocket() throws RuntimeException {
    LOG.debug("createOriginalSocket() called here:",
            new Throwable("stacktrace for debugging - not an error"));

    if (netlibSocketImplFactory == null) {
        // SocketImplFactory not yet set (by this class) in class Socket:
        // use default code
        return new ExtendedSocket();
    } else {
        // SocketImplFactory set in class Socket:
        // use specific special and maybe unportable code

        // 1st attempt,
        // this solution works for Java 1.6, but it does break security
        // restrictions:
        try {
            @SuppressWarnings("rawtypes")
            final Class clazz = Class.forName("java.net.SocksSocketImpl");
            @SuppressWarnings("rawtypes")
            final Constructor constructor = clazz.getDeclaredConstructor();
            // this maybe does not work because of security restrictions:
            constructor.setAccessible(true);
            final SocketImpl impl = (SocketImpl) constructor.newInstance();
            return new ExtendedSocket(impl);

        } catch (final Throwable t1) {
            String msg = "createOriginalSocket()#1st attempt: could not create a Socket for Java Version: "
                    + JavaVersion.getJavaVersion();
            LOG.error(msg, t1);

            // 2nd attempt,
            // this solution doen't work for Java 1.6, but it does not break
            // security restrictions:
            try {
                return new ExtendedSocket(new PatchedProxy());

            } catch (final Throwable t2) {
                msg = "createOriginalSocket()#2nd attempt: could not create a Socket for Java Version: "
                        + JavaVersion.getJavaVersion();
                LOG.error(msg + ", " + t2, t2);

                throw new RuntimeException(msg + ", " + t2);
            }
        }
    }
}
 
Example 53
Project: silvertunnel-ng   File: InvalidSocketImpl.java   Source Code and License 4 votes vote down vote up
@Override
protected void accept(final SocketImpl s) throws IOException {
    notImplemented();
}
 
Example 54
Project: jdk8u_jdk   File: Sdp.java   Source Code and License 4 votes vote down vote up
SdpSocket(SocketImpl impl) throws SocketException {
    super(impl);
}
 
Example 55
Project: lookaside_java-1.8.0-openjdk   File: Sdp.java   Source Code and License 4 votes vote down vote up
SdpSocket(SocketImpl impl) throws SocketException {
    super(impl);
}
 
Example 56
Project: drftpd3   File: DummySocket.java   Source Code and License 4 votes vote down vote up
public DummySocket(SocketImpl impl) {
    throw new UnsupportedOperationException();
}
 
Example 57
Project: namecoinj   File: OrchidSocketImplFactory.java   Source Code and License 4 votes vote down vote up
public SocketImpl createSocketImpl() {
	return new OrchidSocketImpl(torClient);
}
 
Example 58
Project: okserver   File: Handshake.java   Source Code and License 4 votes vote down vote up
HandshakeSocket() throws IOException {
  super((SocketImpl)null);
}
 
Example 59
Project: mobac   File: MySocketImplFactory.java   Source Code and License 4 votes vote down vote up
private MySocketImpl() throws IllegalArgumentException, InstantiationException,
		IllegalAccessException, InvocationTargetException {
	si = (SocketImpl) constructor.newInstance();
	socketId = si.hashCode();
	log.trace("[" + socketId + "] new SocketImpl created");
}
 
Example 60
Project: silvertunnel-monteux   File: NetSocket2SocketImpl.java   Source Code and License 4 votes vote down vote up
@Override
protected void accept(final SocketImpl arg0) throws IOException
{
	logger.warn("method empty/not implemented", new Throwable("method empty/not implemented"));
	// TODO Auto-generated method stub
}