Exemplo n.º 1
0
  @Override
  public int send(ByteBuffer src, SocketAddress target) throws IOException {
    UnixSocketAddress remote = null;
    if (null == target) {
      if (isConnected()) {
        remote = remoteAddress;
      } else {
        throw new IllegalArgumentException(
            "Destination address cannot be null on unconnected datagram sockets");
      }
    } else {
      if (!(target instanceof UnixSocketAddress)) {
        throw new UnsupportedAddressTypeException();
      }
      remote = (UnixSocketAddress) target;
    }
    SockAddrUnix sa = (null == remote) ? null : remote.getStruct();
    int addrlen = (null == sa) ? 0 : sa.length();
    int n = Native.sendto(getFD(), src, sa, addrlen);
    if (n < 0) {
      throw new IOException(Native.getLastErrorString());
    }

    return n;
  }