// Decompiled with JetBrains decompiler // Type: Rei.Net.HttpServer.MyHttpListener // Assembly: Rei.Net.HttpServer, Version=1.13.2.9297, Culture=neutral, PublicKeyToken=null // MVID: 6174F8E9-E7BA-46AD-8F2E-196645884F28 // Assembly location: F:\Eigene Dateien\Dropbox\portable Collection\Progs\CarotDAV\Rei.Net.HttpServer.dll using Microsoft.VisualBasic.CompilerServices; using System; using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Runtime.CompilerServices; using System.Threading; namespace Rei.Net.HttpServer { [DebuggerDisplay("{toString}")] public class MyHttpListener : IDisposable { private TcpListener m_listener; private IPEndPoint m_endpoint; private object m_syncobject; private string m_servername; private bool disposedValue; public MyHttpListener() { this.disposedValue = false; this.m_servername = nameof (ServerName); this.m_syncobject = RuntimeHelpers.GetObjectValue(new object()); this.m_endpoint = new IPEndPoint(IPAddress.Loopback, 0); } public void Start() { object syncobject = this.m_syncobject; ObjectFlowControl.CheckForSyncLockOnValueType(syncobject); Monitor.Enter(syncobject); try { if (this.m_listener != null) throw new ApplicationException(); this.m_listener = new TcpListener(this.m_endpoint); this.m_listener.Start(100); } finally { Monitor.Exit(syncobject); } } public void Stop() { object syncobject = this.m_syncobject; ObjectFlowControl.CheckForSyncLockOnValueType(syncobject); Monitor.Enter(syncobject); try { if (this.m_listener != null) this.m_listener.Stop(); this.m_listener = (TcpListener) null; } finally { Monitor.Exit(syncobject); } } public void Close() { ((IDisposable)this).Dispose(); } protected virtual void Dispose(bool disposing) { if (!this.disposedValue && disposing) { object syncobject = this.m_syncobject; ObjectFlowControl.CheckForSyncLockOnValueType(syncobject); Monitor.Enter(syncobject); try { if (this.m_listener != null) this.m_listener.Stop(); this.m_listener = (TcpListener) null; } finally { Monitor.Exit(syncobject); } } this.disposedValue = true; } void IDisposable.Dispose() { this.Dispose(true); GC.SuppressFinalize((object) this); } public IPEndPoint EndPoint { get { return this.m_endpoint; } set { if (value == null) throw new ArgumentNullException(); this.m_endpoint = value; } } public bool IsListening { get { object syncobject = this.m_syncobject; ObjectFlowControl.CheckForSyncLockOnValueType(syncobject); Monitor.Enter(syncobject); try { return this.m_listener != null; } finally { Monitor.Exit(syncobject); } } } public bool IsPending { get { object syncobject = this.m_syncobject; ObjectFlowControl.CheckForSyncLockOnValueType(syncobject); Monitor.Enter(syncobject); try { return this.m_listener != null && this.m_listener.Pending(); } finally { Monitor.Exit(syncobject); } } } public string ServerName { get { return this.m_servername; } set { if (value == null) throw new ArgumentNullException(); this.m_servername = value; } } public MyHttpServerConnection GetConnection() { return this.EndGetConnection(this.BeginGetConnection((AsyncCallback) null, (object) null)); } public IAsyncResult BeginGetConnection(AsyncCallback callback, object asyncstate) { MyAsyncResult myAsyncResult = new MyAsyncResult(callback, RuntimeHelpers.GetObjectValue(asyncstate)); object syncobject = this.m_syncobject; ObjectFlowControl.CheckForSyncLockOnValueType(syncobject); Monitor.Enter(syncobject); try { if (this.m_listener == null) throw new InvalidOperationException(); myAsyncResult.Tag = (object) this.m_listener; this.m_listener.BeginAcceptSocket(new AsyncCallback(this.OnGetConnection), (object) myAsyncResult); } finally { Monitor.Exit(syncobject); } return (IAsyncResult) myAsyncResult; } private void OnGetConnection(IAsyncResult asyncresult) { MyAsyncResult asyncState = (MyAsyncResult) asyncresult.AsyncState; if (!asyncresult.CompletedSynchronously) asyncState.SetAsync(); TcpListener tag = (TcpListener) asyncState.Tag; try { Socket basesocket = tag.EndAcceptSocket(asyncresult); basesocket.SendTimeout = 1000; basesocket.ReceiveTimeout = 1000; MyHttpServerConnection serverConnection = new MyHttpServerConnection(basesocket); asyncState.ReturnValue = (object) serverConnection; } catch (Exception ex1) { ProjectData.SetProjectError(ex1); Exception ex2 = ex1; asyncState.Complete(ex2); ProjectData.ClearProjectError(); return; } asyncState.Complete(); } public MyHttpServerConnection EndGetConnection(IAsyncResult ar) { MyAsyncResult myAsyncResult = (MyAsyncResult) ar; myAsyncResult.AsyncEnd(); return (MyHttpServerConnection) myAsyncResult.ReturnValue; } public override string ToString() { return this.m_servername + " endpoint:" + this.m_endpoint.ToString(); } } }