SecureSocketStream(IntPtr tls, SocketInfo info, Manos.IO.Libev.IOLoop ioloop) : base(info, ioloop) { this.tls = tls; SetHandle (new IntPtr (info.fd)); }
public IOStream(Manos.IO.Libev.IOLoop ioloop) { this.ioloop = ioloop; TimeOut = TimeSpan.FromMinutes(1); Expires = DateTime.UtcNow + TimeOut; }
public UdpReceiver( Manos.IO.Libev.IOLoop loop, int maxMessageSize ) { this.loop = loop; readBuffer = new byte[maxMessageSize]; this.maxMessageSize = maxMessageSize; }
public Timers( Manos.IO.IOLoop loop, int initialSize = 2 ) { this.loop = loop; freeList = new Queue<int>( initialSize ); growWatchers( initialSize ); }
public override void OnPreProcessRequest(ManosApp app, Manos.Http.IHttpTransaction transaction, Action complete) { transaction.Response.ContentEncoding = Encoding.UTF8; //transaction.Response.Headers.SetHeader("Content-Type", "text/plain; charset=UTF-8"); //transaction.Response.Headers.SetHeader("Content-Language", "en"); transaction.Response.Headers.ContentEncoding = Encoding.UTF8; complete(); }
static void HandleRequest(Manos.Http.IHttpTransaction tx) { Console.WriteLine("request path " + tx.Request.Path); if (tx.Request.Path == "" || tx.Request.Path == "/") { tx.Request.Path = "/index.html"; HandleRequest(tx); } else if (tx.Request.Path.StartsWith("/a/")) { HandleApi(tx); } else if (tx.Request.Path.StartsWith("/")) { HandleStaticFile(tx); } else { tx.Response.StatusCode = 404; tx.Response.End(); tx.Response.Complete(tx.OnResponseFinished); } }
public SocketStream(Manos.IO.Libev.IOLoop ioloop) : base(ioloop) { }
private static void HandleStaticFile(Manos.Http.IHttpTransaction tx) { string fn = tx.Request.Path; while (fn.StartsWith("/")) fn = fn.Substring(1); string path = __staticdir; foreach (var part in fn.Split('/')) { if (part == "..") { tx.Response.StatusCode = 404; tx.Response.End("Not Found"); tx.Response.Complete(tx.OnResponseFinished); return; } path = Path.Combine(path, part); } ThreadPool.QueueUserWorkItem(_ => { try { var bytes = File.ReadAllBytes(path); Manos.Threading.Boundary.Instance.ExecuteOnTargetLoop(() => { tx.Response.StatusCode = 200; tx.Response.Headers.SetHeader("Content-Type", _GetContentTypeFromExtension(Path.GetExtension(path))); tx.Response.Headers.ContentLength = bytes.Length; tx.Response.Write(bytes); tx.Response.End(); tx.Response.Complete(tx.OnResponseFinished); }); } catch (FileNotFoundException) { Manos.Threading.Boundary.Instance.ExecuteOnTargetLoop(() => { tx.Response.StatusCode = 404; tx.Response.End("Not Found"); tx.Response.Complete(tx.OnResponseFinished); }); } catch (Exception e) { Console.WriteLine("Exception serving static file: " + e); Manos.Threading.Boundary.Instance.ExecuteOnTargetLoop(() => { tx.Response.StatusCode = 500; tx.Response.End("Internal Server Error"); tx.Response.Complete(tx.OnResponseFinished); }); } }); }
private static void HandleApi(Manos.Http.IHttpTransaction tx) { tx.Response.StatusCode = 404; tx.Response.End(); tx.Response.Complete(tx.OnResponseFinished); }
static void _HandleRoot(Manos.Http.IHttpTransaction tx) { Stopwatch sw = new Stopwatch(); sw.Start(); tx.Response.StatusCode = 200; StringBuilder sb = new StringBuilder(); _conn.Insert("brian", new Cassandra.ColumnParent("users"), new Cassandra.Column("name", "Brian Luczkiewicz", DateTime.UtcNow.Ticks)); _conn.Insert("brian", new Cassandra.ColumnParent("users"), new Cassandra.Column("email", "*****@*****.**", DateTime.UtcNow.Ticks)); int count; if (!_conn.TryGet("brian", new Cassandra.ColumnPath("users", "visitcount"), out count)) count = 0; count += 1; _conn.Insert("brian", new Cassandra.ColumnParent("users"), new Cassandra.Column("visitcount", count, DateTime.UtcNow.Ticks)); var name = _conn.Get("brian", new Cassandra.ColumnPath("users", "name")); var email = _conn.Get("brian", new Cassandra.ColumnPath("users", "email")); sb.AppendLine("Name: " + name.Column.Value.ToString()); sb.AppendLine("Email: " + email.Column.Value.ToString()); sb.AppendLine("Visit Count: " + count); tx.Response.End(sb.ToString()); tx.Response.Complete(tx.OnResponseFinished); sw.Stop(); Console.WriteLine("services request in " + sw.ElapsedMilliseconds + "ms"); }
public UdpReceiver( Manos.IO.Libev.IOLoop loop) : this(loop, 128 * 1024) { }
public HttpServer( Manos.Http.HttpConnectionCallback callback ) : base( callback, Manos.IO.IOLoop.Instance.CreateSocketStream(), true ) { }
public HttpStream(HttpEntity entity, Manos.IO.IByteStream stream) { HttpEntity = entity; SocketStream = stream; AddHeaders = true; }