public HttpRequest(IHttpTransaction transaction, SocketStream stream) { Transaction = transaction; Socket = stream; RemoteAddress = stream.Address; RemotePort = stream.Port; }
public HttpResponse(IHttpRequest request, SocketStream stream) { Request = request; Socket = stream; StatusCode = 200; WriteHeaders = true; Stream = new HttpStream (this, stream); Stream.Chunked = (request.MajorVersion > 0 && request.MinorVersion > 0); }
public HttpResponse(IHttpTransaction transaction, SocketStream stream) { Transaction = transaction; Socket = stream; StatusCode = 200; WriteHeaders = true; Stream = new HttpStream (this, stream); Stream.Chunked = (transaction.Request.MajorVersion > 0 && transaction.Request.MinorVersion > 0); }
public HttpTransaction(HttpServer server, SocketStream stream, HttpConnectionCallback callback) { Server = server; Stream = stream; ConnectionCallback = callback; gc_handle = GCHandle.Alloc (this); Stream.Closed += delegate (object sender, EventArgs args) { Close (); }; Request = new HttpRequest (this, stream); Request.Read (); }
public void SetLength(long l) { Length = l; if (waiting_stream != null) waiting_stream.EnableWriting (); waiting_stream = null; }
public void HandleWrite(IOStream stream) { SocketStream sstream = (SocketStream) stream; if (!Chunked && Length == -1) { waiting_stream = sstream; sstream.DisableWriting (); return; } sstream.SendFile (filename, Chunked, Length, (length, error) => { IsComplete = true; sstream.EnableWriting (); OnComplete (length, error); }); sstream.DisableWriting (); }
public ConnectionAcceptedEventArgs(SocketStream stream) { Stream = stream; }
public void Listen(string host, int port) { SocketStream socket = new SocketStream (ioloop); socket.Listen (host, port); socket.ConnectionAccepted += ConnectionAccepted; }
public void Listen(IPEndPoint endpoint) { SocketStream socket = new SocketStream (ioloop); socket.Listen (endpoint); socket.ConnectionAccepted += ConnectionAccepted; }
public void Close() { if (gc_handle.IsAllocated) gc_handle.Free (); if (Request != null) Request.Dispose (); if (Response != null) Response.Dispose (); Stream = null; Request = null; Response = null; }
private void AcceptConnections() { while (true) { Socket s = null; try { s = socket.Accept (); } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain) return; Console.WriteLine ("Socket exception in Accept handler"); Console.WriteLine (se); return; } catch (Exception e) { Console.WriteLine ("Exception in Accept handler"); Console.WriteLine (e); return; } SocketStream iostream = new SocketStream (s, IOLoop); OnConnectionAccepted (iostream); } }
public static HttpTransaction BeginTransaction(HttpServer server, SocketStream stream, HttpConnectionCallback cb, bool closeOnEnd = false) { HttpTransaction transaction = new HttpTransaction (server, stream, cb, closeOnEnd); return transaction; }
public HttpResponse(SocketStream stream) { Socket = stream; Stream = new HttpStream (this, stream); }
public HttpStream(HttpEntity entity, SocketStream stream) { HttpEntity = entity; SocketStream = stream; }
public HttpStream(HttpEntity entity, SocketStream stream) { HttpEntity = entity; SocketStream = stream; AddHeaders = true; }
public void Execute() { Socket = new SocketStream (AppHost.IOLoop); Socket.Connect (RemoteAddress, RemotePort); Socket.Connected += delegate { Stream = new HttpStream (this, Socket); Stream.WriteMetadata (() => { HttpResponse response = new HttpResponse (Socket); if (Connected != null) Connected (response); }); }; }
private void AcceptConnections() { int error; int amount = manos_socket_accept_many (fd, accept_infos, MAX_ACCEPT, out error); if (amount < 0) throw new Exception (String.Format ("Exception while accepting. errno: {0}", error)); // Console.WriteLine ("Accepted: '{0}' connections.", amount); for (int i = 0; i < amount; i++) { // Console.WriteLine ("Accepted: '{0}'", accept_infos [i]); SocketStream iostream = new SocketStream (accept_infos [i], IOLoop); OnConnectionAccepted (iostream); } }
public static HttpTransaction BeginTransaction(HttpServer server, SocketStream stream, HttpConnectionCallback cb) { HttpTransaction transaction = new HttpTransaction (server, stream, cb); return transaction; }
private void OnConnectionAccepted(SocketStream stream) { if (ConnectionAccepted != null) ConnectionAccepted (this, new ConnectionAcceptedEventArgs (stream)); }
public void Dispose() { if (socket != null) { socket.Dispose (); socket = null; } }
public void Execute() { Socket = new SocketStream (AppHost.IOLoop); Socket.Connect (RemoteAddress, RemotePort); Socket.Connected += delegate { Stream = new HttpStream (this, Socket); Stream.Chunked = false; Stream.AddHeaders = false; byte [] body = GetBody (); if (body != null) { Headers.ContentLength = body.Length; Stream.Write (body, 0, body.Length); } Stream.End (() => { HttpResponse response = new HttpResponse (this, Socket); response.OnCompleted += () => { if (OnResponse != null) OnResponse (response); }; response.Read (); }); }; }