﻿// Decompiled with JetBrains decompiler
// Type: System.Net.WebSockets.ServerWebSocket
// Assembly: System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 5ABD58FD-DF31-44FD-A492-63F2B47CC9AF
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.dll

using System;
using System.IO;
using System.Net;
using System.Runtime;
using System.Runtime.InteropServices;

namespace System.Net.WebSockets
{
  internal sealed class ServerWebSocket : WebSocketBase
  {
    private readonly SafeHandle m_SessionHandle;
    private readonly WebSocketProtocolComponent.Property[] m_Properties;

    internal override SafeHandle SessionHandle
    {
      [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get
      {
        return this.m_SessionHandle;
      }
    }

    public ServerWebSocket(Stream innerStream, string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<byte> internalBuffer)
      : base(innerStream, subProtocol, keepAliveInterval, WebSocketBuffer.CreateServerBuffer(internalBuffer, receiveBufferSize))
    {
      this.m_Properties = this.InternalBuffer.CreateProperties(false);
      this.m_SessionHandle = this.CreateWebSocketHandle();
      if (this.m_SessionHandle == null || this.m_SessionHandle.IsInvalid)
        WebSocketHelpers.ThrowPlatformNotSupportedException_WSPC();
      this.StartKeepAliveTimer();
    }

    private SafeHandle CreateWebSocketHandle()
    {
      SafeWebSocketHandle webSocketHandle;
      WebSocketProtocolComponent.WebSocketCreateServerHandle(this.m_Properties, this.m_Properties.Length, out webSocketHandle);
      return (SafeHandle) webSocketHandle;
    }
  }
}
