| 152 | } |
| 153 | |
| 154 | public class Session { |
| 155 | private final ReliableUdpHandle handle; |
| 156 | private final SocketAddress peer; |
| 157 | private final LongConcurrentHashMap<Packet> sendWindow = new LongConcurrentHashMap<>(); |
| 158 | private final AtomicLong serialIdGenerator = new AtomicLong(1); |
| 159 | private final LongConcurrentHashMap<Packet> recvWindow = new LongConcurrentHashMap<>(); |
| 160 | |
| 161 | private long lastDispatchedSerialId; |
| 162 | private long maxRecvPacketSerialId; |
| 163 | |
| 164 | public Session(SocketAddress peer, ReliableUdpHandle handle) { |
| 165 | this.handle = handle; |
| 166 | this.peer = peer; |
| 167 | sessions.put(peer, this); |
| 168 | } |
| 169 | |
| 170 | public boolean send(byte[] bytes, int offset, int length) { |
| 171 | if (length > MaxPacketLength) |
| 172 | throw new IllegalArgumentException("length > MaxPacketLength: " + MaxPacketLength); |
| 173 | |
| 174 | var serialId = serialIdGenerator.getAndIncrement(); |
| 175 | var packet = new Packet(serialId, bytes, offset, length); |
| 176 | sendWindow.put(packet.serialId, packet); |
| 177 | |
| 178 | // start auto resend timer. |
| 179 | packet.resendTimerTask = Task.scheduleUnsafe(3000, 3000, () -> sendTo(peer, packet)); |
| 180 | return sendTo(peer, packet); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | private boolean sendTo(SocketAddress peer, Serializable p) { |
| 185 | try { |
nothing calls this directly
no outgoing calls
no test coverage detected