コード例 #1
0
ファイル: PeerUtils.java プロジェクト: purusharth/CMSC621
  public static void printSocketParameters(Socket cl) throws SocketException {

    boolean SO_KEEPALIVE = cl.getKeepAlive();
    boolean TCP_NODELAY = cl.getTcpNoDelay();

    int SO_LINGER = cl.getSoLinger();
    int SO_TIMEOUT = cl.getSoTimeout();

    int SO_RCVBUF = cl.getReceiveBufferSize();
    int SO_SNDBUF = cl.getSendBufferSize();

    int trafficClassVal = cl.getTrafficClass();
    /*
     		0 <= trafficClassVal <= 255
    	IPTOS_LOWCOST (0x02)
    	IPTOS_RELIABILITY (0x04)
     			IPTOS_THROUGHPUT (0x08)
    	IPTOS_LOWDELAY (0x10)

    */

    int remotePort = cl.getPort();
    int localPort = cl.getLocalPort();
    String localIP = getIPstr(cl.getLocalAddress());
    String remoteIP = getIPstr(cl.getInetAddress());

    System.out.println("Socket Paramaters :");
    System.out.println("SO_KEEPAILVE = " + SO_KEEPALIVE + " TCP_NODELAY = " + TCP_NODELAY);
    System.out.println("SO_LINGER = " + SO_LINGER + "  SO_TIMEOUT = " + SO_TIMEOUT);
    System.out.println("SO_RCVBUF = " + SO_RCVBUF + "  SO_SNDBUF = " + SO_SNDBUF);
    System.out.println("Traffic Class = " + trafficClassVal);
    System.out.println("Local Address = " + localIP + ":" + localPort);
    System.out.println("Remote Address = " + remoteIP + ":" + remotePort);
  }
コード例 #2
0
 @Override
 public int getTrafficClass() {
   try {
     return socket.getTrafficClass();
   } catch (SocketException e) {
     throw new ChannelException(e);
   }
 }
コード例 #3
0
ファイル: TcpTransport.java プロジェクト: gerring/daq-eclipse
  /**
   * @param sock The socket on which to set the Traffic Class.
   * @return Whether or not the Traffic Class was set on the given socket.
   * @throws SocketException if the system does not support setting the Traffic Class.
   * @throws IllegalArgumentException if both the Differentiated Services and Type of Services
   *     transport options have been set on the same connection.
   */
  private boolean setTrafficClass(Socket sock) throws SocketException, IllegalArgumentException {
    if (sock == null || (!this.diffServChosen && !this.typeOfServiceChosen)) {
      return false;
    }
    if (this.diffServChosen && this.typeOfServiceChosen) {
      throw new IllegalArgumentException(
          "Cannot set both the "
              + " Differentiated Services and Type of Services transport "
              + " options on the same connection.");
    }

    sock.setTrafficClass(this.trafficClass);

    int resultTrafficClass = sock.getTrafficClass();
    if (this.trafficClass != resultTrafficClass) {
      // In the case where the user has specified the ECN bits (e.g. in
      // Type of Service) but the system won't allow the ECN bits to be
      // set or in the case where setting the traffic class failed for
      // other reasons, emit a warning.
      if ((this.trafficClass >> 2) == (resultTrafficClass >> 2)
          && (this.trafficClass & 3) != (resultTrafficClass & 3)) {
        LOG.warn(
            "Attempted to set the Traffic Class to "
                + this.trafficClass
                + " but the result Traffic Class was "
                + resultTrafficClass
                + ". Please check that your system "
                + "allows you to set the ECN bits (the first two bits).");
      } else {
        LOG.warn(
            "Attempted to set the Traffic Class to "
                + this.trafficClass
                + " but the result Traffic Class was "
                + resultTrafficClass
                + ". Please check that your system "
                + "supports java.net.setTrafficClass.");
      }
      return false;
    }
    // Reset the guards that prevent both the Differentiated Services
    // option and the Type of Service option from being set on the same
    // connection.
    this.diffServChosen = false;
    this.typeOfServiceChosen = false;
    return true;
  }
コード例 #4
0
 @Override
 public int getTrafficClass() throws SocketException {
   return sock.getTrafficClass();
 }