Ejemplo n.º 1
0
 public boolean getReuseAddr(TcpSocket fan) {
   try {
     return socket.getReuseAddress();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 2
0
 public void setTrafficClass(TcpSocket fan, long v) {
   try {
     socket.setTrafficClass((int) v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 3
0
 public boolean getNoDelay(TcpSocket fan) {
   try {
     return socket.getTcpNoDelay();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 4
0
 public void setSendBufferSize(TcpSocket fan, long v) {
   try {
     socket.setSendBufferSize((int) v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 5
0
 public void setNoDelay(TcpSocket fan, boolean v) {
   try {
     socket.setTcpNoDelay(v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 6
0
 public long getTrafficClass(TcpSocket fan) {
   try {
     return socket.getTrafficClass();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 7
0
 public long getSendBufferSize(TcpSocket fan) {
   try {
     return socket.getSendBufferSize();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 8
0
 public void setKeepAlive(TcpSocket fan, boolean v) {
   try {
     socket.setKeepAlive(v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 9
0
 public boolean getKeepAlive(TcpSocket fan) {
   try {
     return socket.getKeepAlive();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 10
0
 public void shutdownOut(TcpSocket fan) {
   try {
     socket.shutdownOutput();
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 11
0
 public void setReuseAddr(TcpSocket fan, boolean v) {
   try {
     socket.setReuseAddress(v);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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);
   }
 }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 19
0
 public InStream in(TcpSocket fan) {
   if (in == null) throw IOErr.make("not connected");
   return in;
 }
Ejemplo n.º 20
0
 public OutStream out(TcpSocket fan) {
   if (out == null) throw IOErr.make("not connected");
   return out;
 }