protected override void update() { while (true) { if (!active) { return; } EzyPacket packet = packetQueue.take(); if (packet == null) { return; } int writtenBytes = writeToSocket(packet); packet.release(); if (writtenBytes <= 0) { return; } networkStatistics.getSocketStats().getNetworkStats().addWrittenPackets(1); networkStatistics.getSocketStats().getNetworkStats().addWrittenBytes(writtenBytes); } }
public void response(EzyPackage pack) { Object bytes = encodeData(pack.getData()); EzyPacket packet = createPacket(bytes, pack); packetQueue.add(packet); }
public bool add(EzyPacket packet) { int queueSize = queue.size(); if (queueSize >= capacity) { return(false); } bool success = queue.offer(packet); return(success); }
protected override int writeToSocket(EzyPacket packet) { try { byte[] bytes = (byte[])packet.getData(); int bytesToWrite = bytes.Length; int writtenByes = datagramChannel.Send(bytes, bytesToWrite); return(writtenByes); } catch (Exception e) { logger.warn("I/O error at socket-writer", e); return(-1); } finally { packet.release(); } }
protected override int writeToSocket(EzyPacket packet) { try { byte[] buffer = (byte[])packet.getData(); NetworkStream stream = socket.GetStream(); stream.Write(buffer, 0, buffer.Length); stream.Flush(); int writtenBytes = buffer.Length; return(writtenBytes); } catch (Exception ex) { logger.warn("I/O error at socket-writer", ex); return(-1); } }
public EzyPacket take() { EzyPacket packet = queue.take(); return(packet); }
protected abstract int writeToSocket(EzyPacket packet);