Example #1
0
        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);
        }
Example #3
0
        public bool add(EzyPacket packet)
        {
            int queueSize = queue.size();

            if (queueSize >= capacity)
            {
                return(false);
            }
            bool success = queue.offer(packet);

            return(success);
        }
Example #4
0
 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();
     }
 }
Example #5
0
 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);
     }
 }
Example #6
0
        public EzyPacket take()
        {
            EzyPacket packet = queue.take();

            return(packet);
        }
Example #7
0
 protected abstract int writeToSocket(EzyPacket packet);