Ignore:
Timestamp:
Aug 1, 2022, 12:26:44 PM (2 years ago)
Author:
alloc
Message:

Made SpaceWizards.HttpListener compilable against .NET 4.8 with preprocessor define UNITY_NETFRAMEWORK

Location:
binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/ChunkStream.cs

    r376 r377  
    3131// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3232//
     33
     34// ReSharper disable RedundantUsingDirective
     35// ReSharper disable ConditionIsAlwaysTrueOrFalse
    3336
    3437using System;
     
    368371                if (st > 0)
    369372                {
     373#if UNITY_NETFRAMEWORK
     374                    _saved.Append(stString.Substring(0, _saved.Length == 0 ? st - 2 : st));
     375#else
    370376                    _saved.Append(stString.AsSpan(0, _saved.Length == 0 ? st - 2 : st));
     377#endif
    371378                    st = 0;
    372379                    if (_saved.Length > 4196)
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/ChunkedInputStream.cs

    r376 r377  
    2828// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    2929// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     30
     31// ReSharper disable RedundantUsingDirective
    3032
    3133using System;
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpConnection.cs

    r376 r377  
    3030// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3131//
     32
     33// ReSharper disable RedundantUsingDirective
     34// ReSharper disable PrivateFieldCanBeConvertedToLocalVariable
     35// ReSharper disable RedundantExplicitArrayCreation
     36// ReSharper disable EmptyGeneralCatchClause
     37// ReSharper disable ConditionIsAlwaysTrueOrFalse
     38// ReSharper disable RedundantJumpStatement
     39#pragma warning disable CS8618
    3240
    3341using System;
     
    132140        }
    133141
     142#if !UNITY_NETFRAMEWORK
    134143        [MemberNotNull(nameof(_memoryStream))]
    135144        [MemberNotNull(nameof(_context))]
     145#endif
    136146        private void Init()
    137147        {
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpEndPointListener.cs

    r376 r377  
    3030// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3131//
     32
     33// ReSharper disable ConditionIsAlwaysTrueOrFalse
     34// ReSharper disable UnusedParameter.Local
    3235
    3336using System;
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpEndPointManager.cs

    r376 r377  
    3030//
    3131
     32// ReSharper disable RedundantAssignment
     33#pragma warning disable CS8602
     34
    3235using System;
    3336using System.Collections;
     
    110113            else
    111114            {
     115#if UNITY_NETFRAMEWORK
     116                if (host.Length > 1 && host[0] == '[' && host[host.Length - 1] == ']')
     117                    host = host.Substring (1, host.Length - 2);
     118#else
    112119                if (host.StartsWith('[') && host.EndsWith(']'))
    113120                    host = host[1..^1];
     121#endif
    114122
    115123                const int NotSupportedErrorCode = 50;
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpListener.Certificates.cs

    r376 r377  
    11// Licensed to the .NET Foundation under one or more agreements.
    22// The .NET Foundation licenses this file to you under the MIT license.
     3
     4// ReSharper disable RedundantUsingDirective
    35
    46using System.Collections;
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpListener.Managed.cs

    r376 r377  
    11// Licensed to the .NET Foundation under one or more agreements.
    22// The .NET Foundation licenses this file to you under the MIT license.
     3
     4// ReSharper disable RedundantUsingDirective
     5// ReSharper disable RedundantCast
     6// ReSharper disable RedundantUnsafeContext
    37
    48using System;
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpListenerContext.Managed.cs

    r376 r377  
    11// Licensed to the .NET Foundation under one or more agreements.
    22// The .NET Foundation licenses this file to you under the MIT license.
     3
     4// ReSharper disable RedundantUsingDirective
     5// ReSharper disable RedundantUnsafeContext
     6// ReSharper disable UnusedVariable
     7#pragma warning disable CS8604
    38
    49using System;
     
    6166            string.Compare(header, 0, AuthenticationTypes.Basic, 0, 5, StringComparison.OrdinalIgnoreCase) == 0;
    6267
     68#if UNITY_NETFRAMEWORK
     69        internal static bool TryParseBasicAuth(string headerValue, out HttpStatusCode errorCode, out string? username, out string? password)
     70#else
    6371        internal static bool TryParseBasicAuth(string headerValue, out HttpStatusCode errorCode, [NotNullWhen(true)] out string? username, [NotNullWhen(true)] out string? password)
     72#endif
    6473        {
    6574            errorCode = HttpStatusCode.OK;
     
    92101        }
    93102
     103#if !UNITY_NETFRAMEWORK
    94104        public Task<WebSockets.HttpListenerWebSocketContext> AcceptWebSocketAsync(string? subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval)
    95105        {
     
    104114            return HttpWebSocket.AcceptWebSocketAsyncCore(this, subProtocol, receiveBufferSize, keepAliveInterval, internalBuffer);
    105115        }
     116#endif
    106117    }
    107118}
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpListenerRequest.Managed.cs

    r376 r377  
    3131// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3232//
     33
     34// ReSharper disable RedundantUsingDirective
     35// ReSharper disable RedundantCast
     36// ReSharper disable RedundantJumpStatement
     37// ReSharper disable ConditionIsAlwaysTrueOrFalse
    3338
    3439using System;
     
    257262            }
    258263
     264#if UNITY_NETFRAMEWORK
     265            string name = header.Substring(0, colon).Trim();
     266            string val = header.Substring(colon + 1).Trim();
     267#else
    259268            string name = header.AsSpan(0, colon).Trim().ToString();
    260269            string val = header.AsSpan(colon + 1).Trim().ToString();
     270#endif
    261271            if (name.Equals("content-length", StringComparison.OrdinalIgnoreCase))
    262272            {
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpListenerResponse.Managed.cs

    r376 r377  
    2929// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3030//
     31
     32// ReSharper disable RedundantExtendsListEntry
    3133
    3234using System;
     
    288290            writer.Write(FormatHeaders(_webHeaders));
    289291            writer.Flush();
     292#if UNITY_NETFRAMEWORK
     293            int preamble = encoding.GetPreamble().Length;
     294#else
    290295            int preamble = encoding.Preamble.Length;
     296#endif
    291297            EnsureResponseStream();
    292298
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpListenerTimeoutManager.Managed.cs

    r376 r377  
    11// Licensed to the .NET Foundation under one or more agreements.
    22// The .NET Foundation licenses this file to you under the MIT license.
     3
     4// ReSharper disable RedundantUsingDirective
     5// ReSharper disable UnusedParameter.Local
    36
    47using System;
     
    3841        }
    3942
     43#if !UNITY_NETFRAMEWORK
    4044        public TimeSpan EntityBody
    4145        {
     
    8488            }
    8589        }
     90#endif
    8691
    8792        private void ValidateTimeout(TimeSpan value)
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpRequestStream.Managed.cs

    r376 r377  
    2929// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3030//
     31
     32// ReSharper disable RedundantUsingDirective
     33// ReSharper disable RedundantExtendsListEntry
     34// ReSharper disable RedundantCast
    3135
    3236using System;
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/HttpResponseStream.Managed.cs

    r376 r377  
    2929// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3030//
     31
     32// ReSharper disable RedundantUsingDirective
     33// ReSharper disable RedundantExtendsListEntry
     34// ReSharper disable EmptyGeneralCatchClause
     35#pragma warning disable CS8600
    3136
    3237using System;
     
    152157            else
    153158            {
    154                 try
    155                 {
     159#if !UNITY_NETFRAMEWORK
     160                try
     161                {
     162#endif
    156163                    _stream.Write(buffer, offset, count);
     164#if !UNITY_NETFRAMEWORK
    157165                }
    158166                catch (IOException ex)
     
    160168                    throw new HttpListenerException(ex.HResult, ex.Message);
    161169                }
     170#endif
    162171            }
    163172        }
     
    168177        private async Task InternalWriteIgnoreErrorsAsync(byte[] buffer, int offset, int count)
    169178        {
     179#if UNITY_NETFRAMEWORK
     180            try { await _stream.WriteAsync(buffer, offset, count).ConfigureAwait(false); }
     181#else
    170182            try { await _stream.WriteAsync(buffer.AsMemory(offset, count)).ConfigureAwait(false); }
     183#endif
    171184            catch { }
    172185        }
     
    282295                return;
    283296
     297#if UNITY_NETFRAMEWORK
     298            HttpStreamAsyncResult result = asyncResult as HttpStreamAsyncResult;
     299            if (result != null && result._buffer != null && result._count == 0)
     300#else
    284301            if (asyncResult is HttpStreamAsyncResult { _buffer: not null, _count: 0 })
     302#endif
    285303                return;
    286304
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/ListenerAsyncResult.Managed.cs

    r376 r377  
    3131// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3232//
     33
     34// ReSharper disable RedundantDelegateCreation
     35// ReSharper disable RedundantSuppressNullableWarningExpression
     36// ReSharper disable EmptyGeneralCatchClause
    3337
    3438using System;
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/ListenerPrefix.cs

    r376 r377  
    3030// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    3131//
     32
     33// ReSharper disable RedundantUsingDirective
     34// ReSharper disable NonReadonlyMemberInGetHashCode
    3235
    3336using System;
     
    8487
    8588        // Equals and GetHashCode are required to detect duplicates in HttpListenerPrefixCollection.
     89#if UNITY_NETFRAMEWORK
     90        public override bool Equals(object? o)
     91#else
    8692        public override bool Equals([NotNullWhen(true)] object? o)
     93#endif
    8794        {
    8895            ListenerPrefix? other = o as ListenerPrefix;
     
    118125                _host = uri.Substring(start_host, end_host - start_host);
    119126                root = uri.IndexOf('/', end_host, length - end_host);
     127#if UNITY_NETFRAMEWORK
     128                string portPart = uri.Substring (end_host + 1, root - end_host - 1);
     129                _port = (ushort)int.Parse (portPart);
     130#else
    120131                _port = (ushort)int.Parse(uri.AsSpan(end_host + 1, root - end_host - 1));
     132#endif
    121133                _path = uri.Substring(root);
    122134            }
  • binary-improvements2/SpaceWizards.HttpListener/src/System/Net/Managed/WebSockets/HttpWebSocket.Managed.cs

    r376 r377  
    11// Licensed to the .NET Foundation under one or more agreements.
    22// The .NET Foundation licenses this file to you under the MIT license.
     3
     4// ReSharper disable RedundantUsingDirective
    35
    46using System;
     
    1315        private const string SupportedVersion = "13";
    1416
     17#if !UNITY_NETFRAMEWORK
    1518        internal static async Task<HttpListenerWebSocketContext> AcceptWebSocketAsyncCore(HttpListenerContext context,
    1619            string? subProtocol,
     
    7982            return webSocketContext;
    8083        }
    81 
     84#endif
     85       
    8286        private const bool WebSocketsSupported = true;
    8387    }
Note: See TracChangeset for help on using the changeset viewer.