Пример #1
0
        /// <summary>
        /// Allocates internal buffer.
        /// </summary>
        /// <exception cref="InvalidOperationException">Operation failed.</exception>
        private void Alloc()
        {
            ErrorCode ret = (ErrorCode)Native.Alloc(_handle);

            if (ret == ErrorCode.None)
            {
                return;
            }

            _handle = IntPtr.Zero;

            switch (ret)
            {
            case ErrorCode.OutOfMemory:
                throw new OutOfMemoryException("Failed to allocate buffer for the packet.");

            default:
                throw new InvalidOperationException("Failed to create a packet.");
            }
        }