mirror of
git://gcc.gnu.org/git/gcc.git
synced 2024-12-19 16:59:53 +08:00
07515641a5
* java/net/DatagramSocket.java (laddr): Removed. (DatagramSocket): Removed attempts to get or set laddr if null. (getLocalAddress): Reimplemented per spec. * java/net/MulticastSocket.java (setTimeToLive): Throw exception when ttl is 0. (joinGroup): Throw NullPointerException if any argument is null. (leaveGroup): ditto. * java/net/PlainDatagramSocketImpl.java: Updated comments. * java/net/PlainSocketImpl.java (timeout): Added. (getInputStream): Added FIXME comment on how to support timeouts for TCP. * java/net/ServerSocket.java (ServerSocket): Added FIXME comment. * java/net/Socket.java: Added FIXME comments to identify conflicting specs between the JCL and JDK 1.2 documents. * java/net/natPlainDatagramSocketImpl.cc (bind): Use INADDR_ANY if host is null. Get localport value resolved by kernel if bind lport is 0. (receive): Implemented support for timeouts in UDP. (setOption): Implemented based on natPlainSocketImpl version. (getOption): ditto. * java/net/natPlainSocketImpl.cc (bind): Get localport value resolved by kernel if bind lport is 0. (connect): Get localport value resolved by kernel if bind wasn't done to set localport. (accept): Implemented support for timeouts for ServerSocket. (setOption): Save value for SO_TIMEOUT. (getOption): Return timeout for SO_TIMEOUT. From-SVN: r27230
113 lines
2.5 KiB
Java
113 lines
2.5 KiB
Java
// ServerSocket.java
|
|
|
|
/* Copyright (C) 1999 Cygnus Solutions
|
|
|
|
This file is part of libgcj.
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|
details. */
|
|
|
|
/**
|
|
* @author Per Bothner <bothner@cygnus.com>
|
|
* @date January 6, 1999.
|
|
*/
|
|
|
|
/** Written using on-line Java Platform 1.2 API Specification.
|
|
* Status: I believe all methods are implemented.
|
|
*/
|
|
|
|
package java.net;
|
|
import java.io.*;
|
|
|
|
public class ServerSocket
|
|
{
|
|
static SocketImplFactory factory;
|
|
SocketImpl impl;
|
|
|
|
public ServerSocket (int port)
|
|
throws java.io.IOException
|
|
{
|
|
// FIXME: JCL p. 1526 says backlog defaults to 50; is 5 to save space
|
|
// or a typo?
|
|
this(port, 5);
|
|
}
|
|
|
|
public ServerSocket (int port, int backlog)
|
|
throws java.io.IOException
|
|
{
|
|
this(port, backlog, InetAddress.getLocalHost());
|
|
}
|
|
|
|
public ServerSocket (int port, int backlog, InetAddress bindAddr)
|
|
throws java.io.IOException
|
|
{
|
|
if (factory == null)
|
|
this.impl = new PlainSocketImpl();
|
|
else
|
|
this.impl = factory.createSocketImpl();
|
|
SecurityManager s = System.getSecurityManager();
|
|
if (s != null)
|
|
s.checkListen(port);
|
|
impl.create(true);
|
|
impl.bind(bindAddr, port);
|
|
impl.listen(backlog);
|
|
}
|
|
|
|
public InetAddress getInetAddress()
|
|
{
|
|
return impl.getInetAddress();
|
|
}
|
|
|
|
public int getLocalPort()
|
|
{
|
|
return impl.getLocalPort();
|
|
}
|
|
|
|
public Socket accept () throws IOException
|
|
{
|
|
Socket s = new Socket(Socket.factory == null ? new PlainSocketImpl()
|
|
: Socket.factory.createSocketImpl());
|
|
implAccept (s);
|
|
return s;
|
|
}
|
|
|
|
protected final void implAccept (Socket s) throws IOException
|
|
{
|
|
impl.accept(s.impl);
|
|
}
|
|
|
|
public void close () throws IOException
|
|
{
|
|
impl.close();
|
|
}
|
|
|
|
public synchronized void setSoTimeout (int timeout) throws SocketException
|
|
{
|
|
if (timeout < 0)
|
|
throw new IllegalArgumentException("Invalid timeout: " + timeout);
|
|
|
|
impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
|
|
}
|
|
|
|
public synchronized int getSoTimeout () throws SocketException
|
|
{
|
|
Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
|
|
if (timeout instanceof Integer)
|
|
return ((Integer)timeout).intValue();
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
public String toString ()
|
|
{
|
|
return "ServerSocket" + impl.toString();
|
|
}
|
|
|
|
public static synchronized void setSocketFactory (SocketImplFactory fac)
|
|
throws IOException
|
|
{
|
|
factory = fac;
|
|
}
|
|
}
|