1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 02:51:28 +00:00

remove contextBuffer fix #396

This commit is contained in:
astaxie 2013-12-21 00:34:59 +08:00
parent 2ad399db05
commit 419c3fc772

View File

@ -46,7 +46,6 @@ type ControllerRegistor struct {
filters map[int][]*FilterRouter filters map[int][]*FilterRouter
enableAuto bool enableAuto bool
autoRouter map[string]map[string]reflect.Type //key:controller key:method value:reflect.type autoRouter map[string]map[string]reflect.Type //key:controller key:method value:reflect.type
contextBuffer chan *beecontext.Context //context buffer pool
} }
func NewControllerRegistor() *ControllerRegistor { func NewControllerRegistor() *ControllerRegistor {
@ -54,7 +53,6 @@ func NewControllerRegistor() *ControllerRegistor {
routers: make([]*controllerInfo, 0), routers: make([]*controllerInfo, 0),
autoRouter: make(map[string]map[string]reflect.Type), autoRouter: make(map[string]map[string]reflect.Type),
filters: make(map[int][]*FilterRouter), filters: make(map[int][]*FilterRouter),
contextBuffer: make(chan *beecontext.Context, 1000),
} }
} }
@ -440,14 +438,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
w.Header().Set("Server", BeegoServerName) w.Header().Set("Server", BeegoServerName)
// init context // init context
var context *beecontext.Context context := &beecontext.Context{
select {
case context = <-p.contextBuffer:
context.ResponseWriter = w
context.Request = r
context.Input.Request = r
default:
context = &beecontext.Context{
ResponseWriter: w, ResponseWriter: w,
Request: r, Request: r,
Input: beecontext.NewInput(r), Input: beecontext.NewInput(r),
@ -455,16 +446,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
} }
context.Output.Context = context context.Output.Context = context
context.Output.EnableGzip = EnableGzip context.Output.EnableGzip = EnableGzip
}
defer func() {
if context != nil {
select {
case p.contextBuffer <- context:
default:
}
}
}()
if context.Input.IsWebsocket() { if context.Input.IsWebsocket() {
context.ResponseWriter = rw context.ResponseWriter = rw