private static unsafe int Write( IntPtr stream, IntPtr buffer, UIntPtr len) { SmartSubtransportStream transportStream = GCHandle.FromIntPtr(Marshal.ReadIntPtr(stream, GitSmartSubtransportStream.GCHandleOffset)).Target as SmartSubtransportStream; if (transportStream != null && len.ToUInt64() < (ulong)long.MaxValue) { long length = (long)len.ToUInt64(); using (UnmanagedMemoryStream dataStream = new UnmanagedMemoryStream((byte *)buffer, length)) { try { return(transportStream.Write(dataStream, length)); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Net, ex); } } } return((int)GitErrorCode.Error); }
private static unsafe int Write(IntPtr stream, IntPtr buffer, UIntPtr len) { SmartSubtransportStream transportStream = GCHandle.FromIntPtr(Marshal.ReadIntPtr(stream, GitSmartSubtransportStream.GCHandleOffset)).Target as SmartSubtransportStream; if (transportStream == null) { Proxy.git_error_set_str(GitErrorCategory.Net, "no transport stream provided"); return((int)GitErrorCode.Error); } if (len.ToUInt64() >= (ulong)long.MaxValue) { Proxy.git_error_set_str(GitErrorCategory.Net, "write length is too large"); return((int)GitErrorCode.Error); } try { long length = (long)len.ToUInt64(); using (UnmanagedMemoryStream dataStream = new UnmanagedMemoryStream((byte *)buffer, length)) { return(transportStream.Write(dataStream, length)); } } catch (Exception ex) { return(SetError(transportStream, ex)); } }
private unsafe static int Read( IntPtr stream, IntPtr buffer, UIntPtr buf_size, out UIntPtr bytes_read) { bytes_read = UIntPtr.Zero; SmartSubtransportStream transportStream = GCHandle.FromIntPtr(Marshal.ReadIntPtr(stream, GitSmartSubtransportStream.GCHandleOffset)).Target as SmartSubtransportStream; if (transportStream != null && buf_size.ToUInt64() < (ulong)long.MaxValue) { using (UnmanagedMemoryStream memoryStream = new UnmanagedMemoryStream((byte *)buffer, 0, (long)buf_size.ToUInt64(), FileAccess.ReadWrite)) { try { long longBytesRead; int toReturn = transportStream.Read(memoryStream, (long)buf_size.ToUInt64(), out longBytesRead); bytes_read = new UIntPtr((ulong)Math.Max(0, longBytesRead)); return(toReturn); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Net, ex); } } } return((int)GitErrorCode.Error); }
private static int SetError(SmartSubtransportStream stream, Exception caught) { Exception ret = (stream.StoredError != null) ? stream.StoredError : caught; GitErrorCode errorCode = GitErrorCode.Error; if (ret is NativeException) { errorCode = ((NativeException)ret).ErrorCode; } return((int)errorCode); }
private static void Free(IntPtr stream) { SmartSubtransportStream transportStream = GCHandle.FromIntPtr(Marshal.ReadIntPtr(stream, GitSmartSubtransportStream.GCHandleOffset)).Target as SmartSubtransportStream; if (transportStream != null) { try { transportStream.Free(); } catch (Exception ex) { Proxy.git_error_set_str(GitErrorCategory.Net, ex); } } }