Skip to content

Instantly share code, notes, and snippets.

@bvanderveen
Created May 1, 2011 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bvanderveen/950570 to your computer and use it in GitHub Desktop.
Save bvanderveen/950570 to your computer and use it in GitHub Desktop.
Interface-based API for New Kayak
using System;
using System.Collections.Generic;
namespace Kayak.Http
{
public struct HttpRequestHead
{
public string Method;
public string Uri;
public Version Version;
public IDictionary<string, string> Headers;
}
public struct HttpResponseHead
{
public string Status;
public IDictionary<string, string> Headers;
}
public interface IHttpServerFactory
{
IServer Create(IHttpServerDelegate del, IScheduler scheduler);
}
public interface IHttpClientFactory
{
IHttpRequest Create(IHttpResponseDelegate del);
}
public interface IHttpServerDelegate
{
IHttpRequestDelegate OnRequest(IServer server, IHttpResponse response);
void OnClose(IServer server);
}
public interface IHttpRequest
{
void WriteHeaders(HttpRequestHead head);
bool WriteBody(ArraySegment<byte> data, Action continuation);
void End();
}
public interface IHttpResponseDelegate
{
void OnContinue();
void OnHeaders(HttpResponseHead head);
bool OnBody(ArraySegment<byte> data, Action continuation);
void OnEnd();
}
public interface IHttpRequestDelegate
{
void OnHeaders(HttpRequestHead head);
bool OnBody(ArraySegment<byte> data, Action continuation);
void OnEnd();
}
public interface IHttpResponse
{
void WriteContinue();
void WriteHeaders(HttpResponseHead head);
bool WriteBody(ArraySegment<byte> data, Action continuation);
void End();
}
}
using System;
using System.Net;
namespace Kayak
{
public interface ISchedulerFactory
{
IScheduler Create(ISchedulerDelegate del);
}
public interface IScheduler : IDisposable
{
IDisposable Start();
void Post(Action action);
}
public interface ISchedulerDelegate
{
void OnStarted(IScheduler scheduler);
void OnStopped(IScheduler scheduler);
void OnException(IScheduler scheduler, Exception e);
}
public interface IServerFactory
{
IServer Create(IServerDelegate del, IScheduler scheduler);
}
public interface IServer : IDisposable
{
IDisposable Listen(IPEndPoint ep);
}
public interface IServerDelegate
{
ISocketDelegate OnConnection(IServer server, ISocket socket);
void OnClose(IServer server);
}
public interface ISocketFactory
{
ISocket Create(ISocketDelegate del, IScheduler scheduler);
}
public interface ISocketDelegate
{
void OnConnected(ISocket socket);
bool OnData(ISocket socket, ArraySegment<byte> data, Action continuation);
void OnEnd(ISocket socket);
void OnError(ISocket socket, Exception e);
void OnClose(ISocket socket);
}
public interface ISocket : IDisposable
{
IPEndPoint RemoteEndPoint { get; }
void Connect(IPEndPoint ep);
bool Write(ArraySegment<byte> data, Action continuation);
void End();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment