gcc/libjava/java/net/ServerSocket.java

540 lines
15 KiB
Java
Raw Normal View History

/* ServerSocket.java -- Class for implementing server side sockets
Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
1999-04-07 16:42:40 +02:00
This file is part of GNU Classpath.
1999-04-07 16:42:40 +02:00
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
1999-04-07 16:42:40 +02:00
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
1999-04-07 16:42:40 +02:00
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
1999-04-07 16:42:40 +02:00
1999-04-07 16:42:40 +02:00
package java.net;
import gnu.java.net.PlainSocketImpl;
import java.io.IOException;
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.ServerSocketChannel;
/* Written using on-line Java Platform 1.2 API Specification.
* Status: I believe all methods are implemented.
*/
/**
* This class models server side sockets. The basic model is that the
* server socket is created and bound to some well known port. It then
* listens for and accepts connections. At that point the client and
* server sockets are ready to communicate with one another utilizing
* whatever application layer protocol they desire.
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
*
* As with the <code>Socket</code> class, most instance methods of this class
* simply redirect their calls to an implementation class.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Per Bothner (bothner@cygnus.com)
*/
1999-04-07 16:42:40 +02:00
public class ServerSocket
{
/**
* This is the user defined SocketImplFactory, if one is supplied
*/
private static SocketImplFactory factory;
/**
* This is the SocketImp object to which most instance methods in this
* class are redirected
*/
private SocketImpl impl;
private boolean closed = false;
/*
* This constructor is only used by java.nio.
*/
// FIXME: Workaround a bug in gcj.
//ServerSocket (PlainSocketImpl impl) throws IOException
ServerSocket (SocketImpl impl) throws IOException
{
this.impl = impl;
this.impl.create (true);
}
/*
* This method is only used by java.nio.
*/
// FIXME: Workaround a bug in gcj.
//PlainSocketImpl getImpl()
SocketImpl getImpl()
{
return impl;
}
/**
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* Constructor that simply sets the implementation.
*
* @exception IOException If an error occurs
*
* @specnote This constructor is public since JDK 1.4
*/
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
public ServerSocket() throws IOException
{
if (factory != null)
impl = factory.createSocketImpl();
else
impl = new PlainSocketImpl();
impl.create(true);
}
/**
* Creates a server socket and binds it to the specified port. If the
* port number is 0, a random free port will be chosen. The pending
* connection queue on this socket will be set to 50.
*
* @param port The port number to bind to
*
* @exception IOException If an error occurs
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation
*/
1999-04-07 16:42:40 +02:00
public ServerSocket (int port)
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
throws IOException
1999-04-07 16:42:40 +02:00
{
this(port, 50);
1999-04-07 16:42:40 +02:00
}
/**
* Creates a server socket and binds it to the specified port. If the
* port number is 0, a random free port will be chosen. The pending
* connection queue on this socket will be set to the value passed as
* arg2.
*
* @param port The port number to bind to
* @param backlog The length of the pending connection queue
*
* @exception IOException If an error occurs
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation
*/
1999-04-07 16:42:40 +02:00
public ServerSocket (int port, int backlog)
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
throws IOException
1999-04-07 16:42:40 +02:00
{
this(port, backlog, null);
1999-04-07 16:42:40 +02:00
}
/**
* Creates a server socket and binds it to the specified port. If the
* port number is 0, a random free port will be chosen. The pending
* connection queue on this socket will be set to the value passed as
* backlog. The third argument specifies a particular local address to
* bind t or null to bind to all local address.
*
* @param port The port number to bind to
* @param backlog The length of the pending connection queue
* @param bindAddr The address to bind to, or null to bind to all addresses
*
* @exception IOException If an error occurs
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation
*
* @since 1.1
*/
1999-04-07 16:42:40 +02:00
public ServerSocket (int port, int backlog, InetAddress bindAddr)
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
throws IOException
1999-04-07 16:42:40 +02:00
{
this();
// bind/listen socket
bind (new InetSocketAddress (bindAddr, port), backlog);
1999-04-07 16:42:40 +02:00
}
/**
* Binds the server socket to a specified socket address
*
* @param endpoint The socket address to bind to
*
* @exception IOException If an error occurs
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* @exception IllegalArgumentException If address type is not supported
* @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation
*
* @since 1.4
*/
public void bind (SocketAddress endpoint)
throws IOException
{
bind (endpoint, 50);
}
/**
* Binds the server socket to a specified socket address
*
* @param endpoint The socket address to bind to
* @param backlog The length of the pending connection queue
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
*
* @exception IOException If an error occurs
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* @exception IllegalArgumentException If address type is not supported
* @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation
*
* @since 1.4
*/
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
public void bind (SocketAddress endpoint, int backlog) throws IOException
{
if (closed)
throw new SocketException ("ServerSocket is closed");
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ("Address type not supported");
InetSocketAddress tmp = (InetSocketAddress) endpoint;
SecurityManager s = System.getSecurityManager ();
if (s != null)
s.checkListen (tmp.getPort ());
try
{
impl.bind (tmp.getAddress (), tmp.getPort ());
impl.listen(backlog);
}
catch (IOException exception)
{
close();
throw exception;
}
catch (RuntimeException exception)
{
close();
throw exception;
}
catch (Error error)
{
close();
throw error;
}
}
/**
* This method returns the local address to which this socket is bound
*
* @return The socket's local address
*/
1999-04-07 16:42:40 +02:00
public InetAddress getInetAddress()
{
try
{
return (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR);
}
catch (SocketException e)
{
return null;
}
1999-04-07 16:42:40 +02:00
}
/**
* This method returns the local port number to which this socket is bound
*
* @return The socket's port number
*/
1999-04-07 16:42:40 +02:00
public int getLocalPort()
{
return impl.getLocalPort();
}
/**
* Returns the local socket address
*
* @since 1.4
*/
public SocketAddress getLocalSocketAddress()
{
InetAddress addr = getInetAddress();
if (addr != null)
return new InetSocketAddress (getInetAddress(), getLocalPort());
return null;
}
/**
* Accepts a new connection and returns a connected <code>Socket</code>
* instance representing that connection. This method will block until a
* connection is available.
*
* @exception IOException If an error occurs
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* @exception SecurityException If a security manager exists and its
* checkListen method doesn't allow the operation
* @exception IllegalBlockingModeException If this socket has an associated
* channel, and the channel is in non-blocking mode
* @exception SocketTimeoutException If a timeout was previously set with
* setSoTimeout and the timeout has been reached
*/
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
public Socket accept () throws IOException
1999-04-07 16:42:40 +02:00
{
SecurityManager sm = System.getSecurityManager ();
if (sm != null)
sm.checkListen (impl.getLocalPort ());
Socket s = new Socket();
1999-04-07 16:42:40 +02:00
implAccept (s);
1999-04-07 16:42:40 +02:00
return s;
}
/**
* This protected method is used to help subclasses override
* <code>ServerSocket.accept()</code>. The passed in socket will be
* connected when this method returns.
*
* @param socket The socket that is used for the accepted connection
*
* @exception IOException If an error occurs
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* @exception IllegalBlockingModeException If this socket has an associated
* channel, and the channel is in non-blocking mode
*
* @since 1.1
*/
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
protected final void implAccept (Socket s)
throws IOException
1999-04-07 16:42:40 +02:00
{
if (getChannel() != null
&& !getChannel().isBlocking())
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
throw new IllegalBlockingModeException();
1999-04-07 16:42:40 +02:00
impl.accept(s.impl);
}
/**
* Closes this socket and stops listening for connections
*
* @exception IOException If an error occurs
*/
1999-04-07 16:42:40 +02:00
public void close () throws IOException
{
impl.close ();
if (getChannel() != null)
getChannel().close ();
closed = true;
1999-04-07 16:42:40 +02:00
}
/**
* Returns the unique ServerSocketChannel object
* associated with this socket, if any.
*
* The socket only has a ServerSocketChannel if its created
* by ServerSocketChannel.open.
*
* @since 1.4
*/
public ServerSocketChannel getChannel()
{
return null;
}
/**
* Returns true then the socket is bound, otherwise false
*
* @since 1.4
*/
public boolean isBound()
{
try
{
Object bindaddr = impl.getOption (SocketOptions.SO_BINDADDR);
}
catch (SocketException e)
{
return false;
}
return true;
}
/**
* Returns true if the socket is closed, otherwise false
*
* @since 1.4
*/
public boolean isClosed()
{
return closed;
}
/**
* Sets the value of SO_TIMEOUT. A value of 0 implies that SO_TIMEOUT is
* disabled (ie, operations never time out). This is the number of
* milliseconds a socket operation can block before an
* InterruptedIOException is thrown.
*
* @param timeout The new SO_TIMEOUT value
*
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* @exception SocketException If an error occurs
*
* @since 1.1
*/
public void setSoTimeout (int timeout) throws SocketException
1999-04-07 16:42:40 +02:00
{
[multiple changes] 1999-05-26 Bryce McKinlay <bryce@albatross.co.nz> * java/net/DatagramSocket.java (getSoTimeout): Verify class type. * java/net/DatagramSocketImpl.java (getOption): Made abstract. (setOption): Made abstract. * java/net/PlainDatagramSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/PlainSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/ServerSocket.java (toString): Prepended "ServerSocket". * java/net/Socket.java (getLocalAddress): Implemented. (setTcpNoDelay): Implemented. (getTcpNoDelay): Implemented. (setSoLinger): Implemented. (getSoLinger): Implemented. (getSoTimeout): Verify class type. (setSendBufferSize): Implemented. (getSendBufferSize): Implemented. (setReceiveBufferSize): Implemented. (getReceiveBufferSize): Implemented. (toString): Prepended "Socket". * java/net/SocketImpl.java (toString): Rewritten. (getOption): Made abstract. (setOption): Made abstract. * java/net/natPlainSocketImpl.cc (connect): Set localport properly. (setOption): Implemented. (getOption): Implemented. 1999-05-26 Warren Levy <warrenl@cygnus.com> * java/net/DatagramSocket.java (DatagramSocket): Get local host address when null. Set SO_REUSEADDR for multicasts. (getSoTimeout): Implemented. (setSoTimeout): Implemented. * java/net/DatagramSocketImpl.java: Implement SocketOptions interface. * java/net/MulticastSocket.java (getInterface): Implemented. (setInterface): Implemented. (setTimeToLive): Check for invalid ttl. (joinGroup): Verify multicast address and security. (leaveGroup): Verify multicast address and security. (send): Implemented. * java/net/PlainDatagramSocketImpl.java (timeout): Added. (iface): Added. (ttl): Added. (setOption): Added. (getOption): Added. (mcastGrp): Added. (getTTL): Implemented as non-native. (setTTL): ditto. (join): ditto. (leave): ditto. * java/net/ServerSocket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (setSocketFactory): Made synchronized. * java/net/Socket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (close): Made synchronized. (setSocketImplFactory): Made synchronized. * java/net/SocketImpl.java: Implement SocketOptions interface. * java/net/natInetAddress.cc: Corrected module name at top of file. * java/net/natPlainDatagramSocketImpl.cc (McastReq): Added union. (bind): Added FIXME. (peek): Implemented. (setTTL): Removed. (getTTL): Removed. (join): Removed. (leave): Removed. (mcastGrp): Added. (setOption): Implemented for SO_REUSEADDR. (getOption): Implemented for SO_REUSEADDR. From-SVN: r27184
1999-05-26 19:00:06 +02:00
if (timeout < 0)
throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0");
[multiple changes] 1999-05-26 Bryce McKinlay <bryce@albatross.co.nz> * java/net/DatagramSocket.java (getSoTimeout): Verify class type. * java/net/DatagramSocketImpl.java (getOption): Made abstract. (setOption): Made abstract. * java/net/PlainDatagramSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/PlainSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/ServerSocket.java (toString): Prepended "ServerSocket". * java/net/Socket.java (getLocalAddress): Implemented. (setTcpNoDelay): Implemented. (getTcpNoDelay): Implemented. (setSoLinger): Implemented. (getSoLinger): Implemented. (getSoTimeout): Verify class type. (setSendBufferSize): Implemented. (getSendBufferSize): Implemented. (setReceiveBufferSize): Implemented. (getReceiveBufferSize): Implemented. (toString): Prepended "Socket". * java/net/SocketImpl.java (toString): Rewritten. (getOption): Made abstract. (setOption): Made abstract. * java/net/natPlainSocketImpl.cc (connect): Set localport properly. (setOption): Implemented. (getOption): Implemented. 1999-05-26 Warren Levy <warrenl@cygnus.com> * java/net/DatagramSocket.java (DatagramSocket): Get local host address when null. Set SO_REUSEADDR for multicasts. (getSoTimeout): Implemented. (setSoTimeout): Implemented. * java/net/DatagramSocketImpl.java: Implement SocketOptions interface. * java/net/MulticastSocket.java (getInterface): Implemented. (setInterface): Implemented. (setTimeToLive): Check for invalid ttl. (joinGroup): Verify multicast address and security. (leaveGroup): Verify multicast address and security. (send): Implemented. * java/net/PlainDatagramSocketImpl.java (timeout): Added. (iface): Added. (ttl): Added. (setOption): Added. (getOption): Added. (mcastGrp): Added. (getTTL): Implemented as non-native. (setTTL): ditto. (join): ditto. (leave): ditto. * java/net/ServerSocket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (setSocketFactory): Made synchronized. * java/net/Socket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (close): Made synchronized. (setSocketImplFactory): Made synchronized. * java/net/SocketImpl.java: Implement SocketOptions interface. * java/net/natInetAddress.cc: Corrected module name at top of file. * java/net/natPlainDatagramSocketImpl.cc (McastReq): Added union. (bind): Added FIXME. (peek): Implemented. (setTTL): Removed. (getTTL): Removed. (join): Removed. (leave): Removed. (mcastGrp): Added. (setOption): Implemented for SO_REUSEADDR. (getOption): Implemented for SO_REUSEADDR. From-SVN: r27184
1999-05-26 19:00:06 +02:00
impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
1999-04-07 16:42:40 +02:00
}
/**
* Retrieves the current value of the SO_TIMEOUT setting. A value of 0
* implies that SO_TIMEOUT is disabled (ie, operations never time out).
* This is the number of milliseconds a socket operation can block before
* an InterruptedIOException is thrown.
*
* @return The value of SO_TIMEOUT
*
* @exception IOException If an error occurs
*
* @since 1.1
*/
public int getSoTimeout () throws IOException
1999-04-07 16:42:40 +02:00
{
[multiple changes] 1999-05-26 Bryce McKinlay <bryce@albatross.co.nz> * java/net/DatagramSocket.java (getSoTimeout): Verify class type. * java/net/DatagramSocketImpl.java (getOption): Made abstract. (setOption): Made abstract. * java/net/PlainDatagramSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/PlainSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/ServerSocket.java (toString): Prepended "ServerSocket". * java/net/Socket.java (getLocalAddress): Implemented. (setTcpNoDelay): Implemented. (getTcpNoDelay): Implemented. (setSoLinger): Implemented. (getSoLinger): Implemented. (getSoTimeout): Verify class type. (setSendBufferSize): Implemented. (getSendBufferSize): Implemented. (setReceiveBufferSize): Implemented. (getReceiveBufferSize): Implemented. (toString): Prepended "Socket". * java/net/SocketImpl.java (toString): Rewritten. (getOption): Made abstract. (setOption): Made abstract. * java/net/natPlainSocketImpl.cc (connect): Set localport properly. (setOption): Implemented. (getOption): Implemented. 1999-05-26 Warren Levy <warrenl@cygnus.com> * java/net/DatagramSocket.java (DatagramSocket): Get local host address when null. Set SO_REUSEADDR for multicasts. (getSoTimeout): Implemented. (setSoTimeout): Implemented. * java/net/DatagramSocketImpl.java: Implement SocketOptions interface. * java/net/MulticastSocket.java (getInterface): Implemented. (setInterface): Implemented. (setTimeToLive): Check for invalid ttl. (joinGroup): Verify multicast address and security. (leaveGroup): Verify multicast address and security. (send): Implemented. * java/net/PlainDatagramSocketImpl.java (timeout): Added. (iface): Added. (ttl): Added. (setOption): Added. (getOption): Added. (mcastGrp): Added. (getTTL): Implemented as non-native. (setTTL): ditto. (join): ditto. (leave): ditto. * java/net/ServerSocket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (setSocketFactory): Made synchronized. * java/net/Socket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (close): Made synchronized. (setSocketImplFactory): Made synchronized. * java/net/SocketImpl.java: Implement SocketOptions interface. * java/net/natInetAddress.cc: Corrected module name at top of file. * java/net/natPlainDatagramSocketImpl.cc (McastReq): Added union. (bind): Added FIXME. (peek): Implemented. (setTTL): Removed. (getTTL): Removed. (join): Removed. (leave): Removed. (mcastGrp): Added. (setOption): Implemented for SO_REUSEADDR. (getOption): Implemented for SO_REUSEADDR. From-SVN: r27184
1999-05-26 19:00:06 +02:00
Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
if (!(timeout instanceof Integer))
throw new IOException("Internal Error");
return ((Integer)timeout).intValue();
1999-04-07 16:42:40 +02:00
}
/**
* Enables/Disables the SO_REUSEADDR option
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public void setReuseAddress (boolean on)
throws SocketException
{
impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on));
}
/**
* Checks if the SO_REUSEADDR option is enabled
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public boolean getReuseAddress()
throws SocketException
{
Object reuseaddr = impl.getOption (SocketOptions.SO_REUSEADDR);
if (!(reuseaddr instanceof Boolean))
throw new SocketException ("Internal Error");
return ((Boolean) reuseaddr).booleanValue ();
}
/**
* This method sets the value for the system level socket option
* SO_RCVBUF to the specified value. Note that valid values for this
* option are specific to a given operating system.
*
* @param size The new receive buffer size.
*
* @exception SocketException If an error occurs or Socket is not connected
2002-09-25 Michael Koch <konqueror@gmx.de> * java/net/DatagramSocket.java (DatagramSocket): Exception documentation added. (bind): Exception documentation added, addded SecurityManager check, added SocketAddress type check. (getSoTimeout): Check impl. (receive): Fix SecurityManager check, check impl, documentation added. (send): Check channel mode, documentation added. (connect): New method. (disconnect): Implemented. (getLocalSocketAddress): New method. (getReceiveBufferSize): Check impl. (setReuseAddress): Check impl. (getReuseAddress): Check impl. (setBroadcast): Check impl. (getBroadcast): Check impl. (setTrafficClass): Check impl, Documentation cleared. (getTrafficClass): Check impl. (getSendBufferSize): Check impl. (setReceiveBufferSize): Check impl, documentation added. (setSendBufferSize): Documentation added. (setDatagramSocketImplFactory): New method. * java/net/HttpURLConnection.java (HTTP_INTERNAL_ERROR): The correct code is 500. (HTTP_NOT_IMPLEMENTED): Added new constant. (setFollowRedirects): Documentation added. (getInstanceFollowRedirects): New method. (setInstanceFollowRedirects): New method. (setRequestMethod): Documentation added. (getResponseCode): Documentation added. (getResponseMessage): Documentation added. * java/net/JarURLConnection.java (JarURLConnection): protected since JDK 1.4. (getJarEntry): java.io.IOException to IOException, documentation added. (getJarFile): Documentation added. * java/net/ServerSocket.java (ServerSocket): Private to public, exception added. (ServerSocket): java.io.IOException to IOException, documentation added. (bind): Check socket address type, documentation added. (bind): java.io.IOException to IOException, documentation added. (accept): Documentation added. (implAccept): Check ch is not non-blocking, documentation added. (setSoTimeout): Documentation fixed. (setReceiveBufferSize): Documentation added. * java/net/Socket.java (Socket): Documentation added. (bind): Documentation added. (connect): Check socket address type, documentation added. (getRemoteSocketAddress): New method. From-SVN: r57494
2002-09-25 11:05:53 +02:00
* @exception IllegalArgumentException If size is 0 or negative
*
* @since 1.4
*/
public void setReceiveBufferSize (int size)
throws SocketException
{
if (size <= 0)
throw new IllegalArgumentException ("SO_RCVBUF value must be > 0");
impl.setOption (SocketOptions.SO_RCVBUF, new Integer (size));
}
/**
* 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.4
*/
public int getReceiveBufferSize ()
throws SocketException
{
Object buf = impl.getOption (SocketOptions.SO_RCVBUF);
if (!(buf instanceof Integer))
throw new SocketException ("Internal Error: Unexpected type");
return ((Integer) buf).intValue ();
}
/**
* Returns the value of this socket as a <code>String</code>.
*
* @return This socket represented as a <code>String</code>.
*/
1999-04-07 16:42:40 +02:00
public String toString ()
{
return "ServerSocket" + impl.toString();
1999-04-07 16:42:40 +02:00
}
// Class methods
/**
* Sets the <code>SocketImplFactory</code> for all
* <code>ServerSocket</code>'s. This may only be done
* once per virtual machine. Subsequent attempts will generate an
* exception. Note that a <code>SecurityManager</code> check is made prior
* to setting the factory. If insufficient privileges exist to set the
* factory, an exception will be thrown
*
* @exception SecurityException If this operation is not allowed by the
* <code>SecurityManager</code>.
* @exception SocketException If the factory object is already defined
* @exception IOException If any other error occurs
*/
[multiple changes] 1999-05-26 Bryce McKinlay <bryce@albatross.co.nz> * java/net/DatagramSocket.java (getSoTimeout): Verify class type. * java/net/DatagramSocketImpl.java (getOption): Made abstract. (setOption): Made abstract. * java/net/PlainDatagramSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/PlainSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/ServerSocket.java (toString): Prepended "ServerSocket". * java/net/Socket.java (getLocalAddress): Implemented. (setTcpNoDelay): Implemented. (getTcpNoDelay): Implemented. (setSoLinger): Implemented. (getSoLinger): Implemented. (getSoTimeout): Verify class type. (setSendBufferSize): Implemented. (getSendBufferSize): Implemented. (setReceiveBufferSize): Implemented. (getReceiveBufferSize): Implemented. (toString): Prepended "Socket". * java/net/SocketImpl.java (toString): Rewritten. (getOption): Made abstract. (setOption): Made abstract. * java/net/natPlainSocketImpl.cc (connect): Set localport properly. (setOption): Implemented. (getOption): Implemented. 1999-05-26 Warren Levy <warrenl@cygnus.com> * java/net/DatagramSocket.java (DatagramSocket): Get local host address when null. Set SO_REUSEADDR for multicasts. (getSoTimeout): Implemented. (setSoTimeout): Implemented. * java/net/DatagramSocketImpl.java: Implement SocketOptions interface. * java/net/MulticastSocket.java (getInterface): Implemented. (setInterface): Implemented. (setTimeToLive): Check for invalid ttl. (joinGroup): Verify multicast address and security. (leaveGroup): Verify multicast address and security. (send): Implemented. * java/net/PlainDatagramSocketImpl.java (timeout): Added. (iface): Added. (ttl): Added. (setOption): Added. (getOption): Added. (mcastGrp): Added. (getTTL): Implemented as non-native. (setTTL): ditto. (join): ditto. (leave): ditto. * java/net/ServerSocket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (setSocketFactory): Made synchronized. * java/net/Socket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (close): Made synchronized. (setSocketImplFactory): Made synchronized. * java/net/SocketImpl.java: Implement SocketOptions interface. * java/net/natInetAddress.cc: Corrected module name at top of file. * java/net/natPlainDatagramSocketImpl.cc (McastReq): Added union. (bind): Added FIXME. (peek): Implemented. (setTTL): Removed. (getTTL): Removed. (join): Removed. (leave): Removed. (mcastGrp): Added. (setOption): Implemented for SO_REUSEADDR. (getOption): Implemented for SO_REUSEADDR. From-SVN: r27184
1999-05-26 19:00:06 +02:00
public static synchronized void setSocketFactory (SocketImplFactory fac)
1999-04-07 16:42:40 +02:00
throws IOException
{
factory = fac;
}
}