wrapper java.net.RegulatedSendSocket {
// Should be able to inherit from Socket, and only replace a few methods.
requires java.net.NRegulatedOutputStream;
requires java.net.NaccioNetworkInputStream;
requires java.net.SocketHelp;
import naccio.library.Check;
import java.net.*;
import java.io.*;
state
public RNetConnection rnc;
// These are the only operations that can't be inherited from Socket.pfi!
wrapper InputStream getInputStream () {
#;
result = new NaccioNetworkInputStream (result, rnc);
}
wrapper OutputStream getOutputStream () {
#;
result = new NRegulatedOutputStream (result, rnc);
}
// The rest should be inherited from Socket.pfi
// 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 pre 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.getHostName (), localport),
new RNetAddress (address, port));
#;
rsetup ();
}
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");
#;
}
wrapper synchronized void close () {
#;
RNetwork.closeConnection (rnc);
}
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