Initial revision
[gcc.git] / libjava / java / net / ServerSocket.java
1 // Socket.java
2
3 /* Copyright (C) 1999 Cygnus Solutions
4
5 This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
10
11 /**
12 * @author Per Bothner <bothner@cygnus.com>
13 * @date January 6, 1999.
14 */
15
16 /** Written using on-line Java Platform 1.2 API Specification.
17 * Status: I believe all methods are implemented, but many
18 * of them just throw an exception.
19 */
20
21 package java.net;
22 import java.io.*;
23
24 public class ServerSocket
25 {
26 static SocketImplFactory factory;
27 SocketImpl impl;
28
29 public ServerSocket (int port)
30 throws java.io.IOException
31 {
32 this(port, 5);
33 }
34
35 public ServerSocket (int port, int backlog)
36 throws java.io.IOException
37 {
38 this(port, backlog, InetAddress.getLocalHost());
39 }
40
41 public ServerSocket (int port, int backlog, InetAddress bindAddr)
42 throws java.io.IOException
43 {
44 if (factory == null)
45 this.impl = new PlainSocketImpl();
46 else
47 this.impl = factory.createSocketImpl();
48 SecurityManager s = System.getSecurityManager();
49 if (s != null)
50 s.checkListen(port);
51 impl.create(true);
52 impl.bind(bindAddr, port);
53 impl.listen(backlog);
54 }
55
56 public InetAddress getInetAddress()
57 {
58 return impl.getInetAddress();
59 }
60
61 public int getLocalPort()
62 {
63 return impl.getLocalPort();
64 }
65
66 public Socket accept () throws IOException
67 {
68 Socket s = new Socket(Socket.factory == null ? new PlainSocketImpl()
69 : Socket.factory.createSocketImpl());
70 implAccept (s);
71 return s;
72 }
73
74 protected final void implAccept (Socket s) throws IOException
75 {
76 impl.accept(s.impl);
77 }
78
79 public void close () throws IOException
80 {
81 impl.close();
82 }
83
84 public void setSoTimeout (int timeout) throws SocketException
85 {
86 throw new InternalError("ServerSocket.setSoTimeout not implemented");
87 }
88
89 public int getSoTimeout () throws SocketException
90 {
91 throw new InternalError("ServerSocket.getSoTimeout not implemented");
92 }
93
94 public String toString ()
95 {
96 return impl.toString();
97 }
98
99 public static void setSocketImplFactory (SocketImplFactory fac)
100 throws IOException
101 {
102 factory = fac;
103 }
104
105 }