1999-05-26 19:00:06 +02:00
|
|
|
// ServerSocket.java
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
/* 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.
|
1999-05-26 19:00:06 +02:00
|
|
|
* Status: I believe all methods are implemented.
|
1999-04-07 16:42:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package java.net;
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
public class ServerSocket
|
|
|
|
{
|
|
|
|
static SocketImplFactory factory;
|
|
|
|
SocketImpl impl;
|
|
|
|
|
|
|
|
public ServerSocket (int port)
|
|
|
|
throws java.io.IOException
|
|
|
|
{
|
1999-06-17 02:21:26 +02:00
|
|
|
this(port, 50);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ServerSocket (int port, int backlog)
|
|
|
|
throws java.io.IOException
|
|
|
|
{
|
1999-06-17 02:21:26 +02:00
|
|
|
this(port, backlog, null);
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
1999-05-26 19:00:06 +02:00
|
|
|
public synchronized void setSoTimeout (int timeout) throws SocketException
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
1999-05-26 19:00:06 +02:00
|
|
|
if (timeout < 0)
|
|
|
|
throw new IllegalArgumentException("Invalid timeout: " + timeout);
|
|
|
|
|
|
|
|
impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
1999-05-26 19:00:06 +02:00
|
|
|
public synchronized int getSoTimeout () throws SocketException
|
1999-04-07 16:42:40 +02:00
|
|
|
{
|
1999-05-26 19:00:06 +02:00
|
|
|
Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
|
|
|
|
if (timeout instanceof Integer)
|
|
|
|
return ((Integer)timeout).intValue();
|
|
|
|
else
|
|
|
|
return 0;
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String toString ()
|
|
|
|
{
|
1999-05-26 19:00:06 +02:00
|
|
|
return "ServerSocket" + impl.toString();
|
1999-04-07 16:42:40 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|