Exemple #1
0
 // TODO: use native memcpy
 public unsafe void CopyTo(BytePtr dest, UInt32 length)
 {
     for (uint i = 0; i < length; i++)
     {
         dest.ptr[i] = this.ptr[i];
     }
 }
Exemple #2
0
 public void WriteLine(BytePtr ptr, UInt32 length)
 {
     Write(ptr, length);
     Write(defaultEncoderNewline);
     if (flushAtWriteLine)
     {
         Flush();
     }
 }
Exemple #3
0
        public static void Write(BytePtr buffer, UInt32 length)
        {
            UInt32 written = 0;

            if (!NativeWindows.TryWriteFile(StdOutFileHandle, buffer, length, out written, IntPtr.Zero))
            {
                throw new InvalidOperationException(String.Format("WriteFile failed (lastError={0})", NativeWindows.GetLastError()));
            }
            if (written != length)
            {
                throw new InvalidOperationException(String.Format("Attempted to write {0} bytes but only wrote {1}", length, written));
            }
        }
Exemple #4
0
        public static unsafe void WriteFile(IntPtr file, BytePtr buffer, UInt32 length)
        {
            UInt32 written = 0;

            if (!TryWriteFile(file, buffer, length, out written, IntPtr.Zero))
            {
                throw new InvalidOperationException(String.Format("WriteFile failed (lastError={0})", GetLastError()));
            }
            if (written != length)
            {
                throw new InvalidOperationException(String.Format("Attempted to write {0} bytes but only wrote {1}", length, written));
            }
        }
Exemple #5
0
 public override void Flush()
 {
     try
     {
         if (sync)
         {
             Monitor.Enter(this);
         }
         FlushHandler(buffer, next.DiffWithSmallerNumber(buffer));
         next = buffer;
     }
     finally
     {
         if (sync)
         {
             Monitor.Exit(this);
         }
     }
 }
Exemple #6
0
        public override void Write(BytePtr ptr, UInt32 length)
        {
            try
            {
                if (sync)
                {
                    Monitor.Enter(this);
                }

                FlushHandler(buffer, next.DiffWithSmallerNumber(buffer));
                next = buffer;
                FlushHandler(ptr, length);
            }
            finally
            {
                if (sync)
                {
                    Monitor.Exit(this);
                }
            }
        }
Exemple #7
0
        protected BytePtr next; // Assumption: buffer <= next <= bufferLimit
        public BufferedSink(BytePtr buffer, BytePtr bufferLimit, Boolean flushAtWriteLine,
                            Encoder defaultEncoder, FlushHandler flushHandler, Boolean sync)
            : base(flushAtWriteLine, defaultEncoder)
        {
            if (buffer >= bufferLimit)
            {
                throw new ArgumentException(String.Format("buffer {0} must be < bufferLimit {1}", buffer, bufferLimit));
            }
            if (bufferLimit.DiffWithSmallerNumber(buffer) < MinimumBufferSize)
            {
                throw new ArgumentException(String.Format("buffer length {0} is too small (minimum is {1})",
                                                          bufferLimit.DiffWithSmallerNumber(buffer), MinimumBufferSize));
            }
            if (flushHandler == null)
            {
                throw new ArgumentNullException("flushHandler");
            }

            this.buffer       = buffer;
            this.bufferLimit  = bufferLimit;
            this.sync         = sync;
            this.FlushHandler = flushHandler;
            this.next         = buffer;
        }
Exemple #8
0
 public static extern bool TryWriteFile(
     IntPtr hFile,
     BytePtr lpBuffer,
     UInt32 nNumberOfBytesToWrite,
     out UInt32 lpNumberOfBytesWritten,
     IntPtr lpOverlapped);
Exemple #9
0
 private BufferedWindowsConsoleSink(BytePtr buffer, BytePtr bufferLimit, Boolean flushAtWriteLine)
     : base(buffer, bufferLimit, flushAtWriteLine, Encoder.Utf8,
            (NativeWindowsConsole.StdOutFileHandle == IntPtr.Zero) ? new FlushHandler(TypedSink.DoNothingFlushHandler) :
            new FlushHandler(NativeWindowsConsole.Write), true)
 {
 }
Exemple #10
0
 public abstract void Write(BytePtr ptr, UInt32 length);
Exemple #11
0
 public static void DoNothingFlushHandler(BytePtr ptr, UInt32 length)
 {
 }
Exemple #12
0
 public BufferSlice(BytePtr ptr, UInt32 length)
 {
     this.ptr    = ptr;
     this.length = length;
 }
Exemple #13
0
 public unsafe UInt32 DiffWithSmallerNumber(BytePtr smaller)
 {
     return((UInt32)(this.ptr - smaller.ptr));
 }