3 /* Copyright (C) 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 * @author Per Bothner <bothner@cygnus.com>
13 * @date January 6, 1999.
16 /** Written using on-line Java Platform 1.2 API Specification.
17 * Status: I believe all methods are implemented.
23 public class ServerSocket
25 static SocketImplFactory factory;
28 public ServerSocket (int port)
29 throws java.io.IOException
34 public ServerSocket (int port, int backlog)
35 throws java.io.IOException
37 this(port, backlog, InetAddress.getLocalHost());
40 public ServerSocket (int port, int backlog, InetAddress bindAddr)
41 throws java.io.IOException
44 this.impl = new PlainSocketImpl();
46 this.impl = factory.createSocketImpl();
47 SecurityManager s = System.getSecurityManager();
51 impl.bind(bindAddr, port);
55 public InetAddress getInetAddress()
57 return impl.getInetAddress();
60 public int getLocalPort()
62 return impl.getLocalPort();
65 public Socket accept () throws IOException
67 Socket s = new Socket(Socket.factory == null ? new PlainSocketImpl()
68 : Socket.factory.createSocketImpl());
73 protected final void implAccept (Socket s) throws IOException
78 public void close () throws IOException
83 public synchronized void setSoTimeout (int timeout) throws SocketException
86 throw new IllegalArgumentException("Invalid timeout: " + timeout);
88 impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
91 public synchronized int getSoTimeout () throws SocketException
93 Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
94 if (timeout instanceof Integer)
95 return ((Integer)timeout).intValue();
100 public String toString ()
102 return "ServerSocket" + impl.toString();
105 public static synchronized void setSocketFactory (SocketImplFactory fac)