예제 #1
0
        /// <summary>
        /// Add a osc message to the send queue
        /// </summary>
        /// <param name="message">message to send</param>
        public void Send(OscPacket message)
        {
            if (State == OscSocketState.Connected)
            {
                lock (m_Lock)
                {
                    m_QueueEmpty.Reset();

                    if (m_Count >= m_SendQueue.Length)
                    {
                        return;
                    }

                    m_SendQueue[m_WriteIndex] = message;

                    m_WriteIndex = NextWriteIndex;
                    m_Count++;

                    if (m_Count == 1)
                    {
                        int size = message.Write(m_Bytes);

                        Socket.BeginSend(m_Bytes, 0, size, SocketFlags, Send_Callback, message);
                    }
                }
            }
        }
예제 #2
0
        void Send_Callback(IAsyncResult ar)
        {
            lock (m_Lock)
            {
                try
                {
                    SocketError error;

                    Socket.EndSend(ar, out error);

                    if (m_SendQueue[m_ReadIndex].IsSameInstance(ar.AsyncState as OscPacket) == false)
                    {
                        Debug.WriteLine("Objects do not match at index " + m_ReadIndex);
                    }

                    m_Count--;
                    m_ReadIndex = NextReadIndex;

                    if (m_Count > 0 && State == OscSocketState.Connected)
                    {
                        OscPacket packet = m_SendQueue[m_ReadIndex];

                        int size = packet.Write(m_Bytes);

                        Socket.BeginSend(m_Bytes, 0, size, SocketFlags, Send_Callback, packet);
                    }
                    else
                    {
                        m_QueueEmpty.Set();
                    }
                }
                catch
                {
                    m_QueueEmpty.Set();
                }
            }
        }