Example #1
0
        private void SendPackets(Socket h)
        {
            lock (m_packetQueue)
            {
                Packet packet = m_packetQueue.Peek();

                while (packet != null)
                {
                    int  bytesWritten = (0);
                    bool success      = SocketBase.Write(h, packet.GetData(), ref bytesWritten);

                    // Failed to send data. Most probably sending too much, break and
                    // hope for the best next time
                    if (!success)
                    {
                        Debug.Check(false);
                        behaviac.Debug.LogWarning("A packet is not correctly sent...\n");
                        break;
                    }

                    m_packetQueue.Dequeue();    // 'Commit' pop if data sent.
                    packet = m_packetQueue.Peek();
                }
            }
        }
Example #2
0
        //~ConnectorImpl()
        //{
        //}

        private void SendInitialSettings()
        {
            InitialSettingsPacket initialPacket = new InitialSettingsPacket();

            initialPacket.Init();
            int bytesWritten = 0;

            if (!SocketBase.Write(m_writeSocket, initialPacket.GetData(), ref bytesWritten))
            {
                Log("behaviac: Couldn't send initial settings.\n");
            }

            gs_packetsStats.init++;
        }
        protected void SendExistingPackets()
        {
            int packetsCount = 0;

            foreach (Packet p in this.m_packetPool)
            {
                int bytesWritten = (0);
                SocketBase.Write(m_writeSocket, p.GetData(), ref bytesWritten);
                packetsCount++;
            }

            //wait for the finish
            System.Threading.Thread.Sleep(1000);

            this.m_packetPool.Clear();
        }
        protected void SendAllPackets()
        {
            if (this.m_writeSocket != null && this.m_writeSocket.Connected)
            {
                for (int i = 0; i < m_maxTracedThreads; ++i)
                {
                    if (m_packetBuffers[i] != null && !m_packetBuffers[i].m_free)
                    {
#if USING_BEHAVIAC_SEQUENTIAL
                        if (!m_packetBuffers[i].CollectPackets(m_packetCollection))
                        {
                            break;
                        }
#else
                        m_packetBuffers[i].SendPackets(m_writeSocket);
#endif
                    }
                }

#if USING_BEHAVIAC_SEQUENTIAL
                // TODO: Deal with Socket.Write failures.
                // (right now packet is lost).
                m_packetCollection.Sort();

                int      endIndex = 0;
                Packet[] packets  = m_packetCollection.GetPackets(ref endIndex);

                for (int i = 0; i < endIndex; ++i)
                {
                    Packet p = packets[i];

                    int bytesWritten = (0);
                    SocketBase.Write(this.m_writeSocket, p.GetData(), ref bytesWritten);

                    if (this.m_writeSocket == null || !this.m_writeSocket.Connected || bytesWritten <= 0)
                    {
                        break;
                    }
                }

                m_packetCollection.Reset();
#endif
                this.m_packetsCount = 0;
            }
        }