"

2013 FRC Java API

"

com.sun.squawk.platform.posix
Class GCFSocketsImpl

java.lang.Object
  extended by com.sun.squawk.platform.posix.GCFSocketsImpl
All Implemented Interfaces:
GCFSockets

public class GCFSocketsImpl
extends Object
implements GCFSockets

POSIX implementation of GCFSockets that calls the BSD socket API.


Field Summary
static boolean DEBUG
           
static boolean NBIO_WORKS
           
 
Constructor Summary
GCFSocketsImpl()
           
 
Method Summary
 int accept(int fd)
          Accept client connections on server socket fd.
 int available(int fd)
          Gets the number of bytes that can be read without blocking.
 void close(int fd)
          Closes the socket connection.
 int getSockOpt(int socket, int option_name)
          get a socket option
 int getSockOpt(int socket, int level, int option_name)
          get a socket option
 String inet_ntop(int in)
          Takes an IPv4 Internet address and returns string representing the address in `.' notation
 int open(String hostname, int port, int mode)
          Opens a TCP connection to a server.
 int openServer(int port, int backlog)
          Opens a server TCP connection to clients.
 int readBuf(int fd, byte[] b, int offset, int length)
          Reads from the open socket connection.
 int readByte(int fd)
          Read a byte from the open socket connection.
 int readByte(int fd, byte[] b)
          Read a byte from the open socket connection.
 void setSockOpt(int socket, int option_name, int option_value)
          set a socket option
 void setSockOpt(int socket, int level, int option_name, int option_value)
          set a socket option
 int writeBuf(int fd, byte[] buffer, int off, int len)
          Writes to the open socket connection.
 int writeByte(int fd, int b)
          Writes to the open socket connection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values

NBIO_WORKS

public static final boolean NBIO_WORKS
See Also:
Constant Field Values
Constructor Detail

GCFSocketsImpl

public GCFSocketsImpl()
Method Detail

open

public int open(String hostname,
                int port,
                int mode)
         throws IOException
Description copied from interface: GCFSockets
Opens a TCP connection to a server.

Specified by:
open in interface GCFSockets
Parameters:
hostname - host name
port - TCP port at host
mode - connection mode (ignored, should be read/write?
Returns:
a native handle to the network connection.
Throws:
IOException

inet_ntop

public String inet_ntop(int in)
Takes an IPv4 Internet address and returns string representing the address in `.' notation

Parameters:
in - the opaque bytes of an IPv4 "struct in_addr"
Returns:
String

openServer

public int openServer(int port,
                      int backlog)
               throws IOException
Opens a server TCP connection to clients. Creates, binds, and listens

Specified by:
openServer in interface GCFSockets
Parameters:
port - local TCP port to listen on
backlog - listen backlog.
Returns:
a native handle to the network connection.
Throws:
IOException

accept

public int accept(int fd)
           throws IOException
Accept client connections on server socket fd. Blocks until a client connects.

Specified by:
accept in interface GCFSockets
Parameters:
fd - open server socket. See openServer(int, int).
Returns:
a native handle to the network connection.
Throws:
IOException

readBuf

public int readBuf(int fd,
                   byte[] b,
                   int offset,
                   int length)
            throws IOException
Description copied from interface: GCFSockets
Reads from the open socket connection.

Specified by:
readBuf in interface GCFSockets
Parameters:
fd - the socket descriptor
b - the buffer into which the data is read.
offset - the start offset in array b at which the data is written.
length - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no mo data because the end of the stream has been reached.
Throws:
IOException

readByte

public int readByte(int fd,
                    byte[] b)
             throws IOException
Description copied from interface: GCFSockets
Read a byte from the open socket connection. This function will return an unsigned byte (0-255) if data was read, or -1 if EOF was reached. This version is passed a temporary buffer instead of allocating one.

Specified by:
readByte in interface GCFSockets
Parameters:
fd - the socket descriptor
Returns:
the byte read or -1
Throws:
IOException

readByte

public int readByte(int fd)
             throws IOException
Description copied from interface: GCFSockets
Read a byte from the open socket connection. This function will return an unsigned byte (0-255) if data was read, or -1 if EOF was reached.

Specified by:
readByte in interface GCFSockets
Returns:
the byte read or -1
Throws:
IOException

writeBuf

public int writeBuf(int fd,
                    byte[] buffer,
                    int off,
                    int len)
             throws IOException
Description copied from interface: GCFSockets
Writes to the open socket connection.

Specified by:
writeBuf in interface GCFSockets
Parameters:
fd - the socket descriptor
buffer - the buffer of the data to write
off - the start offset in array b at which the data is written.
len - the number of bytes to write.
Returns:
the total number of bytes written
Throws:
IOException

writeByte

public int writeByte(int fd,
                     int b)
              throws IOException
Description copied from interface: GCFSockets
Writes to the open socket connection.

Specified by:
writeByte in interface GCFSockets
Parameters:
fd - the socket descriptor
b - the byte to write
Returns:
the total number of bytes written
Throws:
IOException

available

public int available(int fd)
              throws IOException
Description copied from interface: GCFSockets
Gets the number of bytes that can be read without blocking.

Specified by:
available in interface GCFSockets
Parameters:
fd - the socket descriptor
Returns:
number of bytes that can be read without blocking
Throws:
IOException

close

public void close(int fd)
           throws IOException
Description copied from interface: GCFSockets
Closes the socket connection.

Specified by:
close in interface GCFSockets
Parameters:
fd - the socket descriptor
Throws:
IOException

setSockOpt

public void setSockOpt(int socket,
                       int level,
                       int option_name,
                       int option_value)
                throws IOException
set a socket option

Parameters:
socket - socket descriptor
level - Socket.SOL_SOCKET, etc.
option_name -
option_value - new value
Throws:
IOException - on error

getSockOpt

public int getSockOpt(int socket,
                      int level,
                      int option_name)
               throws IOException
get a socket option

Parameters:
socket - socket descriptor
level - Socket.SOL_SOCKET, etc.
option_name -
Returns:
socket option value
Throws:
IOException - on error

setSockOpt

public void setSockOpt(int socket,
                       int option_name,
                       int option_value)
                throws IOException
set a socket option

Specified by:
setSockOpt in interface GCFSockets
Parameters:
socket - socket descriptor
option_name -
option_value - new value
Throws:
IOException - on error

getSockOpt

public int getSockOpt(int socket,
                      int option_name)
               throws IOException
get a socket option

Specified by:
getSockOpt in interface GCFSockets
Parameters:
socket - socket descriptor
option_name -
Returns:
option value
Throws:
IOException - on error

"

2013 FRC Java API

"

"
For updated information see the Java FRC site
"