/** * Returns the value of the SO_TIMEOUT option on the socket. If this value is set, and an * read/write is performed that does not complete within the timeout period, a short count is * returned (or an EWOULDBLOCK signal would be sent in Unix if no data had been read). A value of * 0 for this option implies that there is no timeout (ie, operations will block forever). On * systems that have separate read and write timeout values, this method returns the read timeout. * This value is in thousandths of a second (implementation specific?). * * @return The length of the timeout in thousandth's of a second or 0 if not set * @exception SocketException If an error occurs or Socket not connected * @since 1.1 */ public synchronized int getSoTimeout() throws SocketException { if (impl == null) throw new SocketException("Not connected"); Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT); if (timeout instanceof Integer) return (((Integer) timeout).intValue()); else return 0; }
/** * Returns the value of the SO_LINGER option on the socket. If the SO_LINGER option is set on a * socket and there is still data waiting to be sent when the socket is closed, then the close * operation will block until either that data is delivered or until the timeout period expires. * This method either returns the timeouts (in hundredths of of a second (platform specific?)) if * SO_LINGER is set, or -1 if SO_LINGER is not set. * * @return The SO_LINGER timeout in hundreths of a second or -1 if SO_LINGER not set * @exception SocketException If an error occurs or Socket is not connected * @since 1.1 */ public int getSoLinger() throws SocketException { if (impl == null) throw new SocketException("Not connected"); Object linger = impl.getOption(SocketOptions.SO_LINGER); if (linger instanceof Integer) return (((Integer) linger).intValue()); else return -1; }
/** * Returns the current traffic class * * @exception SocketException If an error occurs * @see Socket:setTrafficClass * @since 1.4 */ public int getTrafficClass() throws SocketException { if (impl == null) throw new SocketException("Cannot initialize Socket implementation"); Object obj = impl.getOption(SocketOptions.IP_TOS); if (obj instanceof Integer) return ((Integer) obj).intValue(); else throw new SocketException("Unexpected type"); }
/** * This method returns the value of the socket level socket option SO_KEEPALIVE. * * @return The setting * @exception SocketException If an error occurs or Socket is not connected * @since 1.3 */ public boolean getKeepAlive() throws SocketException { if (impl == null) throw new SocketException("Not connected"); Object buf = impl.getOption(SocketOptions.SO_KEEPALIVE); if (buf instanceof Boolean) return (((Boolean) buf).booleanValue()); else throw new SocketException("Internal Error: Unexpected type"); }
/** * This method returns the value of the system level socket option SO_RCVBUF, which is used by the * operating system to tune buffer sizes for data transfers. * * @return The receive buffer size. * @exception SocketException If an error occurs or Socket is not connected * @since 1.2 */ public int getReceiveBufferSize() throws SocketException { if (impl == null) throw new SocketException("Not connected"); Object buf = impl.getOption(SocketOptions.SO_RCVBUF); if (buf instanceof Integer) return (((Integer) buf).intValue()); else throw new SocketException("Internal Error: Unexpected type"); }
/** * Tests whether or not the TCP_NODELAY option is set on the socket. Returns true if enabled, * false if disabled. When on it disables the Nagle algorithm which means that packets are always * send immediatly and never merged together to reduce network trafic. * * @return Whether or not TCP_NODELAY is set * @exception SocketException If an error occurs or Socket not connected * @since 1.1 */ public boolean getTcpNoDelay() throws SocketException { if (impl == null) throw new SocketException("Not connected"); Object on = impl.getOption(SocketOptions.TCP_NODELAY); if (on instanceof Boolean) return (((Boolean) on).booleanValue()); else throw new SocketException("Internal Error"); }
/** * Checks if the SO_REUSEADDR option is enabled * * @exception SocketException If an error occurs * @since 1.4 */ public boolean getReuseAddress() throws SocketException { if (impl == null) throw new SocketException("Cannot initialize Socket implementation"); Object reuseaddr = impl.getOption(SocketOptions.SO_REUSEADDR); if (!(reuseaddr instanceof Boolean)) throw new SocketException("Internal Error"); return ((Boolean) reuseaddr).booleanValue(); }
/** * Returns the local address to which this socket is bound. If this socket is not connected, then * <code>null</code> is returned. * * @return The local address * @since 1.1 */ public InetAddress getLocalAddress() { if (impl == null) return null; InetAddress addr = null; try { addr = (InetAddress) impl.getOption(SocketOptions.SO_BINDADDR); } catch (SocketException e) { // (hopefully) shouldn't happen // throw new java.lang.InternalError // ("Error in PlainSocketImpl.getOption"); return null; } // FIXME: According to libgcj, checkConnect() is supposed to be called // before performing this operation. Problems: 1) We don't have the // addr until after we do it, so we do a post check. 2). The docs I // see don't require this in the Socket case, only DatagramSocket, but // we'll assume they mean both. SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkConnect(addr.getHostName(), getLocalPort()); return addr; }