From 4eee3e5f53c45d20604c7ab73bb7e9cccb0dc0bd Mon Sep 17 00:00:00 2001 From: Gerasimos Maropoulos Date: Sun, 18 Sep 2016 07:21:35 +0300 Subject: [PATCH] Export the funcs: AcquireCtx and ReleaseCtx, see previous commit for more --- iris.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/iris.go b/iris.go index 48f9a14c..b7f7bcef 100644 --- a/iris.go +++ b/iris.go @@ -145,6 +145,8 @@ type ( ListenTLS(string, string, string) ListenUNIX(string, os.FileMode) ListenVirtual(...string) *Server + AcquireCtx(*fasthttp.RequestCtx) *Context + ReleaseCtx(*Context) Go() error Close() error UseSessionDB(sessions.Database) @@ -301,16 +303,24 @@ func (s *Framework) initialize() { } -// Go starts the iris station, listens to all registered servers, and prepare only if Virtual -func Go() error { - return Default.Go() +// AcquireCtx gets an Iris' Context from pool +// see iris.Handler & ReleaseCtx, Go() +func AcquireCtx(reqCtx *fasthttp.RequestCtx) { + Default.AcquireCtx(reqCtx) +} + +// ReleaseCtx puts the Iris' Context back to the pool in order to be re-used +// see iris.Handler & AcquireCtx, Go() +func ReleaseCtx(ctx *Context) { + Default.ReleaseCtx(ctx) } // AcquireCtx gets an Iris' Context from pool // see iris.Handler & ReleaseCtx, Go() -func (s *Framework) AcquireCtx(reqCtx *fasthttp.RequestCtx) { +func (s *Framework) AcquireCtx(reqCtx *fasthttp.RequestCtx) *Context { ctx := s.contextPool.Get().(*Context) // Changed to use the pool's New 09/07/2016, ~ -4k nanoseconds(9 bench tests) per requests (better performance) ctx.RequestCtx = reqCtx + return ctx } // ReleaseCtx puts the Iris' Context back to the pool in order to be re-used @@ -322,6 +332,11 @@ func (s *Framework) ReleaseCtx(ctx *Context) { s.contextPool.Put(ctx) } +// Go starts the iris station, listens to all registered servers, and prepare only if Virtual +func Go() error { + return Default.Go() +} + // Go starts the iris station, listens to all registered servers, and prepare only if Virtual func (s *Framework) Go() error { s.initialize()