示例#1
0
        internal WebSocketProtocolComponent.Property[] CreateProperties(bool useZeroMaskingKey)
        {
            ThrowIfDisposed();

            // serialize marshaled property values in the property segment of the internal buffer
            // m_GCHandle.AddrOfPinnedObject() points to the address of m_InternalBuffer.Array
            IntPtr internalBufferPtr = m_GCHandle.AddrOfPinnedObject();
            int    offset            = m_PropertyBuffer.Offset;

            Marshal.WriteInt32(internalBufferPtr, offset, m_ReceiveBufferSize);
            offset += s_SizeOfUInt;
            Marshal.WriteInt32(internalBufferPtr, offset, m_SendBufferSize);
            offset += s_SizeOfUInt;
            Marshal.WriteIntPtr(internalBufferPtr, offset, internalBufferPtr + m_InternalBuffer.Offset);
            offset += IntPtr.Size;
            Marshal.WriteInt32(internalBufferPtr, offset, useZeroMaskingKey ? (int)1 : (int)0);

            int propertyCount = useZeroMaskingKey ? 4 : 3;

            WebSocketProtocolComponent.Property[] properties =
                new WebSocketProtocolComponent.Property[propertyCount];

            // Calculate the pointers to the positions of the properties within the internal buffer
            offset        = m_PropertyBuffer.Offset;
            properties[0] = new WebSocketProtocolComponent.Property()
            {
                Type         = WebSocketProtocolComponent.PropertyType.ReceiveBufferSize,
                PropertySize = (uint)s_SizeOfUInt,
                PropertyData = IntPtr.Add(internalBufferPtr, offset)
            };
            offset += s_SizeOfUInt;

            properties[1] = new WebSocketProtocolComponent.Property()
            {
                Type         = WebSocketProtocolComponent.PropertyType.SendBufferSize,
                PropertySize = (uint)s_SizeOfUInt,
                PropertyData = IntPtr.Add(internalBufferPtr, offset)
            };
            offset += s_SizeOfUInt;

            properties[2] = new WebSocketProtocolComponent.Property()
            {
                Type         = WebSocketProtocolComponent.PropertyType.AllocatedBuffer,
                PropertySize = (uint)m_NativeBuffer.Count,
                PropertyData = IntPtr.Add(internalBufferPtr, offset)
            };
            offset += IntPtr.Size;

            if (useZeroMaskingKey)
            {
                properties[3] = new WebSocketProtocolComponent.Property()
                {
                    Type         = WebSocketProtocolComponent.PropertyType.DisableMasking,
                    PropertySize = (uint)s_SizeOfBool,
                    PropertyData = IntPtr.Add(internalBufferPtr, offset)
                };
            }

            return(properties);
        }
        internal WebSocketProtocolComponent.Property[] CreateProperties(bool useZeroMaskingKey)
        {
            ThrowIfDisposed();
            // serialize marshaled property values in the property segment of the internal buffer
            IntPtr internalBufferPtr = m_GCHandle.AddrOfPinnedObject();
            int offset = m_PropertyBuffer.Offset;
            Marshal.WriteInt32(internalBufferPtr, offset, m_ReceiveBufferSize);
            offset += s_SizeOfUInt;
            Marshal.WriteInt32(internalBufferPtr, offset, m_SendBufferSize);
            offset += s_SizeOfUInt;
            Marshal.WriteIntPtr(internalBufferPtr, offset, internalBufferPtr);
            offset += IntPtr.Size;
            Marshal.WriteInt32(internalBufferPtr, offset, useZeroMaskingKey ? (int)1 : (int)0);

            int propertyCount = useZeroMaskingKey ? 4 : 3;
            WebSocketProtocolComponent.Property[] properties =
                new WebSocketProtocolComponent.Property[propertyCount];

            // Calculate the pointers to the positions of the properties within the internal buffer
            offset = m_PropertyBuffer.Offset;
            properties[0] = new WebSocketProtocolComponent.Property()
            {
                Type = WebSocketProtocolComponent.PropertyType.ReceiveBufferSize,
                PropertySize = (uint)s_SizeOfUInt,
                PropertyData = IntPtr.Add(internalBufferPtr, offset)
            };
            offset += s_SizeOfUInt;

            properties[1] = new WebSocketProtocolComponent.Property()
            {
                Type = WebSocketProtocolComponent.PropertyType.SendBufferSize,
                PropertySize = (uint)s_SizeOfUInt,
                PropertyData = IntPtr.Add(internalBufferPtr, offset)
            };
            offset += s_SizeOfUInt;

            properties[2] = new WebSocketProtocolComponent.Property()
            {
                Type = WebSocketProtocolComponent.PropertyType.AllocatedBuffer,
                PropertySize = (uint)m_NativeBuffer.Count,
                PropertyData = IntPtr.Add(internalBufferPtr, offset)
            };
            offset += IntPtr.Size;

            if (useZeroMaskingKey)
            {
                properties[3] = new WebSocketProtocolComponent.Property()
                {
                    Type = WebSocketProtocolComponent.PropertyType.DisableMasking,
                    PropertySize = (uint)s_SizeOfBool,
                    PropertyData = IntPtr.Add(internalBufferPtr, offset)
                };
            }

            return properties;
        }