Package com.barchart.udt

Examples of com.barchart.udt.SocketUDT


    return new ChannelServerSocketUDT(this, serverSocketUDT);
  }

  @Override
  public ChannelSocketUDT openSocketChannel() throws IOException {
    final SocketUDT socketUDT = new SocketUDT(type);
    return new ChannelSocketUDT(this, socketUDT);
  }
View Full Code Here


    final int remaining = buffer.remaining();

    if (remaining > 0) {

      final SocketUDT socket = socketUDT;
      final boolean isBlocking = isBlockingMode;

      final int sizeReceived;

      try {

        if (isBlocking) {
          begin(); // JDK contract for NIO blocking calls
        }

        if (buffer.isDirect()) {

          sizeReceived = socket.receive(buffer);

        } else {

          final byte[] array = buffer.array();
          final int position = buffer.position();
          final int limit = buffer.limit();

          sizeReceived = socket.receive(array, position, limit);

          if (0 < sizeReceived && sizeReceived <= remaining) {
            buffer.position(position + sizeReceived);
          }

        }

      } finally {
        if (isBlocking) {
          end(true); // JDK contract for NIO blocking calls
        }
      }

      // see contract for receive()

      if (sizeReceived < 0) {
        log.trace("nothing was received; socketID={}",
            socket.getSocketId());
        return 0;
      }

      if (sizeReceived == 0) {
        log.trace("receive timeout; socketID={}", socket.getSocketId());
        return 0;
      }

      if (sizeReceived <= remaining) {
        return sizeReceived;
      } else { // should not happen
        log.error("unexpected: sizeReceived > remaining; socketID={}",
            socket.getSocketId());
        return 0;
      }

    } else {
      return 0;
View Full Code Here

    final int remaining = buffer.remaining();

    if (remaining > 0) {

      final SocketUDT socket = socketUDT;
      final boolean isBlocking = isBlockingMode;

      final int sizeSent;

      try {

        if (isBlocking) {
          begin(); // JDK contract for NIO blocking calls
        }

        if (buffer.isDirect()) {

          sizeSent = socket.send(buffer);

        } else {

          final byte[] array = buffer.array();
          final int position = buffer.position();
          final int limit = buffer.limit();

          sizeSent = socket.send(array, position, limit);

          if (0 < sizeSent && sizeSent <= remaining) {
            buffer.position(position + sizeSent);
          }
        }
      } finally {
        if (isBlocking) {
          end(true); // JDK contract for NIO blocking calls
        }
      }

      // see contract for send()

      if (sizeSent < 0) {
        log.trace("no buffer space for send; socketID={}",
            socket.getSocketId());
        return 0;
      }

      if (sizeSent == 0) {
        log.trace("send timeout; socketID={}", socket.getSocketId());
        return 0;
      }

      if (sizeSent <= remaining) {
        return sizeSent;
      } else { // should not happen
        log.error("unexpected: sizeSent > remaining; socketID={}",
            socket.getSocketId());
        return 0;
      }

    } else {
      return 0;
View Full Code Here

  public ChannelSocketUDT accept() throws IOException {
    try {

      begin();

      final SocketUDT clientUDT = socketUDT.accept();

      if (clientUDT == null) {

        return null;

      } else {

        return new ChannelSocketUDT( //
            providerUDT(), //
            clientUDT, //
            clientUDT.isConnected() //
        );

      }
    } finally {
      end(true);
View Full Code Here

  protected final SocketUDT socketUDT;

  /** uses {@link TypeUDT#STREAM} socket in blocking mode */
  public NetSocketUDT() throws ExceptionUDT {
    this(new SocketUDT(TypeUDT.STREAM));
    this.socketUDT.setBlocking(true);
  }
View Full Code Here

  protected final SocketUDT socketUDT;

  /** uses {@link TypeUDT#STREAM} socket in blocking mode */
  public NetServerSocketUDT() throws IOException {
    this(new SocketUDT(TypeUDT.STREAM));
    this.socketUDT.setBlocking(true);
  }
View Full Code Here

    this.socketUDT = socketUDT;
  }

  @Override
  public Socket accept() throws IOException {
    final SocketUDT clientUDT = socketUDT.accept();
    return new NetSocketUDT(clientUDT);
  }
View Full Code Here

   * Open UDT {@link KindUDT#RENDEZVOUS} socket channel.
   *
   * @see RendezvousChannelUDT
   */
  public RendezvousChannelUDT openRendezvousChannel() throws IOException {
    final SocketUDT socketUDT = new SocketUDT(type);
    return new RendezvousChannelUDT(this, socketUDT);
  }
View Full Code Here

   *
   * @see ServerSocketChannelUDT
   */
  @Override
  public ServerSocketChannelUDT openServerSocketChannel() throws IOException {
    final SocketUDT serverSocketUDT = new SocketUDT(type);
    return new ServerSocketChannelUDT(this, serverSocketUDT);
  }
View Full Code Here

   *
   * @see SocketChannelUDT
   */
  @Override
  public SocketChannelUDT openSocketChannel() throws IOException {
    final SocketUDT socketUDT = new SocketUDT(type);
    return new SocketChannelUDT(this, socketUDT);
  }
View Full Code Here

TOP

Related Classes of com.barchart.udt.SocketUDT

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.