1. /*
  2. * @(#)DatagramSocketImpl.java 1.19 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.net;
  11. import java.io.FileDescriptor;
  12. import java.io.IOException;
  13. import java.io.InterruptedIOException;
  14. /**
  15. * Abstract datagram and multicast socket implementation base class.
  16. * @author Pavani Diwanji
  17. * @since JDK1.1
  18. */
  19. public abstract class DatagramSocketImpl implements SocketOptions {
  20. /**
  21. * The local port number.
  22. */
  23. protected int localPort;
  24. /**
  25. * The file descriptor object.
  26. */
  27. protected FileDescriptor fd;
  28. /**
  29. * Creates a datagram socket.
  30. * @exception SocketException if there is an error in the
  31. * underlying protocol, such as a TCP error.
  32. */
  33. protected abstract void create() throws SocketException;
  34. /**
  35. * Binds a datagram socket to a local port and address.
  36. * @param lport the local port
  37. * @param laddr the local address
  38. * @exception SocketException if there is an error in the
  39. * underlying protocol, such as a TCP error.
  40. */
  41. protected abstract void bind(int lport, InetAddress laddr) throws SocketException;
  42. /**
  43. * Sends a datagram packet. The packet contains the data and the
  44. * destination address to send the packet to.
  45. * @param p the packet to be sent.
  46. * @exception IOException if an I/O exception occurs while sending the
  47. * datagram packet.
  48. */
  49. protected abstract void send(DatagramPacket p) throws IOException;
  50. /**
  51. * Peek at the packet to see who it is from.
  52. * @param i an InetAddress object
  53. * @return the address which the packet came from.
  54. * @exception IOException if an I/O exception occurs
  55. */
  56. protected abstract int peek(InetAddress i) throws IOException;
  57. /**
  58. * Receive the datagram packet.
  59. * @param p the Packet Received.
  60. * @exception IOException if an I/O exception occurs
  61. * while receiving the datagram packet.
  62. */
  63. protected abstract void receive(DatagramPacket p) throws IOException;
  64. /**
  65. * Set the TTL (time-to-live) option.
  66. * @param ttl a byte specifying the TTL value
  67. *
  68. * @deprecated use setTimeToLive instead.
  69. * @exception IOException if an I/O exception occurs while setting
  70. * the time-to-live option.
  71. * @see #getTTL()
  72. */
  73. protected abstract void setTTL(byte ttl) throws IOException;
  74. /**
  75. * Retrieve the TTL (time-to-live) option.
  76. *
  77. * @exception IOException if an I/O exception occurs
  78. * while retrieving the time-to-live option
  79. * @deprecated use getTimeToLive instead.
  80. * @return a byte representing the TTL value
  81. * @see #setTTL(byte)
  82. */
  83. protected abstract byte getTTL() throws IOException;
  84. /**
  85. * Set the TTL (time-to-live) option.
  86. * @param ttl an <tt>int</tt> specifying the time-to-live value
  87. * @exception IOException if an I/O exception occurs
  88. * while setting the time-to-live option.
  89. * @see #getTimeToLive()
  90. */
  91. protected abstract void setTimeToLive(int ttl) throws IOException;
  92. /**
  93. * Retrieve the TTL (time-to-live) option.
  94. * @exception IOException if an I/O exception occurs
  95. * while retrieving the time-to-live option
  96. * @return an <tt>int</tt> representing the time-to-live value
  97. * @see #setTimeToLive(int)
  98. */
  99. protected abstract int getTimeToLive() throws IOException;
  100. /**
  101. * Join the multicast group.
  102. * @param inetaddr multicast address to join.
  103. * @exception IOException if an I/O exception occurs
  104. * while joining the multicast group.
  105. */
  106. protected abstract void join(InetAddress inetaddr) throws IOException;
  107. /**
  108. * Leave the multicast group.
  109. * @param inetaddr multicast address to leave.
  110. * @exception IOException if an I/O exception occurs
  111. * while leaving the multicast group.
  112. */
  113. protected abstract void leave(InetAddress inetaddr) throws IOException;
  114. /**
  115. * Close the socket.
  116. */
  117. protected abstract void close();
  118. /**
  119. * Gets the local port.
  120. * @return an <tt>int</tt> representing the local port value
  121. */
  122. protected int getLocalPort() {
  123. return localPort;
  124. }
  125. /**
  126. * Gets the datagram socket file descriptor.
  127. * @return a <tt>FileDescriptor</tt> object representing the datagram socket
  128. * file descriptor
  129. */
  130. protected FileDescriptor getFileDescriptor() {
  131. return fd;
  132. }
  133. }