ln.http/listener/HttpListener.cs

57 lines
1.4 KiB
C#

// /**
// * File: HttpListener.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.types;
using ln.types.net;
using ln.http.connections;
namespace ln.http.listener
{
public class HttpListener : Listener
{
protected TcpListener tcpListener;
public HttpListener(int port) :this(IPv6.ANY,port){}
public HttpListener(Endpoint endpoint) : this(endpoint.Address, endpoint.Port) {}
public HttpListener(IPv4 listen, int port) : this((IPv6)listen,port){}
public HttpListener(IPv6 listen, int port)
: base(listen, port)
{
}
public override Connection Accept() => new HttpConnection(this,tcpListener.AcceptTcpClient());
public override bool IsOpen => (tcpListener != null);
public override void Open()
{
tcpListener = new TcpListener(Listen, Port);
tcpListener.Start();
}
public override void Close()
{
if (tcpListener != null)
{
tcpListener.Stop();
tcpListener = null;
}
}
public override void Dispose()
{
if (IsOpen)
Close();
}
}
}