1
1
/*
2
- * Copyright (c) 1995, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1995, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -395,7 +395,7 @@ public DatagramSocket(int port, InetAddress laddr) throws SocketException {
395
395
*
396
396
* @param addr The address and port to bind to.
397
397
* @throws SocketException if any error happens during the bind, or if the
398
- * socket is already bound.
398
+ * socket is already bound or is closed .
399
399
* @throws SecurityException if a security manager exists and its
400
400
* {@code checkListen} method doesn't allow the operation.
401
401
* @throws IllegalArgumentException if addr is a SocketAddress subclass
@@ -422,6 +422,11 @@ public void bind(SocketAddress addr) throws SocketException {
422
422
* call to send or receive may throw a PortUnreachableException. Note,
423
423
* there is no guarantee that the exception will be thrown.
424
424
*
425
+ * <p> If this socket is already connected, then this method will attempt to
426
+ * connect to the given address. If this connect fails then the state of
427
+ * this socket is unknown - it may or may not be connected to the address
428
+ * that it was previously connected to.
429
+ *
425
430
* <p> If a security manager has been installed then it is invoked to check
426
431
* access to the remote address. Specifically, if the given {@code address}
427
432
* is a {@link InetAddress#isMulticastAddress multicast address},
@@ -461,7 +466,7 @@ public void bind(SocketAddress addr) throws SocketException {
461
466
* not permit access to the given remote address
462
467
*
463
468
* @throws UncheckedIOException
464
- * may be thrown if connect fails, for example, if the
469
+ * if the port is 0 or connect fails, for example, if the
465
470
* destination address is non-routable
466
471
*
467
472
* @see #disconnect
@@ -484,6 +489,11 @@ public void connect(InetAddress address, int port) {
484
489
* have not been {@linkplain #receive(DatagramPacket) received} before invoking
485
490
* this method, may be discarded.
486
491
*
492
+ * <p> If this socket is already connected, then this method will attempt to
493
+ * connect to the given address. If this connect fails then the state of
494
+ * this socket is unknown - it may or may not be connected to the address
495
+ * that it was previously connected to.
496
+ *
487
497
* @param addr The remote address.
488
498
*
489
499
* @throws SocketException
@@ -643,7 +653,7 @@ public SocketAddress getLocalSocketAddress() {
643
653
*
644
654
* @param p the {@code DatagramPacket} to be sent.
645
655
*
646
- * @throws IOException if an I/O error occurs.
656
+ * @throws IOException if an I/O error occurs, or the socket is closed .
647
657
* @throws SecurityException if a security manager exists and its
648
658
* {@code checkMulticast} or {@code checkConnect}
649
659
* method doesn't allow the send.
@@ -702,7 +712,7 @@ public void send(DatagramPacket p) throws IOException {
702
712
*
703
713
* @param p the {@code DatagramPacket} into which to place
704
714
* the incoming data.
705
- * @throws IOException if an I/O error occurs.
715
+ * @throws IOException if an I/O error occurs, or the socket is closed .
706
716
* @throws SocketTimeoutException if setSoTimeout was previously called
707
717
* and the timeout has expired.
708
718
* @throws PortUnreachableException may be thrown if the socket is connected
@@ -770,7 +780,8 @@ public int getLocalPort() {
770
780
* operation to have effect.
771
781
*
772
782
* @param timeout the specified timeout in milliseconds.
773
- * @throws SocketException if there is an error in the underlying protocol, such as an UDP error.
783
+ * @throws SocketException if there is an error in the underlying protocol,
784
+ * such as an UDP error, or the socket is closed.
774
785
* @throws IllegalArgumentException if {@code timeout} is negative
775
786
* @since 1.1
776
787
* @see #getSoTimeout()
@@ -784,7 +795,8 @@ public void setSoTimeout(int timeout) throws SocketException {
784
795
* option is disabled (i.e., timeout of infinity).
785
796
*
786
797
* @return the setting for SO_TIMEOUT
787
- * @throws SocketException if there is an error in the underlying protocol, such as an UDP error.
798
+ * @throws SocketException if there is an error in the underlying protocol,
799
+ * such as an UDP error, or the socket is closed.
788
800
* @since 1.1
789
801
* @see #setSoTimeout(int)
790
802
*/
@@ -820,8 +832,8 @@ public int getSoTimeout() throws SocketException {
820
832
* @param size the size to which to set the send buffer
821
833
* size, in bytes. This value must be greater than 0.
822
834
*
823
- * @throws SocketException if there is an error
824
- * in the underlying protocol, such as an UDP error.
835
+ * @throws SocketException if there is an error in the underlying protocol,
836
+ * such as an UDP error, or the socket is closed .
825
837
* @throws IllegalArgumentException if the value is 0 or is
826
838
* negative.
827
839
* @see #getSendBufferSize()
@@ -841,8 +853,8 @@ public void setSendBufferSize(int size) throws SocketException {
841
853
* getOption(StandardSocketOptions.SO_SNDBUF)}.
842
854
*
843
855
* @return the value of the SO_SNDBUF option for this {@code DatagramSocket}
844
- * @throws SocketException if there is an error in
845
- * the underlying protocol, such as an UDP error.
856
+ * @throws SocketException if there is an error in the underlying protocol,
857
+ * such as an UDP error, or the socket is closed .
846
858
* @see #setSendBufferSize
847
859
* @see StandardSocketOptions#SO_SNDBUF
848
860
* @since 1.2
@@ -878,8 +890,8 @@ public int getSendBufferSize() throws SocketException {
878
890
* @param size the size to which to set the receive buffer
879
891
* size, in bytes. This value must be greater than 0.
880
892
*
881
- * @throws SocketException if there is an error in
882
- * the underlying protocol, such as an UDP error.
893
+ * @throws SocketException if there is an error in the underlying protocol,
894
+ * such as an UDP error, or the socket is closed .
883
895
* @throws IllegalArgumentException if the value is 0 or is
884
896
* negative.
885
897
* @see #getReceiveBufferSize()
@@ -899,7 +911,8 @@ public void setReceiveBufferSize(int size) throws SocketException {
899
911
* getOption(StandardSocketOptions.SO_RCVBUF)}.
900
912
*
901
913
* @return the value of the SO_RCVBUF option for this {@code DatagramSocket}
902
- * @throws SocketException if there is an error in the underlying protocol, such as an UDP error.
914
+ * @throws SocketException if there is an error in the underlying protocol,
915
+ * such as an UDP error, or the socket is closed.
903
916
* @see #setReceiveBufferSize(int)
904
917
* @see StandardSocketOptions#SO_RCVBUF
905
918
* @since 1.2
@@ -959,8 +972,8 @@ public void setReuseAddress(boolean on) throws SocketException {
959
972
* getOption(StandardSocketOptions.SO_REUSEADDR)}.
960
973
*
961
974
* @return a {@code boolean} indicating whether or not SO_REUSEADDR is enabled.
962
- * @throws SocketException if there is an error
963
- * in the underlying protocol, such as an UDP error.
975
+ * @throws SocketException if there is an error in the underlying protocol,
976
+ * such as an UDP error, or the socket is closed .
964
977
* @since 1.4
965
978
* @see #setReuseAddress(boolean)
966
979
* @see StandardSocketOptions#SO_REUSEADDR
@@ -983,9 +996,8 @@ public boolean getReuseAddress() throws SocketException {
983
996
* @param on
984
997
* whether or not to have broadcast turned on.
985
998
*
986
- * @throws SocketException
987
- * if there is an error in the underlying protocol, such as an UDP
988
- * error.
999
+ * @throws SocketException if there is an error in the underlying protocol,
1000
+ * such as an UDP error, or the socket is closed.
989
1001
*
990
1002
* @since 1.4
991
1003
* @see #getBroadcast()
@@ -1003,8 +1015,8 @@ public void setBroadcast(boolean on) throws SocketException {
1003
1015
* getOption(StandardSocketOptions.SO_BROADCAST)}.
1004
1016
*
1005
1017
* @return a {@code boolean} indicating whether or not SO_BROADCAST is enabled.
1006
- * @throws SocketException if there is an error
1007
- * in the underlying protocol, such as an UDP error.
1018
+ * @throws SocketException if there is an error in the underlying protocol,
1019
+ * such as an UDP error, or the socket is closed .
1008
1020
* @since 1.4
1009
1021
* @see #setBroadcast(boolean)
1010
1022
* @see StandardSocketOptions#SO_BROADCAST
@@ -1049,8 +1061,8 @@ public boolean getBroadcast() throws SocketException {
1049
1061
* setOption(StandardSocketOptions.IP_TOS, tc)}.
1050
1062
*
1051
1063
* @param tc an {@code int} value for the bitset.
1052
- * @throws SocketException if there is an error setting the
1053
- * traffic class or type-of-service
1064
+ * @throws SocketException if there is an error setting the traffic class or type-of-service,
1065
+ * or the socket is closed.
1054
1066
* @since 1.4
1055
1067
* @see #getTrafficClass
1056
1068
* @see StandardSocketOptions#IP_TOS
@@ -1074,8 +1086,8 @@ public void setTrafficClass(int tc) throws SocketException {
1074
1086
* getOption(StandardSocketOptions.IP_TOS)}.
1075
1087
*
1076
1088
* @return the traffic class or type-of-service already set
1077
- * @throws SocketException if there is an error obtaining the
1078
- * traffic class or type-of-service value.
1089
+ * @throws SocketException if there is an error obtaining the traffic class
1090
+ * or type-of-service value, or the socket is closed .
1079
1091
* @since 1.4
1080
1092
* @see #setTrafficClass(int)
1081
1093
* @see StandardSocketOptions#IP_TOS
@@ -1092,6 +1104,9 @@ public int getTrafficClass() throws SocketException {
1092
1104
*
1093
1105
* <p> If this socket has an associated channel then the channel is closed
1094
1106
* as well.
1107
+ *
1108
+ * <p> Once closed, several of the methods defined by this class will throw
1109
+ * an exception if invoked on the closed socket.
1095
1110
*/
1096
1111
public void close () {
1097
1112
delegate ().close ();
@@ -1299,7 +1314,7 @@ public Set<SocketOption<?>> supportedOptions() {
1299
1314
* datagram packets, or {@code null}.
1300
1315
* @throws IOException if there is an error joining, or when the address
1301
1316
* is not a multicast address, or the platform does not support
1302
- * multicasting
1317
+ * multicasting, or the socket is closed
1303
1318
* @throws SecurityException if a security manager exists and its
1304
1319
* {@code checkMulticast} method doesn't allow the join.
1305
1320
* @throws IllegalArgumentException if mcastaddr is {@code null} or is a
@@ -1343,7 +1358,7 @@ public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
1343
1358
* is unspecified: any interface may be selected or the operation
1344
1359
* may fail with a {@code SocketException}.
1345
1360
* @throws IOException if there is an error leaving or when the address
1346
- * is not a multicast address.
1361
+ * is not a multicast address, or the socket is closed .
1347
1362
* @throws SecurityException if a security manager exists and its
1348
1363
* {@code checkMulticast} method doesn't allow the operation.
1349
1364
* @throws IllegalArgumentException if mcastaddr is {@code null} or is a
0 commit comments