private static void RequestBinarySuccess(ulong hostId, ulong responseCode, IntPtr headers, ulong headersSize, IntPtr body, ulong bodySize) { Debug.Assert(_responseForEachHost.ContainsKey(hostId)); var res = new Http3Sharp.ResponseParamaters { ResponseCode = responseCode, }; ReadResponseHeaders(headers, headersSize, ref res); // todo : でかいサイズの場合の非同期読み込み, int 上限越えのサイズ対応 if ((IntPtr.Zero != body) && (0 < bodySize)) { res.Body = new byte[bodySize]; unsafe { using (UnmanagedMemoryStream src = new UnmanagedMemoryStream((byte *)body.ToPointer(), (long)bodySize)) { src.Read(res.Body, 0, (int)bodySize); }; } } _responseForEachHost[hostId].Add(res); }
private static void RequestError(ulong hostId, Http3Sharp.Status status, string errorDetail) { Debug.Assert(_responseForEachHost.ContainsKey(hostId)); var res = new Http3Sharp.ResponseParamaters { Status = status, ErrorMessage = errorDetail, }; // header 欲しいかも _responseForEachHost[hostId].Add(res); }
private static void RequestFileSuccess(ulong hostId, ulong responseCode, IntPtr headers, ulong headersSize, string filePath) { Debug.Assert(_responseForEachHost.ContainsKey(hostId)); var res = new Http3Sharp.ResponseParamaters { SaveFilePath = filePath, ResponseCode = responseCode, }; ReadResponseHeaders(headers, headersSize, ref res); _responseForEachHost[hostId].Add(res); }
private static void ReadResponseHeaders(IntPtr headers, ulong headersSize, ref Http3Sharp.ResponseParamaters res) { int elementSize = Marshal.SizeOf(typeof(IntPtr)); IntPtr ptr; res.Headers = new Http3Sharp.Headers[headersSize / 2]; for (int num = 0; num < (int)headersSize; ++num) { ptr = Marshal.ReadIntPtr(headers, elementSize * num); if (0 == (num % 2)) { res.Headers[num / 2].Name = Marshal.PtrToStringAnsi(ptr); } else { res.Headers[num / 2].Value = Marshal.PtrToStringAnsi(ptr); } } }