ln.http/ln.http/listener/Listener.cs

56 lines
1.3 KiB
C#

// /**
// * File: Listener.cs
// * Author: haraldwolff
// *
// * This file and it's content is copyrighted by the Author and / or copyright holder.
// * Any use wihtout proper permission is illegal and may lead to legal actions.
// *
// *
// **/
using System;
using System.Net.Sockets;
using ln.http.connections;
using ln.logging;
using ln.type;
namespace ln.http.listener
{
public abstract class Listener : IDisposable
{
public IPv6 Listen { get; }
public int Port { get; }
public virtual Endpoint LocalEndpoint => new Endpoint(Listen, Port);
public abstract bool IsOpen { get; }
protected Listener(IPv6 listen, int port)
{
Listen = listen;
Port = port;
}
public virtual void AcceptMany(Action<Connection> handler)
{
while (IsOpen)
{
try
{
handler(Accept());
}
catch (SocketException soe)
{
if (IsOpen)
Logging.Log(soe);
}
}
}
public abstract void Open();
public abstract void Close();
public abstract Connection Accept();
public abstract void Dispose();
}
}