wrapper java.net.Socket requiredif RNetwork, RNetAddress, RNetConnection, RNetListener {
requires java.net.NaccioNetworkInputStream;
requires java.net.NaccioNetworkOutputStream;
requires java.net.SocketHelp;
import naccio.library.NCheck;
import java.net.*;
import java.io.*;
state public RNetConnection rnc;
// Called when a ServerSocket accepts a connection
helper void setupClientSocket (RNetListener rnl) {
rnc = new RNetConnection
(new RNetAddress (getLocalAddress (), getLocalPort ()),
new RNetAddress (getInetAddress (), getPort ()));
}
helper void rsetup () {
rnc = new RNetConnection
(new RNetAddress (getLocalAddress (), getLocalPort ()),
new RNetAddress (getInetAddress (), getPort ()));
RNetwork.postOpenConnection (rnc);
}
helper static void preOpen (RNetAddress local, RNetAddress remote) {
RNetConnection trnc;
trnc = new RNetConnection (local, remote);
RNetwork.preOpenConnection (trnc);
}
// wrapper Socket () - No connection is made, so no wrapper is needed.
wrapper Socket (SocketImpl impl) {
NCheck.fatalViolation ("User-specified SocketImpl objects are not yet supported by Naccio.");
#;
}
wrapper Socket (String host, int port) {
preOpen (new RNetAddress (SocketHelp.getLocalAddress ()),
new RNetAddress (SocketHelp.absoluteName (host), port));
#;
rsetup ();
}
wrapper Socket (InetAddress address, int port) {
preOpen (new RNetAddress (SocketHelp.getLocalAddress ()),
new RNetAddress (address, port));
#;
rsetup ();
}
wrapper Socket (String host, int port, InetAddress localAddr, int localPort) {
preOpen (new RNetAddress (localAddr, localPort),
new RNetAddress (SocketHelp.absoluteName (host), port));
#;
rsetup ();
}
wrapper Socket (InetAddress address, int port, InetAddress localAddr, int localport) {
preOpen (new RNetAddress (localAddr, localport),
new RNetAddress (address, port));
#;
rsetup ();
}
// The two constructors below are deprecated, and should really use
// a DatagramSocket if stream is false.
wrapper Socket(String host, int port, boolean stream) {
NCheck.fatalViolation ("Deprecated Socket constructor");
#;
}
wrapper Socket(InetAddress address, int port, boolean stream) {
NCheck.fatalViolation ("Deprecated Socket constructor");
#;
}
// Input/Output
wrapper InputStream getInputStream() {
#;
result = new NaccioNetworkInputStream (result, rnc);
}
wrapper OutputStream getOutputStream () {
#;
result = new NaccioNetworkOutputStream (result, rnc);
}
// Behavior control: no checking for these, but should probably add resource operations.
// wrapper void setTcpNoDelay (boolean on)
// wrapper boolean getTcpNoDelay ()
// wrapper void setSoLinger (boolean on, int val)
// wrapper int getSoLinger ()
// wrapper synchronized void setSoTimeout (int timeout)
// wrapper synchronized int getSoTimeout ()
// Closing Connections
wrapper synchronized void close () {
#;
RNetwork.closeConnection (rnc);
}
// User-defined SocketImpl objects
wrapper static synchronized void setSocketImplFactory (SocketImplFactory fac) {
NCheck.fatalViolation ("User-specified SocketImpl objects are not yet supported by Naccio.");
#;
}
}
Naccio Home Page
University of Virginia, Computer Science