remove contextBuffer fix #396
Showing
1 changed file
with
17 additions
and
36 deletions
| ... | @@ -40,21 +40,19 @@ type controllerInfo struct { | ... | @@ -40,21 +40,19 @@ type controllerInfo struct { |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | type ControllerRegistor struct { | 42 | type ControllerRegistor struct { |
| 43 | routers []*controllerInfo // regexp router storage | 43 | routers []*controllerInfo // regexp router storage |
| 44 | fixrouters []*controllerInfo // fixed router storage | 44 | fixrouters []*controllerInfo // fixed router storage |
| 45 | enableFilter bool | 45 | enableFilter bool |
| 46 | filters map[int][]*FilterRouter | 46 | filters map[int][]*FilterRouter |
| 47 | enableAuto bool | 47 | enableAuto bool |
| 48 | autoRouter map[string]map[string]reflect.Type //key:controller key:method value:reflect.type | 48 | autoRouter map[string]map[string]reflect.Type //key:controller key:method value:reflect.type |
| 49 | contextBuffer chan *beecontext.Context //context buffer pool | ||
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | func NewControllerRegistor() *ControllerRegistor { | 51 | func NewControllerRegistor() *ControllerRegistor { |
| 53 | return &ControllerRegistor{ | 52 | return &ControllerRegistor{ |
| 54 | routers: make([]*controllerInfo, 0), | 53 | routers: make([]*controllerInfo, 0), |
| 55 | autoRouter: make(map[string]map[string]reflect.Type), | 54 | autoRouter: make(map[string]map[string]reflect.Type), |
| 56 | filters: make(map[int][]*FilterRouter), | 55 | filters: make(map[int][]*FilterRouter), |
| 57 | contextBuffer: make(chan *beecontext.Context, 1000), | ||
| 58 | } | 56 | } |
| 59 | } | 57 | } |
| 60 | 58 | ||
| ... | @@ -440,31 +438,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) | ... | @@ -440,31 +438,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) |
| 440 | w.Header().Set("Server", BeegoServerName) | 438 | w.Header().Set("Server", BeegoServerName) |
| 441 | 439 | ||
| 442 | // init context | 440 | // init context |
| 443 | var context *beecontext.Context | 441 | context := &beecontext.Context{ |
| 444 | select { | 442 | ResponseWriter: w, |
| 445 | case context = <-p.contextBuffer: | 443 | Request: r, |
| 446 | context.ResponseWriter = w | 444 | Input: beecontext.NewInput(r), |
| 447 | context.Request = r | 445 | Output: beecontext.NewOutput(), |
| 448 | context.Input.Request = r | 446 | } |
| 449 | default: | 447 | context.Output.Context = context |
| 450 | context = &beecontext.Context{ | 448 | context.Output.EnableGzip = EnableGzip |
| 451 | ResponseWriter: w, | ||
| 452 | Request: r, | ||
| 453 | Input: beecontext.NewInput(r), | ||
| 454 | Output: beecontext.NewOutput(), | ||
| 455 | } | ||
| 456 | context.Output.Context = context | ||
| 457 | context.Output.EnableGzip = EnableGzip | ||
| 458 | } | ||
| 459 | |||
| 460 | defer func() { | ||
| 461 | if context != nil { | ||
| 462 | select { | ||
| 463 | case p.contextBuffer <- context: | ||
| 464 | default: | ||
| 465 | } | ||
| 466 | } | ||
| 467 | }() | ||
| 468 | 449 | ||
| 469 | if context.Input.IsWebsocket() { | 450 | if context.Input.IsWebsocket() { |
| 470 | context.ResponseWriter = rw | 451 | context.ResponseWriter = rw | ... | ... |
-
Please register or sign in to post a comment