예제 #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];
     }
 }
예제 #2
0
파일: Sink.cs 프로젝트: blinds52/More
 public void WriteLine(BytePtr ptr, UInt32 length)
 {
     Write(ptr, length);
     Write(defaultEncoderNewline);
     if (flushAtWriteLine)
     {
         Flush();
     }
 }
예제 #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));
            }
        }
예제 #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));
            }
        }
예제 #5
0
파일: Sink.cs 프로젝트: blinds52/More
 public override void Flush()
 {
     try
     {
         if (sync)
         {
             Monitor.Enter(this);
         }
         FlushHandler(buffer, next.DiffWithSmallerNumber(buffer));
         next = buffer;
     }
     finally
     {
         if (sync)
         {
             Monitor.Exit(this);
         }
     }
 }
예제 #6
0
파일: Sink.cs 프로젝트: blinds52/More
        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);
                }
            }
        }
예제 #7
0
파일: Sink.cs 프로젝트: blinds52/More
        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;
        }
예제 #8
0
 public static extern bool TryWriteFile(
     IntPtr hFile,
     BytePtr lpBuffer,
     UInt32 nNumberOfBytesToWrite,
     out UInt32 lpNumberOfBytesWritten,
     IntPtr lpOverlapped);
예제 #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)
 {
 }
예제 #10
0
파일: Sink.cs 프로젝트: blinds52/More
 public abstract void Write(BytePtr ptr, UInt32 length);
예제 #11
0
파일: Sink.cs 프로젝트: blinds52/More
 public static void DoNothingFlushHandler(BytePtr ptr, UInt32 length)
 {
 }
예제 #12
0
 public BufferSlice(BytePtr ptr, UInt32 length)
 {
     this.ptr    = ptr;
     this.length = length;
 }
예제 #13
0
 public unsafe UInt32 DiffWithSmallerNumber(BytePtr smaller)
 {
     return((UInt32)(this.ptr - smaller.ptr));
 }