Example #1
0
        protected virtual uint[] ValueToArray()
        {
            int   count = 0;
            void *cch   = null;

            try
            {
                cch = nsjs_localvalue_get_uint32array(this.Handle, ref count);
                uint[] buffer = new uint[count];
                if (count > 0)
                {
                    fixed(uint *data = buffer)
                    {
                        BufferExtension.memcpy(cch, data, sizeof(uint) * count);
                    }
                }
                return(buffer);
            }
            finally
            {
                if (cch != null)
                {
                    NSJSMemoryManagement.Free(cch);
                }
            }
        }
Example #2
0
        protected virtual sbyte[] ValueToArray()
        {
            void *cch   = null;
            int   count = 0;

            try
            {
                cch = nsjs_localvalue_get_int8array(this.Handle, ref count);
                sbyte[] buffer = new sbyte[count];
                if (count > 0)
                {
                    fixed(sbyte *data = buffer)
                    {
                        BufferExtension.memcpy(cch, data, (sizeof(sbyte) * count));
                    }
                }
                return(buffer);
            }
            finally
            {
                if (cch != null)
                {
                    NSJSMemoryManagement.Free(cch);
                }
            }
        }
Example #3
0
        private unsafe void WriteBufferToClient(byte *buffer, long count, Action <Exception> callback)
        {
            Exception exception = null;

            if (buffer == null)
            {
                exception = new ArgumentNullException("buffer");
            }
            else if (count <= 0)
            {
                exception = new ArgumentOutOfRangeException("count");
            }
            if (exception != null)
            {
                if (callback != null)
                {
                    callback(exception);
                }
                return;
            }
            Stream output = response.OutputStream;

            byte[] chunk  = new byte[1400];
            long   offset = 0;

            lock (output)
            {
                while (offset < count && exception == null)
                {
                    long rdsz = unchecked (count - offset);
                    if (rdsz > chunk.Length)
                    {
                        rdsz = chunk.Length;
                    }
                    int len = unchecked ((int)rdsz);
                    BufferExtension.memcpy(&buffer[offset], chunk, 0, len);
                    try
                    {
                        output.Write(chunk, 0, len);
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                    offset = unchecked (offset + rdsz);
                }
            }
            if (callback != null)
            {
                callback(exception);
            }
        }