aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/net/ServerSocket.java
blob: e4b50693e750745a252ef4ab0a8691e37545cabf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Socket.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, but many
  * of them just throw an exception.
  */

package java.net;
import java.io.*;

public class ServerSocket
{
  static SocketImplFactory factory;
  SocketImpl impl;

  public ServerSocket (int port)
    throws java.io.IOException
  {
    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 void setSoTimeout (int timeout) throws SocketException
  {
    throw new InternalError("ServerSocket.setSoTimeout not implemented");
  }

  public int getSoTimeout () throws SocketException
  {
    throw new InternalError("ServerSocket.getSoTimeout not implemented");
  }

  public String toString ()
  {
    return impl.toString();
  }

  public static void setSocketImplFactory (SocketImplFactory fac)
    throws IOException
  {
    factory = fac;
  }

}