Methods Summary |
---|
public int | available()Returns the number of bytes that can be read (or skipped over) from
this input stream without blocking by the next caller of a method for
this input stream. The next caller might be the same thread or
another thread.
if (count > 0) {
/*
* The next read will only return the bytes in the buffer,
* so only return the number of bytes in the buffer.
* While available can return a number less than than the next
* read will get, it should not return more.
*/
return count;
}
// The buffer is empty, so the next read will go directly to native
return available0();
|
private native int | available0()Get the number of bytes that can be read without blocking,
accesses the handle field.
|
private void | checkOption(byte option)Check a socket option to make sure it's a valid option.
if (option == SocketConnection.KEEPALIVE
|| option == SocketConnection.LINGER
|| option == SocketConnection.SNDBUF
|| option == SocketConnection.RCVBUF
|| option == SocketConnection.DELAY) {
return;
}
throw new IllegalArgumentException("Unsupported Socket Option");
|
private native void | close0()Close the connection, accesses the handle field.
|
protected void | closeOutputStream()Called once by the child output stream. The output side of the socket
will be shutdown and then the parent method will be called.
/*
* Shutdown the output gracefully closes the sending side of the
* TCP connection by sending all pending data and the FIN flag.
*/
shutdownOutput0();
outputShutdown = true;
super.closeOutputStream();
|
public void | connect(java.lang.String name, int mode, boolean timeouts)Connect to a server.
byte[] szHost;
verifyPermissionCheck();
/*
* The host and port were set by overridding the openPrim method of
* our super class.
*/
if (port < 0) {
throw new IllegalArgumentException("Missing port number");
}
szHost = Util.toCString(host);
open0(szHost, port);
registerCleanup();
|
public void | disconnect()Disconnect from the server.
/*
* Only shutdown or close of the sending side of a connection is
* defined in the TCP spec.
*
* The receiver can only abort (reset) the entire connection to stop
* the a sender from sending. InputStream close already causes
* an reads to fail so no native action is needed.
*
* Shutdown the output gracefully closes the sending side of the
* TCP connection by sending all pending data and the FIN flag.
*/
if (!outputShutdown) {
shutdownOutput0();
}
close0();
|
private native void | finalize()Native finalizer
|
public java.lang.String | getAddress()Gets the remote address to which the socket is bound.
The address can be either the remote host name or the IP
address(if available).
ensureOpen();
return getHost0(false);
|
private native java.lang.String | getHost0(boolean local)Get the requested IP number.
|
public java.lang.String | getLocalAddress()Gets the local address to which the socket is bound.
The host address(IP number) that can be used to connect to this
end of the socket connection from an external system.
Since IP addresses may be dynamically assigned a remote application
will need to be robust in the face of IP number reasssignment.
The local hostname (if available) can be accessed from
System.getProperty("microedition.hostname")
ensureOpen();
return getHost0(true);
|
public int | getLocalPort()Returns the local port to which this socket is bound.
ensureOpen();
return getPort0(true);
|
public int | getPort()Returns the remote port to which this socket is bound.
ensureOpen();
return getPort0(false);
|
private native int | getPort0(boolean local)Get the requested port number.
|
private native int | getSockOpt0(int option)Get the requested socket option.
|
public int | getSocketOption(byte option)Get a socket option for the connection.
checkOption(option);
ensureOpen();
return getSockOpt0(option);
|
protected int | nonBufferedRead(byte[] b, int off, int len)Reads up to len bytes of data from the input stream into
an array of bytes, blocks until at least one byte is available.
Sets the eof field of the connection when the native read
returns -1.
int bytesRead;
for (;;) {
try {
bytesRead = read0(b, off, len);
} finally {
if (iStreams == 0) {
throw new InterruptedIOException("Stream closed");
}
}
if (bytesRead == -1) {
eof = true;
return -1;
}
if (bytesRead != 0) {
return bytesRead;
}
/* Wait a while for I/O to become ready */
GeneralBase.iowait();
}
|
public void | open(int handle)Create a Java connection object from an open TCP socket.
This method is only used by com.sun.midp.io.j2me.serversocket.Socket;
this.handle = handle;
try {
connectionOpen = true;
checkForPermission(getAddress());
} catch (Exception e) {
connectionOpen = false;
if (e instanceof IOException) {
e = new SecurityException("Unknown TCP client");
}
try {
close0();
} catch (IOException ioe) {
// ignore
}
throw (RuntimeException)e;
}
registerCleanup();
|
private native void | open0(byte[] szHost, int port)Connect to a server and fillin the handle field.
|
public Connection | openPrim(java.lang.String name, int mode, boolean timeouts)Open a client or server socket connection.
The name string for this protocol should be:
"socket://<name or IP number>:<port number>
We allow "socket://:nnnn" to mean an inbound server socket connection.
HttpUrl url;
if (name.charAt(0) != '/" || name.charAt(1) != '/") {
throw new IllegalArgumentException(
"Protocol must start with \"//\"");
}
url = new HttpUrl("socket", name); // parse name into host and port
/*
* Since we reused the HttpUrl parser, we must make sure that
* there was nothing past the authority in the URL.
*/
if (url.path != null || url.query != null || url.fragment != null) {
throw new IllegalArgumentException("Malformed address");
}
host = url.host;
port = url.port;
/*
* If 'host' == null then we are a server endpoint at
* port 'port'.
*/
if (host != null) {
// this will call the connect method which uses the host and port
return super.openPrim(name, mode, timeouts);
}
// We allow "socket://:nnnn" to mean an inbound TCP server socket.
com.sun.midp.io.j2me.serversocket.Socket con;
con = new com.sun.midp.io.j2me.serversocket.Socket();
con.open(port);
return con;
|
private native int | read0(byte[] b, int off, int len)Read from the socket, accesses the handle field.
|
private native void | registerCleanup()Register with the native cleanup code, accesses the handle field.
|
private native void | setSockOpt0(int option, int value)Set the requested socket option.
|
public void | setSocketOption(byte option, int value)Set a socket option for the connection.
Options inform the low level networking code about intended
usage patterns that the application will use in dealing with
the socket connection.
checkOption(option);
if (value < 0) {
throw new IllegalArgumentException("Unsupported Socket Option");
}
ensureOpen();
setSockOpt0(option, value);
|
private native void | shutdownOutput0()Shutdown the output side of the connection.
|
private native int | write0(byte[] b, int off, int len)Write to the socket, accesses the handle field.
|
public int | writeBytes(byte[] b, int off, int len)Writes len bytes from the specified byte array
starting at offset off to this output stream.
Polling the will be done by our super class.
return write0(b, off, len);
|