97 /**
98 * The port number on the remote host to which this socket is connected.
99 */
100 protected int port;
101
102 /**
103 * The local port number to which this socket is connected.
104 */
105 protected int localport;
106
107 /**
108 * Initialize a new instance of this class
109 */
110 public SocketImpl() { }
111
112 /**
113 * Creates either a stream or a datagram socket.
114 *
115 * @param stream if {@code true}, create a stream socket;
116 * otherwise, create a datagram socket.
117 * @exception IOException if an I/O error occurs while creating the
118 * socket.
119 */
120 protected abstract void create(boolean stream) throws IOException;
121
122 /**
123 * Connects this socket to the specified port on the named host.
124 *
125 * @param host the name of the remote host.
126 * @param port the port number.
127 * @exception IOException if an I/O error occurs when connecting to the
128 * remote host.
129 */
130 protected abstract void connect(String host, int port) throws IOException;
131
132 /**
133 * Connects this socket to the specified port number on the specified host.
134 *
135 * @param address the IP address of the remote host.
136 * @param port the port number.
137 * @exception IOException if an I/O error occurs when attempting a
138 * connection.
139 */
140 protected abstract void connect(InetAddress address, int port) throws IOException;
141
142 /**
143 * Connects this socket to the specified port number on the specified host.
144 * A timeout of zero is interpreted as an infinite timeout. The connection
145 * will then block until established or an error occurs.
146 *
147 * @param address the Socket address of the remote host.
148 * @param timeout the timeout value, in milliseconds, or zero for no timeout.
149 * @exception IOException if an I/O error occurs when attempting a
150 * connection.
151 * @since 1.4
152 */
153 protected abstract void connect(SocketAddress address, int timeout) throws IOException;
154
155 /**
156 * Binds this socket to the specified local IP address and port number.
157 *
158 * @param host an IP address that belongs to a local interface.
159 * @param port the port number.
160 * @exception IOException if an I/O error occurs when binding this socket.
161 */
162 protected abstract void bind(InetAddress host, int port) throws IOException;
163
164 /**
165 * Sets the maximum queue length for incoming connection indications
166 * (a request to connect) to the {@code count} argument. If a
167 * connection indication arrives when the queue is full, the
168 * connection is refused.
169 *
170 * @param backlog the maximum length of the queue.
171 * @exception IOException if an I/O error occurs when creating the queue.
172 */
173 protected abstract void listen(int backlog) throws IOException;
174
175 /**
176 * Accepts a connection.
177 *
178 * @param s the accepted connection.
179 * @exception IOException if an I/O error occurs when accepting the
180 * connection.
181 */
182 protected abstract void accept(SocketImpl s) throws IOException;
183
184 /**
185 * Returns an input stream for this socket.
186 *
187 * @return a stream for reading from this socket.
188 * @exception IOException if an I/O error occurs when creating the
189 * input stream.
190 */
191 protected abstract InputStream getInputStream() throws IOException;
192
193 /**
194 * Returns an output stream for this socket.
195 *
196 * @return an output stream for writing to this socket.
197 * @exception IOException if an I/O error occurs when creating the
198 * output stream.
199 */
200 protected abstract OutputStream getOutputStream() throws IOException;
201
202 /**
203 * Returns the number of bytes that can be read from this socket
204 * without blocking.
205 *
206 * @return the number of bytes that can be read from this socket
207 * without blocking.
208 * @exception IOException if an I/O error occurs when determining the
209 * number of bytes available.
210 */
211 protected abstract int available() throws IOException;
212
213 /**
214 * Closes this socket.
215 *
216 * @exception IOException if an I/O error occurs when closing this socket.
217 */
218 protected abstract void close() throws IOException;
219
220 /**
221 * Closes this socket, ignoring any IOException that is thrown by close.
222 */
223 void closeQuietly() {
224 try {
225 close();
226 } catch (IOException ignore) { }
227 }
228
229 /**
230 * Places the input stream for this socket at "end of stream".
231 * Any data sent to this socket is acknowledged and then
232 * silently discarded.
233 *
234 * If you read from a socket input stream after invoking this method on the
235 * socket, the stream's {@code available} method will return 0, and its
236 * {@code read} methods will return {@code -1} (end of stream).
237 *
238 * @exception IOException if an I/O error occurs when shutting down this
239 * socket.
240 * @see java.net.Socket#shutdownOutput()
241 * @see java.net.Socket#close()
242 * @see java.net.Socket#setSoLinger(boolean, int)
243 * @since 1.3
244 */
245 protected void shutdownInput() throws IOException {
246 throw new IOException("Method not implemented!");
247 }
248
249 /**
250 * Disables the output stream for this socket.
251 * For a TCP socket, any previously written data will be sent
252 * followed by TCP's normal connection termination sequence.
253 *
254 * If you write to a socket output stream after invoking
255 * shutdownOutput() on the socket, the stream will throw
256 * an IOException.
257 *
258 * @exception IOException if an I/O error occurs when shutting down this
259 * socket.
260 * @see java.net.Socket#shutdownInput()
261 * @see java.net.Socket#close()
262 * @see java.net.Socket#setSoLinger(boolean, int)
263 * @since 1.3
264 */
265 protected void shutdownOutput() throws IOException {
266 throw new IOException("Method not implemented!");
267 }
268
269 /**
270 * Returns the value of this socket's {@code fd} field.
271 *
272 * @return the value of this socket's {@code fd} field.
273 * @see java.net.SocketImpl#fd
274 */
275 protected FileDescriptor getFileDescriptor() {
276 return fd;
277 }
278
296 return port;
297 }
298
299 /**
300 * Returns whether or not this SocketImpl supports sending
301 * urgent data. By default, false is returned
302 * unless the method is overridden in a sub-class
303 *
304 * @return true if urgent data supported
305 * @see java.net.SocketImpl#address
306 * @since 1.4
307 */
308 protected boolean supportsUrgentData () {
309 return false; // must be overridden in sub-class
310 }
311
312 /**
313 * Send one byte of urgent data on the socket.
314 * The byte to be sent is the low eight bits of the parameter
315 * @param data The byte of data to send
316 * @exception IOException if there is an error
317 * sending the data.
318 * @since 1.4
319 */
320 protected abstract void sendUrgentData (int data) throws IOException;
321
322 /**
323 * Returns the value of this socket's {@code localport} field.
324 *
325 * @return the value of this socket's {@code localport} field.
326 * @see java.net.SocketImpl#localport
327 */
328 protected int getLocalPort() {
329 return localport;
330 }
331
332 /**
333 * Returns the address and port of this socket as a {@code String}.
334 *
335 * @return a string representation of this socket.
336 */
|
97 /**
98 * The port number on the remote host to which this socket is connected.
99 */
100 protected int port;
101
102 /**
103 * The local port number to which this socket is connected.
104 */
105 protected int localport;
106
107 /**
108 * Initialize a new instance of this class
109 */
110 public SocketImpl() { }
111
112 /**
113 * Creates either a stream or a datagram socket.
114 *
115 * @param stream if {@code true}, create a stream socket;
116 * otherwise, create a datagram socket.
117 * @throws IOException if an I/O error occurs while creating the
118 * socket.
119 */
120 protected abstract void create(boolean stream) throws IOException;
121
122 /**
123 * Connects this socket to the specified port on the named host.
124 *
125 * @param host the name of the remote host.
126 * @param port the port number.
127 * @throws IOException if an I/O error occurs when connecting to the
128 * remote host.
129 */
130 protected abstract void connect(String host, int port) throws IOException;
131
132 /**
133 * Connects this socket to the specified port number on the specified host.
134 *
135 * @param address the IP address of the remote host.
136 * @param port the port number.
137 * @throws IOException if an I/O error occurs when attempting a
138 * connection.
139 */
140 protected abstract void connect(InetAddress address, int port) throws IOException;
141
142 /**
143 * Connects this socket to the specified port number on the specified host.
144 * A timeout of zero is interpreted as an infinite timeout. The connection
145 * will then block until established or an error occurs.
146 *
147 * @param address the Socket address of the remote host.
148 * @param timeout the timeout value, in milliseconds, or zero for no timeout.
149 * @throws IOException if an I/O error occurs when attempting a
150 * connection.
151 * @since 1.4
152 */
153 protected abstract void connect(SocketAddress address, int timeout) throws IOException;
154
155 /**
156 * Binds this socket to the specified local IP address and port number.
157 *
158 * @param host an IP address that belongs to a local interface.
159 * @param port the port number.
160 * @throws IOException if an I/O error occurs when binding this socket.
161 */
162 protected abstract void bind(InetAddress host, int port) throws IOException;
163
164 /**
165 * Sets the maximum queue length for incoming connection indications
166 * (a request to connect) to the {@code count} argument. If a
167 * connection indication arrives when the queue is full, the
168 * connection is refused.
169 *
170 * @param backlog the maximum length of the queue.
171 * @throws IOException if an I/O error occurs when creating the queue.
172 */
173 protected abstract void listen(int backlog) throws IOException;
174
175 /**
176 * Accepts a connection.
177 *
178 * @param s the accepted connection.
179 * @throws IOException if an I/O error occurs when accepting the
180 * connection.
181 */
182 protected abstract void accept(SocketImpl s) throws IOException;
183
184 /**
185 * Returns an input stream for this socket.
186 *
187 * @return a stream for reading from this socket.
188 * @throws IOException if an I/O error occurs when creating the
189 * input stream.
190 */
191 protected abstract InputStream getInputStream() throws IOException;
192
193 /**
194 * Returns an output stream for this socket.
195 *
196 * @return an output stream for writing to this socket.
197 * @throws IOException if an I/O error occurs when creating the
198 * output stream.
199 */
200 protected abstract OutputStream getOutputStream() throws IOException;
201
202 /**
203 * Returns the number of bytes that can be read from this socket
204 * without blocking.
205 *
206 * @return the number of bytes that can be read from this socket
207 * without blocking.
208 * @throws IOException if an I/O error occurs when determining the
209 * number of bytes available.
210 */
211 protected abstract int available() throws IOException;
212
213 /**
214 * Closes this socket.
215 *
216 * @throws IOException if an I/O error occurs when closing this socket.
217 */
218 protected abstract void close() throws IOException;
219
220 /**
221 * Closes this socket, ignoring any IOException that is thrown by close.
222 */
223 void closeQuietly() {
224 try {
225 close();
226 } catch (IOException ignore) { }
227 }
228
229 /**
230 * Places the input stream for this socket at "end of stream".
231 * Any data sent to this socket is acknowledged and then
232 * silently discarded.
233 *
234 * If you read from a socket input stream after invoking this method on the
235 * socket, the stream's {@code available} method will return 0, and its
236 * {@code read} methods will return {@code -1} (end of stream).
237 *
238 * @throws IOException if an I/O error occurs when shutting down this
239 * socket.
240 * @see java.net.Socket#shutdownOutput()
241 * @see java.net.Socket#close()
242 * @see java.net.Socket#setSoLinger(boolean, int)
243 * @since 1.3
244 */
245 protected void shutdownInput() throws IOException {
246 throw new IOException("Method not implemented!");
247 }
248
249 /**
250 * Disables the output stream for this socket.
251 * For a TCP socket, any previously written data will be sent
252 * followed by TCP's normal connection termination sequence.
253 *
254 * If you write to a socket output stream after invoking
255 * shutdownOutput() on the socket, the stream will throw
256 * an IOException.
257 *
258 * @throws IOException if an I/O error occurs when shutting down this
259 * socket.
260 * @see java.net.Socket#shutdownInput()
261 * @see java.net.Socket#close()
262 * @see java.net.Socket#setSoLinger(boolean, int)
263 * @since 1.3
264 */
265 protected void shutdownOutput() throws IOException {
266 throw new IOException("Method not implemented!");
267 }
268
269 /**
270 * Returns the value of this socket's {@code fd} field.
271 *
272 * @return the value of this socket's {@code fd} field.
273 * @see java.net.SocketImpl#fd
274 */
275 protected FileDescriptor getFileDescriptor() {
276 return fd;
277 }
278
296 return port;
297 }
298
299 /**
300 * Returns whether or not this SocketImpl supports sending
301 * urgent data. By default, false is returned
302 * unless the method is overridden in a sub-class
303 *
304 * @return true if urgent data supported
305 * @see java.net.SocketImpl#address
306 * @since 1.4
307 */
308 protected boolean supportsUrgentData () {
309 return false; // must be overridden in sub-class
310 }
311
312 /**
313 * Send one byte of urgent data on the socket.
314 * The byte to be sent is the low eight bits of the parameter
315 * @param data The byte of data to send
316 * @throws IOException if there is an error
317 * sending the data.
318 * @since 1.4
319 */
320 protected abstract void sendUrgentData (int data) throws IOException;
321
322 /**
323 * Returns the value of this socket's {@code localport} field.
324 *
325 * @return the value of this socket's {@code localport} field.
326 * @see java.net.SocketImpl#localport
327 */
328 protected int getLocalPort() {
329 return localport;
330 }
331
332 /**
333 * Returns the address and port of this socket as a {@code String}.
334 *
335 * @return a string representation of this socket.
336 */
|