Пример #1
0
 public UVLoop()
 {
     _pool = UVBuffer.Default;
     var size = UVInterop.uv_loop_size().ToInt32();
     var loopHandle = Marshal.AllocHGlobal(size); // this needs to be deallocated
     UVException.ThrowIfError(UVInterop.uv_loop_init(loopHandle));
     _handle = loopHandle;
 }
Пример #2
0
        public UVLoop()
        {
            _pool = UVBuffer.Default;
            var size       = UVInterop.uv_loop_size().ToInt32();
            var loopHandle = Marshal.AllocHGlobal(size); // this needs to be deallocated

            UVException.ThrowIfError(UVInterop.uv_loop_init(loopHandle));
            _handle = loopHandle;
        }
Пример #3
0
 void OnReadWindows(UVBuffer.Windows buffer, IntPtr bytesAvaliable)
 {
     // TODO: all branches need to release buffer, I think
     long bytesRead = bytesAvaliable.ToInt64();
     if (bytesRead == 0)
     {
         buffer.Dispose();
         return;
     }
     else if (bytesRead < 0)
     {
         var error = UVException.ErrorCodeToError((int)bytesRead);
         if (error == UVError.EOF)
         {
             OnEndOfStream();
             Dispose();
             buffer.Dispose();
         }
         else if(error == UVError.ECONNRESET)
         {
             Debug.Assert(buffer.Buffer == IntPtr.Zero && buffer.Length == 0);
             // no need to dispose
             // TODO: what should we do here?
         }
         else
         {
             Dispose();
             buffer.Dispose();
             throw new UVException((int)bytesRead);
         }
     }
     else
     {
         var readSlice = new ByteSpan((byte*)buffer.Buffer, (int)bytesRead);
         OnReadCompleted(readSlice);
         buffer.Dispose();
     }
 }
Пример #4
0
 void OnReadUnix(UVBuffer.Unix buffer, IntPtr bytesAvaliable)
 {
     long bytesRead = bytesAvaliable.ToInt64();
     if (bytesRead == 0)
     {
         return;
     }
     else if (bytesRead < 0)
     {
         var error = UVException.ErrorCodeToError((int)bytesRead);
         if (error == UVError.EOF)
         {
             OnEndOfStream();
             Dispose();
         }
         else
         {
             Dispose();
             throw new UVException((int)bytesRead);
         }
     }
     else
     {
         var readSlice = new ByteSpan((byte*)buffer.Buffer, (int)bytesRead);
         OnReadCompleted(readSlice);
         buffer.Dispose();
     }
 }
Пример #5
0
 static void OnReadWindows(IntPtr streamPointer, IntPtr size, ref UVBuffer.Windows buffer)
 {
     var stream = As<UVStream>(streamPointer);
     stream.OnReadWindows(buffer, size);
 }
Пример #6
0
 static void OnReadUnix(IntPtr streamPointer, IntPtr size, ref UVBuffer.Unix buffer)
 {
     var stream = As<UVStream>(streamPointer);
     stream.OnReadUnix(buffer, size);
 }
Пример #7
0
 void OnReadUnix(UVBuffer.Unix buffer, IntPtr bytesAvaliable)
 {
     long bytesRead = bytesAvaliable.ToInt64();
     if (bytesRead == 0)
     {
         return;
     }
     else if (bytesRead < 0)
     {
         var error = UVException.ErrorCodeToError((int)bytesRead);
         if (error == UVError.EOF)
         {
             OnEndOfStream();
             Dispose();
         }
         else
         {
             Dispose();
             throw new UVException((int)bytesRead);
         }
     }
     else
     {
         using (var owned = new OwnedNativeMemory((int)bytesRead, buffer.Buffer)) {
             OnReadCompleted(owned.Memory);
             //buffer.Dispose(); // TODO: owned memory frees the memory. this is bad; need to fix
         }
     }
 }
Пример #8
0
 void OnReadWindows(UVBuffer.Windows buffer, IntPtr bytesAvaliable)
 {
     // TODO: all branches need to release buffer, I think
     long bytesRead = bytesAvaliable.ToInt64();
     if (bytesRead == 0)
     {
         buffer.Dispose();
         return;
     }
     else if (bytesRead < 0)
     {
         var error = UVException.ErrorCodeToError((int)bytesRead);
         if (error == UVError.EOF)
         {
             OnEndOfStream();
             Dispose();
             buffer.Dispose();
         }
         else if (error == UVError.ECONNRESET)
         {
             Debug.Assert(buffer.Buffer == IntPtr.Zero && buffer.Length == 0);
             // no need to dispose
             // TODO: what should we do here?
         }
         else
         {
             Dispose();
             buffer.Dispose();
             throw new UVException((int)bytesRead);
         }
     }
     else
     {
         using (var owned = new OwnedNativeMemory((int)bytesRead, buffer.Buffer)) {
             OnReadCompleted(owned.Memory);
             //buffer.Dispose(); // TODO: owned memory frees the memory. this is bad; need to fix
         }
     }
 }
Пример #9
0
 UVLoop(IntPtr handle, UVBuffer pool)
 {
     _handle = handle;
     _pool   = pool;
 }
Пример #10
0
 void OnReadUnix(UVBuffer.Unix buffer, IntPtr bytesAvaliable)
 {
     long bytesRead = bytesAvaliable.ToInt64();
     if (bytesRead == 0)
     {
         return;
     }
     else if (bytesRead < 0)
     {
         var error = UVException.ErrorCodeToError((int)bytesRead);
         if (error == UVError.EOF)
         {
             OnEndOfStream();
             Dispose();
         }
         else
         {
             Dispose();
             throw new UVException((int)bytesRead);
         }
     }
     else
     {
         // This can be a Span<byte> but the samples pass it directly to TryWrite which
         // needs to unpack the data and turn it back into either an array or native memory
         var readSlice = new UnsafeMemory<byte>((byte*)buffer.Buffer, (int)bytesRead);
         OnReadCompleted(readSlice);
         buffer.Dispose();
     }
 }
Пример #11
0
 UVLoop(IntPtr handle, UVBuffer pool) 
 {
     _handle = handle;
     _pool = pool;
 }
Пример #12
0
 internal unsafe static extern int uv_write_win(IntPtr req, IntPtr handle, UVBuffer.Windows* bufferList, int bufferCount, handle_callback callback);
Пример #13
0
 internal unsafe static extern int uv_write_unix(IntPtr req, IntPtr handle, UVBuffer.Unix* bufferList, int bufferCount, handle_callback callback);
Пример #14
0
 internal unsafe extern static int uv_try_write(IntPtr handle, UVBuffer.Unix* buffersList, int bufferCount);
Пример #15
0
 void OnReadWindows(UVBuffer.Windows buffer, IntPtr bytesAvaliable)
 {
     // TODO: all branches need to release buffer, I think
     long bytesRead = bytesAvaliable.ToInt64();
     if (bytesRead == 0)
     {
         buffer.Dispose();
         return;
     }
     else if (bytesRead < 0)
     {
         var error = UVException.ErrorCodeToError((int)bytesRead);
         if (error == UVError.EOF)
         {
             OnEndOfStream();
             Dispose();
             buffer.Dispose();
         }
         else
         {
             Dispose();
             buffer.Dispose();
             throw new UVException((int)bytesRead);
         }
     }
     else
     {
         var readSlice = new ByteSpan((byte*)buffer.Buffer, (int)bytesRead);
         OnReadCompleted(readSlice);
         buffer.Dispose();
     }
 }