Пример #1
0
 public boolean getReuseAddr(TcpSocket fan) {
   try {
     return socket.getReuseAddress();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #2
0
 public void setTrafficClass(TcpSocket fan, long v) {
   try {
     socket.setTrafficClass((int) v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #3
0
 public boolean getNoDelay(TcpSocket fan) {
   try {
     return socket.getTcpNoDelay();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #4
0
 public void setSendBufferSize(TcpSocket fan, long v) {
   try {
     socket.setSendBufferSize((int) v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #5
0
 public void setNoDelay(TcpSocket fan, boolean v) {
   try {
     socket.setTcpNoDelay(v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #6
0
 public long getTrafficClass(TcpSocket fan) {
   try {
     return socket.getTrafficClass();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #7
0
 public long getSendBufferSize(TcpSocket fan) {
   try {
     return socket.getSendBufferSize();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #8
0
 public void setKeepAlive(TcpSocket fan, boolean v) {
   try {
     socket.setKeepAlive(v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #9
0
 public boolean getKeepAlive(TcpSocket fan) {
   try {
     return socket.getKeepAlive();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #10
0
 public void shutdownOut(TcpSocket fan) {
   try {
     socket.shutdownOutput();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #11
0
 public void setReuseAddr(TcpSocket fan, boolean v) {
   try {
     socket.setReuseAddress(v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #12
0
 public void setLinger(TcpSocket fan, Duration v) {
   try {
     if (v == null) socket.setSoLinger(false, 0);
     else socket.setSoLinger(true, (int) (v.sec()));
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #13
0
 public void setReceiveTimeout(TcpSocket fan, Duration v) {
   try {
     if (v == null) socket.setSoTimeout(0);
     else socket.setSoTimeout((int) (v.millis()));
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #14
0
 public Duration getReceiveTimeout(TcpSocket fan) {
   try {
     int timeout = socket.getSoTimeout();
     if (timeout <= 0) return null;
     return Duration.makeMillis(timeout);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #15
0
 public Duration getLinger(TcpSocket fan) {
   try {
     int linger = socket.getSoLinger();
     if (linger < 0) return null;
     return Duration.makeSec(linger);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #16
0
 public TcpSocket bind(TcpSocket fan, IpAddr addr, Long port) {
   try {
     InetAddress javaAddr = (addr == null) ? null : addr.peer.java;
     int javaPort = (port == null) ? 0 : port.intValue();
     socket.bind(new InetSocketAddress(javaAddr, javaPort));
     return fan;
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #17
0
 public TcpSocket connect(TcpSocket fan, IpAddr addr, long port, Duration timeout) {
   try {
     // connect
     int javaTimeout = (timeout == null) ? 0 : (int) timeout.millis();
     socket.connect(new InetSocketAddress(addr.peer.java, (int) port), javaTimeout);
     connected(fan);
     return fan;
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Пример #18
0
  public static TcpSocket makeTls(TcpSocket upgrade) {
    try {
      SSLContext sslContext = SSLContext.getInstance("TLS");
      sslContext.init(null, null, null);

      // get SSL factory because Java loves factories!
      SSLSocketFactory factory = sslContext.getSocketFactory();

      // create new SSL socket
      SSLSocket socket;
      if (upgrade == null) {
        socket = (SSLSocket) factory.createSocket();
      }

      // upgrade an existing socket
      else {
        socket =
            (SSLSocket)
                factory.createSocket(
                    upgrade.peer.socket,
                    upgrade.peer.socket.getInetAddress().getHostAddress(),
                    upgrade.peer.socket.getPort(),
                    false);
        socket.setUseClientMode(true);
        socket.startHandshake();
      }

      // create the new TcpSocket instance
      TcpSocket self = new TcpSocket();
      self.peer = new TcpSocketPeer(socket);

      // if upgrade, then initialize socket as already connected
      if (upgrade != null) self.peer.connected(self);

      return self;
    } catch (Exception e) {
      throw IOErr.make(e);
    }
  }
Пример #19
0
 public InStream in(TcpSocket fan) {
   if (in == null) throw IOErr.make("not connected");
   return in;
 }
Пример #20
0
 public OutStream out(TcpSocket fan) {
   if (out == null) throw IOErr.make("not connected");
   return out;
 }