public HttpResponse(IHttpTransaction transaction, IOStream stream) { Transaction = transaction; IOStream = stream; StatusCode = 200; WriteHeaders = true; Headers = new HttpHeaders (); Stream = new HttpResponseStream (this, IOStream); Stream.Chunked = (transaction.Request.MajorVersion > 0 && transaction.Request.MinorVersion > 0); }
public HttpTransaction(HttpServer server, IOStream stream, Socket socket, HttpConnectionCallback callback) { Server = server; IOStream = stream; Socket = socket; ConnectionCallback = callback; stream.OnClose (OnClose); parser_settings = CreateParserSettings (); parser = new HttpParser (); stream.ReadBytes (OnBytesRead); }
public HttpResponse(IHttpTransaction transaction, IOStream stream) { Transaction = transaction; IOStream = stream; StatusCode = 200; WriteHeaders = true; Headers = new HttpHeaders (); Stream = new HttpResponseStream (this, IOStream); Stream.Chunked = (transaction.Request.MajorVersion > 0 && transaction.Request.MinorVersion > 0); end_watcher = new AsyncWatcher (IOLoop.Instance.EventLoop, OnEnd); end_watcher.Start (); }
private void OnBytesRead(IOStream stream, byte [] data, int offset, int count) { ByteBuffer bytes = new ByteBuffer (data, offset, count); parser.Execute (parser_settings, bytes); }
public static HttpTransaction BeginTransaction(HttpServer server, IOStream stream, Socket socket, HttpConnectionCallback cb) { HttpTransaction transaction = new HttpTransaction (server, stream, socket, cb); return transaction; }
private void HandleIOEvents(Loop loop, IOWatcher watcher, EventTypes revents) { 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; } IOStream iostream = new IOStream (s, IOLoop); transactions.Add (HttpTransaction.BeginTransaction (this, iostream, s, callback)); } }
public void HandleWrite(IOStream stream) { SocketStream sstream = (SocketStream) stream; while (file_offset < file_length) { try { Mono.Unix.Native.Syscall.sendfile (sstream.socket.Handle.ToInt32 (), file.Handle.ToInt32 (), ref file_offset, (ulong) (file_length - file_offset)); } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain) return; sstream.Close (); } catch (Exception e) { sstream.Close (); } } if (file_offset >= file_length) IsComplete = true; }
public virtual void FireReadEvent(IOStream stream, byte [] data, int offset, int count) { if (ReadEvent != null) { ReadEvent (stream, data, offset, count); } }
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 void BeginWrite(IOStream stream) { }
public void Write(IOStream stream) { stream.SendFile (file, callback); }
public void HandleWrite(IOStream stream) { }
public void HandleWrite(IOStream stream) { SocketStream sstream = (SocketStream) stream; while (file_offset < file_length) { try { int fdin = -1; try { fdin = Mono.Unix.Native.Syscall.open (filename, Mono.Unix.Native.OpenFlags.O_RDONLY); if (fdin != -1) Mono.Unix.Native.Syscall.sendfile (sstream.socket.Handle.ToInt32 (), fdin, ref file_offset, (ulong) (file_length - file_offset)); } finally { if (fdin != -1) Mono.Unix.Native.Syscall.close (fdin); } } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain) return; sstream.Close (); } catch (Exception e) { sstream.Close (); } } if (file_offset >= file_length) IsComplete = true; }
public void HandleWrite(IOStream stream) { while (bytes_index < file_length) { int len = -1; try { len = stream.socket.Send (bytes, bytes_index, file_length, SocketFlags.None); } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain) return; stream.Close (); } catch (Exception e) { stream.Close (); } finally { if (len != -1) bytes_index += len; } } IsComplete = (bytes_index == file_length); }
private void OnClose(IOStream stream) { }
public void EndWrite(IOStream stream) { if (Callback != null) Callback (); }
public void EndWrite(IOStream stream) { }
public void Write(IOStream stream) { stream.Write (bytes, callback); }
public void HandleWrite(IOStream stream) { while (bytes.Count > 0) { int len = -1; try { len = stream.socket.Send (bytes); } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain) return; stream.Close (); } catch (Exception e) { stream.Close (); } finally { if (len != -1) { int num_segments = bytes.Count; IOStream.AdjustSegments (len, bytes); segments_written = num_segments - bytes.Count; } } } FireCallbacks (); IsComplete = (bytes.Count == 0); }
public void EndWrite(IOStream stream) { if (Callback != null) Callback (); if (file != null) { file.Close (); file = null; } }
private void OnBytesRead(IOStream stream, byte [] data, int offset, int count) { ByteBuffer bytes = new ByteBuffer (data, offset, count); try { parser.Execute (parser_settings, bytes); } catch (Exception e) { Console.WriteLine ("HTTP Parsing Exception:"); Console.WriteLine (e); Console.WriteLine (); Console.WriteLine ("Parsing data:"); Console.WriteLine (Encoding.Default.GetString (data, offset, count)); Console.WriteLine ("Please report this exception at http://groups.google.com/group/manos-de-mono"); } }
private void HandleIOEvents(Loop loop, IOWatcher watcher, EventTypes revents) { while (true) { Socket s = null; try { s = Socket.Accept (); } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain) return; throw se; } catch { throw; } IOStream iostream = new IOStream (s, IOLoop); transactions.Add (HttpTransaction.BeginTransaction (this, iostream, s, callback)); } }
public HttpResponseStream(HttpResponse response, IOStream stream) { Response = response; IOStream = stream; }