44 lines
1.0 KiB
C#
44 lines
1.0 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 ln.http.connections;
|
|||
|
using ln.type;
|
|||
|
namespace ln.http.listener
|
|||
|
{
|
|||
|
public abstract class Listener : IDisposable
|
|||
|
{
|
|||
|
public IPv6 Listen { get; }
|
|||
|
public int Port { get; }
|
|||
|
|
|||
|
public 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)
|
|||
|
handler(Accept());
|
|||
|
}
|
|||
|
|
|||
|
public abstract void Open();
|
|||
|
public abstract void Close();
|
|||
|
|
|||
|
public abstract Connection Accept();
|
|||
|
|
|||
|
public abstract void Dispose();
|
|||
|
}
|
|||
|
}
|