equal
deleted
inserted
replaced
386 |
386 |
387 // Substitute a native buffer. If the supplied buffer is empty |
387 // Substitute a native buffer. If the supplied buffer is empty |
388 // we must instead use a nonempty buffer, otherwise the call |
388 // we must instead use a nonempty buffer, otherwise the call |
389 // will not block waiting for a datagram on some platforms. |
389 // will not block waiting for a datagram on some platforms. |
390 int newSize = Math.max(rem, 1); |
390 int newSize = Math.max(rem, 1); |
391 ByteBuffer bb = null; |
391 ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize); |
392 try { |
392 try { |
393 bb = Util.getTemporaryDirectBuffer(newSize); |
|
394 int n = receiveIntoNativeBuffer(fd, bb, newSize, 0); |
393 int n = receiveIntoNativeBuffer(fd, bb, newSize, 0); |
395 bb.flip(); |
394 bb.flip(); |
396 if (n > 0 && rem > 0) |
395 if (n > 0 && rem > 0) |
397 dst.put(bb); |
396 dst.put(bb); |
398 return n; |
397 return n; |
480 int pos = src.position(); |
479 int pos = src.position(); |
481 int lim = src.limit(); |
480 int lim = src.limit(); |
482 assert (pos <= lim); |
481 assert (pos <= lim); |
483 int rem = (pos <= lim ? lim - pos : 0); |
482 int rem = (pos <= lim ? lim - pos : 0); |
484 |
483 |
485 ByteBuffer bb = null; |
484 ByteBuffer bb = Util.getTemporaryDirectBuffer(rem); |
486 try { |
485 try { |
487 bb = Util.getTemporaryDirectBuffer(rem); |
|
488 bb.put(src); |
486 bb.put(src); |
489 bb.flip(); |
487 bb.flip(); |
490 // Do not update src until we see how many bytes were written |
488 // Do not update src until we see how many bytes were written |
491 src.position(pos); |
489 src.position(pos); |
492 |
490 |
764 throw new IllegalArgumentException("Group not a multicast address"); |
762 throw new IllegalArgumentException("Group not a multicast address"); |
765 |
763 |
766 // check multicast address is compatible with this socket |
764 // check multicast address is compatible with this socket |
767 if (group instanceof Inet4Address) { |
765 if (group instanceof Inet4Address) { |
768 if (family == StandardProtocolFamily.INET6 && !Net.canIPv6SocketJoinIPv4Group()) |
766 if (family == StandardProtocolFamily.INET6 && !Net.canIPv6SocketJoinIPv4Group()) |
769 throw new IllegalArgumentException("Group is not IPv4 multicast address"); |
767 throw new IllegalArgumentException("IPv6 socket cannot join IPv4 multicast group"); |
770 } else if (group instanceof Inet6Address) { |
768 } else if (group instanceof Inet6Address) { |
771 if (family != StandardProtocolFamily.INET6) |
769 if (family != StandardProtocolFamily.INET6) |
772 throw new IllegalArgumentException("Group is not IPv6 multicast address"); |
770 throw new IllegalArgumentException("Only IPv6 sockets can join IPv6 multicast group"); |
773 } else { |
771 } else { |
774 throw new IllegalArgumentException("Address type not supported"); |
772 throw new IllegalArgumentException("Address type not supported"); |
775 } |
773 } |
776 |
774 |
777 // check source address |
775 // check source address |