44 |
import gnu.classpath.Configuration; |
import gnu.classpath.Configuration; |
45 |
|
|
46 |
/** |
/** |
47 |
* Unless the application installs its own SocketImplFactory, this is the |
* Written using on-line Java Platform 1.2 API Specification, as well |
48 |
* default socket implemetation that will be used. It simply uses a |
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). |
49 |
* combination of Java and native routines to implement standard BSD |
* Status: Believed complete and correct. |
50 |
* style sockets of family AF_INET and types SOCK_STREAM and SOCK_DGRAM |
*/ |
51 |
* |
|
52 |
* @version 0.1 |
/** |
53 |
* |
* Unless the application installs its own SocketImplFactory, this is the |
54 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* default socket implemetation that will be used. It simply uses a |
55 |
*/ |
* combination of Java and native routines to implement standard BSD |
56 |
|
* style sockets of family AF_INET and types SOCK_STREAM and SOCK_DGRAM |
57 |
|
* |
58 |
|
* @author Per Bothner <bothner@cygnus.com> |
59 |
|
* @author Nic Ferrier <nferrier@tapsellferrier.co.uk> |
60 |
|
* @author Aaron M. Renn <arenn@urbanophile.com> |
61 |
|
*/ |
62 |
class PlainSocketImpl extends SocketImpl |
class PlainSocketImpl extends SocketImpl |
63 |
{ |
{ |
64 |
// Static initializer to load native library |
// Static initializer to load native library. |
65 |
static |
static |
66 |
{ |
{ |
67 |
if (Configuration.INIT_LOAD_LIBRARY) |
if (Configuration.INIT_LOAD_LIBRARY) |
71 |
} |
} |
72 |
|
|
73 |
/** |
/** |
74 |
* This is the native file descriptor for this socket |
* The OS file handle representing the socket. |
75 |
|
* This is used for reads and writes to/from the socket and |
76 |
|
* to close it. |
77 |
|
* |
78 |
|
* When the socket is closed this is reset to -1. |
79 |
*/ |
*/ |
80 |
protected int native_fd = -1; |
protected int native_fd = -1; |
81 |
|
|
|
|
|
82 |
/** |
/** |
83 |
* Default do nothing constructor |
* Default do nothing constructor |
84 |
*/ |
*/ |
87 |
} |
} |
88 |
|
|
89 |
/** |
/** |
90 |
* Accepts a new connection on this socket and returns in in the |
* Sets the specified option on a socket to the passed in object. For |
91 |
* passed in SocketImpl. |
* options that take an integer argument, the passed in object is an |
92 |
|
* Integer. The option_id parameter is one of the defined constants in |
93 |
|
* this interface. |
94 |
* |
* |
95 |
* @param impl The SocketImpl object to accept this connection. |
* @param option_id The identifier of the option |
96 |
|
* @param val The value to set the option to |
97 |
|
* |
98 |
|
* @exception SocketException If an error occurs |
99 |
*/ |
*/ |
100 |
protected native synchronized void accept(SocketImpl impl) |
public native void setOption(int option_id, Object val) |
101 |
throws IOException; |
throws SocketException; |
102 |
|
|
103 |
/** |
/** |
104 |
* Returns the number of bytes that the caller can read from this socket |
* Returns the current setting of the specified option. The Object returned |
105 |
* without blocking. |
* will be an Integer for options that have integer values. The option_id |
106 |
|
* is one of the defined constants in this interface. |
107 |
* |
* |
108 |
* @return The number of readable bytes before blocking |
* @param option_id The option identifier |
109 |
* |
* |
110 |
* @exception IOException If an error occurs |
* @return The current value of the option |
111 |
|
* |
112 |
|
* @exception SocketException If an error occurs |
113 |
*/ |
*/ |
114 |
protected native int available() throws IOException; |
public native Object getOption(int option_id) |
115 |
|
throws SocketException; |
116 |
|
|
117 |
|
public void shutdownInput() |
118 |
|
{ |
119 |
|
throw new InternalError ("PlainSocketImpl::shutdownInput not implemented"); |
120 |
|
} |
121 |
|
|
122 |
|
public void shutdownOutput() |
123 |
|
{ |
124 |
|
throw new InternalError ("PlainSocketImpl::shutdownOutput not implemented"); |
125 |
|
} |
126 |
|
|
127 |
/** |
/** |
128 |
* Binds to the specified port on the specified addr. Note that this addr |
* Creates a new socket that is not bound to any local address/port and |
129 |
* must represent a local IP address. **** How bind to INADDR_ANY? **** |
* is not connected to any remote address/port. This will be created as |
130 |
* |
* a stream socket if the stream parameter is true, or a datagram socket |
131 |
* @param addr The address to bind to |
* if the stream parameter is false. |
|
* @param port The port number to bind to |
|
132 |
* |
* |
133 |
* @exception IOException If an error occurs |
* @param stream true for a stream socket, false for a datagram socket |
134 |
*/ |
*/ |
135 |
protected native synchronized void bind(InetAddress addr, int port) |
protected native synchronized void create(boolean stream) |
136 |
throws IOException; |
throws IOException; |
137 |
|
|
138 |
/** |
/** |
139 |
* Closes the socket. This will cause any InputStream or OutputStream |
* Connects to the remote hostname and port specified as arguments. |
140 |
* objects for this Socket to be closed as well. |
* |
141 |
* <p> |
* @param hostname The remote hostname to connect to |
142 |
* Note that if the SO_LINGER option is set on this socket, then the |
* @param port The remote port to connect to |
|
* operation could block. |
|
143 |
* |
* |
144 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
145 |
*/ |
*/ |
146 |
protected native void close () throws IOException; |
protected synchronized void connect(String hostname, int port) |
147 |
|
throws IOException |
148 |
|
{ |
149 |
|
InetAddress addr = InetAddress.getByName(hostname); |
150 |
|
connect(addr, port); |
151 |
|
} |
152 |
|
|
153 |
/** |
/** |
154 |
* Connects to the remote address and port specified as arguments. |
* Connects to the remote address and port specified as arguments. |
161 |
protected native void connect(InetAddress addr, int port) |
protected native void connect(InetAddress addr, int port) |
162 |
throws IOException; |
throws IOException; |
163 |
|
|
164 |
/** |
public void connect(SocketAddress address, int timeout) |
|
* Connects to the remote hostname and port specified as arguments. |
|
|
* |
|
|
* @param hostname The remote hostname to connect to |
|
|
* @param port The remote port to connect to |
|
|
* |
|
|
* @exception IOException If an error occurs |
|
|
*/ |
|
|
protected synchronized void connect(String hostname, int port) |
|
|
throws IOException |
|
165 |
{ |
{ |
166 |
InetAddress addr = InetAddress.getByName(hostname); |
throw new InternalError ("PlainSocketImpl::connect not implemented"); |
|
connect(addr, port); |
|
167 |
} |
} |
168 |
|
|
169 |
/** |
/** |
170 |
* Creates a new socket that is not bound to any local address/port and |
* Binds to the specified port on the specified addr. Note that this addr |
171 |
* is not connected to any remote address/port. This will be created as |
* must represent a local IP address. **** How bind to INADDR_ANY? **** |
|
* a stream socket if the stream parameter is true, or a datagram socket |
|
|
* if the stream parameter is false. |
|
172 |
* |
* |
173 |
* @param stream true for a stream socket, false for a datagram socket |
* @param addr The address to bind to |
174 |
|
* @param port The port number to bind to |
175 |
|
* |
176 |
|
* @exception IOException If an error occurs |
177 |
*/ |
*/ |
178 |
protected native synchronized void create(boolean stream) |
protected native synchronized void bind(InetAddress addr, int port) |
179 |
throws IOException; |
throws IOException; |
180 |
|
|
181 |
/** |
/** |
192 |
throws IOException; |
throws IOException; |
193 |
|
|
194 |
/** |
/** |
195 |
|
* Accepts a new connection on this socket and returns in in the |
196 |
|
* passed in SocketImpl. |
197 |
|
* |
198 |
|
* @param impl The SocketImpl object to accept this connection. |
199 |
|
*/ |
200 |
|
protected native synchronized void accept(SocketImpl impl) |
201 |
|
throws IOException; |
202 |
|
|
203 |
|
/** |
204 |
|
* Returns the number of bytes that the caller can read from this socket |
205 |
|
* without blocking. |
206 |
|
* |
207 |
|
* @return The number of readable bytes before blocking |
208 |
|
* |
209 |
|
* @exception IOException If an error occurs |
210 |
|
*/ |
211 |
|
protected native int available() throws IOException; |
212 |
|
|
213 |
|
/** |
214 |
|
* Closes the socket. This will cause any InputStream or OutputStream |
215 |
|
* objects for this Socket to be closed as well. |
216 |
|
* <p> |
217 |
|
* Note that if the SO_LINGER option is set on this socket, then the |
218 |
|
* operation could block. |
219 |
|
* |
220 |
|
* @exception IOException If an error occurs |
221 |
|
*/ |
222 |
|
protected native void close () throws IOException; |
223 |
|
|
224 |
|
public void sendUrgentData(int data) |
225 |
|
{ |
226 |
|
throw new InternalError ("PlainSocketImpl::sendUrgentData not implemented"); |
227 |
|
} |
228 |
|
|
229 |
|
/** |
230 |
* Internal method used by SocketInputStream for reading data from |
* Internal method used by SocketInputStream for reading data from |
231 |
* the connection. Reads up to len bytes of data into the buffer |
* the connection. Reads up to len bytes of data into the buffer |
232 |
* buf starting at offset bytes into the buffer. |
* buf starting at offset bytes into the buffer. |
249 |
throws IOException; |
throws IOException; |
250 |
|
|
251 |
/** |
/** |
|
* Sets the specified option on a socket to the passed in object. For |
|
|
* options that take an integer argument, the passed in object is an |
|
|
* Integer. The option_id parameter is one of the defined constants in |
|
|
* this interface. |
|
|
* |
|
|
* @param option_id The identifier of the option |
|
|
* @param val The value to set the option to |
|
|
* |
|
|
* @exception SocketException If an error occurs |
|
|
*/ |
|
|
public native void setOption(int option_id, Object val) |
|
|
throws SocketException; |
|
|
|
|
|
/** |
|
|
* Returns the current setting of the specified option. The Object returned |
|
|
* will be an Integer for options that have integer values. The option_id |
|
|
* is one of the defined constants in this interface. |
|
|
* |
|
|
* @param option_id The option identifier |
|
|
* |
|
|
* @return The current value of the option |
|
|
* |
|
|
* @exception SocketException If an error occurs |
|
|
*/ |
|
|
public native Object getOption(int option_id) |
|
|
throws SocketException; |
|
|
|
|
|
/** |
|
252 |
* Returns an InputStream object for reading from this socket. This will |
* Returns an InputStream object for reading from this socket. This will |
253 |
* be an instance of SocketInputStream. |
* be an instance of SocketInputStream. |
254 |
* |
* |
273 |
{ |
{ |
274 |
return(new SocketOutputStream(this)); |
return(new SocketOutputStream(this)); |
275 |
} |
} |
276 |
|
} |
|
public void connect(SocketAddress address, int timeout) |
|
|
{ |
|
|
throw new InternalError ("PlainSocketImpl::connect not implemented"); |
|
|
} |
|
|
|
|
|
public void sendUrgentData(int data) |
|
|
{ |
|
|
throw new InternalError ("PlainSocketImpl::sendUrgentData not implemented"); |
|
|
} |
|
|
|
|
|
public void shutdownInput() |
|
|
{ |
|
|
throw new InternalError ("PlainSocketImpl::shutdownInput not implemented"); |
|
|
} |
|
|
|
|
|
public void shutdownOutput() |
|
|
{ |
|
|
throw new InternalError ("PlainSocketImpl::shutdownOutput not implemented"); |
|
|
} |
|
|
} // class PlainSocketImpl |
|