Beispiel #1
0
        public unsafe int ReceiveMessageEx(NetworkInterfaceEndPoint local, ref UdpCHeader header, void *payloadData, int payloadLen, ref NetworkInterfaceEndPoint remote)
        {
            IPCData data;

            if (!m_IPCQueue.Peek(*(int *)local.data, out data))
            {
                return(0);
            }
            GetEndPointByHandle(data.from, out remote);

            int totalLength = 0;
            var curLength   = Math.Min(UdpCHeader.Length, data.length - totalLength);

            fixed(void *headerData = header.Data)
            {
                UnsafeUtility.MemCpy(headerData, data.data + totalLength, curLength);
            }

            totalLength += curLength;

            curLength = Math.Min(payloadLen, data.length - totalLength);
            UnsafeUtility.MemCpy(payloadData, data.data + totalLength, curLength);
            totalLength += curLength;

            if (totalLength < data.length)
            {
                return(-1);
            }
            m_IPCQueue.Dequeue(*(int *)local.data, out data);

            return(totalLength);
        }
        public unsafe int ReceiveMessageEx(NetworkInterfaceEndPoint local, network_iovec *iov, int iov_len, ref NetworkInterfaceEndPoint remote)
        {
            IPCData data;

            if (!m_IPCQueue.Peek(*(int *)local.data, out data))
            {
                return(0);
            }
            GetEndPointByHandle(data.from, out remote);

            int totalLength = 0;

            for (int i = 0; i < iov_len; i++)
            {
                var curLength = Math.Min(iov[i].len, data.length - totalLength);
                UnsafeUtility.MemCpy(iov[i].buf, data.data + totalLength, curLength);
                totalLength += curLength;
                iov[i].len   = curLength;
            }

            if (totalLength < data.length)
            {
                return(-1);
            }
            m_IPCQueue.Dequeue(*(int *)local.data, out data);

            return(totalLength);
        }
Beispiel #3
0
        public void NativeMultiQueue_SimpleScenarios()
        {
            using (NativeMultiQueue <int> eventQ = new NativeMultiQueue <int>(5))
            {
                for (int connection = 0; connection < 5; connection++)
                {
                    // Test Add
                    int item = 0;

                    eventQ.Enqueue(connection, 1);
                    eventQ.Enqueue(connection, 1);
                    eventQ.Enqueue(connection, 1);
                    eventQ.Enqueue(connection, 1);
                    eventQ.Enqueue(connection, 1);

                    // Add grows capacity
                    eventQ.Enqueue(connection, 1);

                    // Test Rem
                    Assert.True(eventQ.Dequeue(connection, out item));
                    Assert.True(eventQ.Dequeue(connection, out item));
                    Assert.True(eventQ.Dequeue(connection, out item));
                    Assert.True(eventQ.Dequeue(connection, out item));
                    Assert.True(eventQ.Dequeue(connection, out item));

                    // Remove with grown capacity
                    Assert.True(eventQ.Dequeue(connection, out item));
                }
            }
        }
        public unsafe int ReceiveMessageEx(NetworkEndPoint local, network_iovec *iov, int iov_len, ref NetworkEndPoint remote)
        {
            IPCData data;

            if (!m_IPCQueue.Peek(local.ipc_handle, out data))
            {
                return(0);
            }
            NetworkEndPoint endpoint;

            if (!TryGetEndPointByHandle(data.from, out endpoint))
            {
                return(-1);
            }
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (endpoint.Family != NetworkFamily.IPC)
            {
                throw new InvalidDataException("An incorrect message was pushed to the IPC message queue");
            }
#endif

#if (UNITY_EDITOR_OSX || ((UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR))
            remote.family.sa_family = (byte)NetworkFamily.IPC;
#else
            remote.family.sa_family = (ushort)NetworkFamily.IPC;
#endif
            remote.ipc_handle = endpoint.ipc_handle;
            remote.nbo_port   = endpoint.nbo_port;
            remote.length     = 6;

            int totalLength = 0;
            for (int i = 0; i < iov_len; i++)
            {
                var curLength = Math.Min(iov[i].len, data.length - totalLength);
                UnsafeUtility.MemCpy(iov[i].buf, data.data + totalLength, curLength);
                totalLength += curLength;
                iov[i].len   = curLength;
            }

            if (totalLength < data.length)
            {
                return(-1);
            }
            m_IPCQueue.Dequeue(local.ipc_handle, out data);

            return(totalLength);
        }