wrapper java.net.RegulatedSendDatagramSocket requiredif RNetwork, RNetAddress, RNetConnection, RNetListener {
//
// Alternate version of DatagramSocket platform interface designed
// to support soft bandwidth limit.
//
requires java.net.SocketHelp;
import naccio.library.NCheck;
import java.net.*;
state RNetAddress local; RNetListener port;
passwrapper <clinit>;
helper void rsetup () {
// Turning off checking is only necessary so we don't generate
// superfluous calls to SecurityManager methods when testing
// mimicking the JDK. In normal situations, this would not be
// necessary.
if (NCheck.isChecking ()) {
NCheck.noChecking ();
local = new RNetAddress (getLocalAddress (), getLocalPort ());
NCheck.resumeChecking ();
} else {
local = new RNetAddress (getLocalAddress (), getLocalPort ());
}
port = new RNetListener (local);
RNetwork.openDatagramPort (port);
}
// Don't care about the port number (uses port 0 by default)
wrapper DatagramSocket () {
#;
rsetup ();
}
wrapper DatagramSocket (int port) {
#;
rsetup ();
}
wrapper DatagramSocket (int port, InetAddress laddr) {
#;
rsetup ();
}
// Send/Receive
wrapper void send (DatagramPacket p) {
synchronized (p) {
synchronized (this) {
RNetAddress remote;
remote = new RNetAddress (p.getAddress (), p.getPort ());
RNetwork.preSendDatagram (local, remote, p.getLength ());
#;
RNetwork.postSendDatagram (local, remote, p.getLength ());
}
}
}
wrapper synchronized void receive (DatagramPacket p) {
synchronized (p) {
synchronized (this) {
RNetwork.preReceiveDatagram (local, p.getLength ());
#;
RNetAddress remote;
remote = new RNetAddress (p.getAddress (), p.getPort ());
RNetwork.postReceiveDatagram (local, remote, p.getLength ());
}
}
}
wrapper void close () {
RNetwork.closeDatagramPort (port);
#;
}
}
Naccio Home Page
University of Virginia, Computer Science