3 /* Copyright (C) 1999 Free Software Foundation
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 static final byte[] zeros = {0,0,0,0};
29 /* dummy InetAddress, used to bind socket to any (all) network interfaces */
30 static final InetAddress ANY_IF = new InetAddress(zeros, null);
32 public ServerSocket (int port)
33 throws java.io.IOException
38 public ServerSocket (int port, int backlog)
39 throws java.io.IOException
41 this(port, backlog, ANY_IF);
44 public ServerSocket (int port, int backlog, InetAddress bindAddr)
45 throws java.io.IOException
48 this.impl = new PlainSocketImpl();
50 this.impl = factory.createSocketImpl();
51 SecurityManager s = System.getSecurityManager();
55 impl.bind(bindAddr == null ? ANY_IF : bindAddr, port);
59 public InetAddress getInetAddress()
61 return impl.getInetAddress();
64 public int getLocalPort()
66 return impl.getLocalPort();
69 public Socket accept () throws IOException
71 Socket s = new Socket(Socket.factory == null ? new PlainSocketImpl()
72 : Socket.factory.createSocketImpl());
77 protected final void implAccept (Socket s) throws IOException
82 public void close () throws IOException
87 public synchronized void setSoTimeout (int timeout) throws SocketException
90 throw new IllegalArgumentException("Invalid timeout: " + timeout);
92 impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
95 public synchronized int getSoTimeout () throws SocketException
97 Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
98 if (timeout instanceof Integer)
99 return ((Integer)timeout).intValue();
104 public String toString ()
106 return "ServerSocket" + impl.toString();
109 public static synchronized void setSocketFactory (SocketImplFactory fac)