|
| 1 | +package com.datagramSocket; |
| 2 | + |
| 3 | +import java.net.DatagramPacket; |
| 4 | +import java.net.DatagramSocket; |
| 5 | +import java.net.InetAddress; |
| 6 | +import java.net.SocketAddress; |
| 7 | +import java.net.SocketOption; |
| 8 | + |
| 9 | +import liquidjava.specification.ExternalRefinementsFor; |
| 10 | +import liquidjava.specification.Refinement; |
| 11 | +import liquidjava.specification.RefinementAlias; |
| 12 | +import liquidjava.specification.StateRefinement; |
| 13 | +import liquidjava.specification.StateSet; |
| 14 | + |
| 15 | +@RefinementAlias("Port(int n) { 0 <= n && n <= 65535 }") |
| 16 | +@RefinementAlias("NonNegative(int v) { v >= 0 }") |
| 17 | +@RefinementAlias("Positive(int v) { v > 0 }") |
| 18 | +@RefinementAlias("TrafficClass(int tc) { 0 <= tc && tc <= 255 }") |
| 19 | +@ExternalRefinementsFor("java.net.DatagramSocket") |
| 20 | +@StateSet({"unbound", "bound", "connected", "disconnected", "closed" }) |
| 21 | +public interface DatagramSocketRefinements { |
| 22 | + |
| 23 | + @StateRefinement(to="bound(this)") // "Constructs a datagram socket and binds it to any available port on the local host machine" |
| 24 | + public void DatagramSocket(); |
| 25 | + |
| 26 | + @StateRefinement(to="bound(this)") |
| 27 | + public void DatagramSocket(SocketAddress bindaddr); // cant check for null value to start with unbound state |
| 28 | + |
| 29 | + @StateRefinement(to="bound(this)") |
| 30 | + public void DatagramSocket(@Refinement("Port(_)") int port); |
| 31 | + |
| 32 | + @StateRefinement(from="unbound(this)", to="bound(this)") |
| 33 | + public void bind(SocketAddress addr); |
| 34 | + |
| 35 | + @StateRefinement(from="bound(this)", to="connected(this)") |
| 36 | + @StateRefinement(from="unbound(this)", to="connected(this)") // "If this socket is not bound then this method will first cause the socket to be bound to an address that is assigned automatically (...)" |
| 37 | + public void connect(InetAddress address, @Refinement("Port(_)") int port); // cant check if address is null |
| 38 | + |
| 39 | + @StateRefinement(from="bound(this)", to="connected(this)") |
| 40 | + @StateRefinement(from="unbound(this)", to="connected(this)") |
| 41 | + public void connect(SocketAddress addr); // "If given an InetSocketAddress, this method behaves as if invoking connect(InetAddress,int)" |
| 42 | + |
| 43 | + @StateRefinement(from="connected(this)", to="disconnected(this)") |
| 44 | + public void disconnect(); |
| 45 | + |
| 46 | + @StateRefinement(from="connected(this)") |
| 47 | + public void send(DatagramPacket p); |
| 48 | + |
| 49 | + @StateRefinement(from="connected(this)") |
| 50 | + public void receive(DatagramPacket p); |
| 51 | + |
| 52 | + @StateRefinement(from="!closed(this)", to="closed(this)") |
| 53 | + public void close(); |
| 54 | + |
| 55 | + @StateRefinement(from="unbound(this)") |
| 56 | + @StateRefinement(from="bound(this)") |
| 57 | + @StateRefinement(from="connected(this)") |
| 58 | + @StateRefinement(from="disconnected(this)") |
| 59 | + public <T> DatagramSocket setOption(SocketOption<T> name, T value); // "IOException - if an I/O error occurs, or if the socket is closed." |
| 60 | + |
| 61 | + @StateRefinement(from="unbound(this)") |
| 62 | + @StateRefinement(from="bound(this)") |
| 63 | + @StateRefinement(from="connected(this)") |
| 64 | + @StateRefinement(from="disconnected(this)") |
| 65 | + public <T> T getOption(SocketOption<T> name); // same as above |
| 66 | + |
| 67 | + public void setSoTimeout(@Refinement("NonNegative(_)") int timeout); |
| 68 | + |
| 69 | + @Refinement("NonNegative(_)") |
| 70 | + public int getSoTimeout(); |
| 71 | + |
| 72 | + public void setSendBufferSize(@Refinement("Positive(_)") int size); |
| 73 | + |
| 74 | + @Refinement("Positive(_)") |
| 75 | + public int getSendBufferSize(); |
| 76 | + |
| 77 | + public void setReceiveBufferSize(@Refinement("Positive(_)") int size); |
| 78 | + |
| 79 | + @Refinement("Positive(_)") |
| 80 | + public int getReceiveBufferSize(); |
| 81 | + |
| 82 | + public void setTrafficClass(@Refinement("TrafficClass(_)") int tc); |
| 83 | + |
| 84 | + @Refinement("TrafficClass(_)") |
| 85 | + public int getTrafficClass(); |
| 86 | +} |
| 87 | + |
0 commit comments