Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: mindbright/ssh/SSHServerSocket.java


1   /******************************************************************************
2    *
3    * Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
4    *                 www.mindbright.se, info@mindbright.se
5    *
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   *****************************************************************************
17   * $Author: nallen $
18   * $Date: 2001/11/12 16:31:22 $
19   * $Name:  $
20   *****************************************************************************/
21  package mindbright.ssh;
22  
23  import java.net.*;
24  import java.io.*;
25  
26  public class SSHServerSocket {
27    //
28    // !!! Can't extend ServerSocket since it's not intended to be used
29    // in this way... (i.e. it's only for a "vm-global" switch of
30    // socket-implementation)
31    //
32    // If we extend ServerSocket we waste a local port for each remote
33    // port we listen to, this is perhaps not too bad, BUT since applets
34    // can't listen to local sockets we are doomed if we want to use it
35    // in one... There is not much gain in extension here, I can't think
36    // of a real case where it would really matter.
37    //
38    public static final int DEFAULT_BACKLOG = 25;
39  
40    protected SSHSocketFactory factory;
41    protected SSHSocketImpl    impl;
42  
43    protected SSHServerSocket(SSHSocketImpl impl) {
44      this.impl = impl;
45    }
46  
47    protected void finalize() throws IOException {
48      impl.close();
49    }
50  
51    protected void setSocketFactory(SSHSocketFactory factory) {
52      this.factory = factory;
53    }
54  
55    public InetAddress getInetAddress() {
56      return impl.getInetAddress();
57    }
58  
59    protected int getLocalPort() {
60      return impl.getLocalPort();
61    }
62  
63    public SSHSocket accept() throws IOException {
64      SSHSocketImpl aImpl = factory.createSocketImpl(impl.client, false);
65      SSHSocket     aSock;
66  
67      impl.accept(aImpl);
68      aSock = new SSHSocket(aImpl);
69  
70      return aSock;
71    }
72  
73    public void close() throws IOException {
74      impl.close();
75    }
76  
77    public synchronized void setSoTimeout(int timeout) throws SocketException {
78      impl.setOption(SSHSocketImpl.SO_TIMEOUT, new Integer(timeout));
79    }
80  
81    public synchronized int getSoTimeout() throws IOException {
82      Object o = impl.getOption(SSHSocketImpl.SO_TIMEOUT);
83      /* extra type safety */
84      if (o instanceof Integer) {
85        return ((Integer) o).intValue();
86      } else {
87        return 0;
88      }
89    }
90  
91    public String toString() {
92      return "ServerSocket[addr=" + impl.getInetAddress() +
93        ",port=" + impl.getPort() +
94        ",localport=" + impl.getLocalPort()  + "]";
95    }
96  
97  }