@@ -76,6 +76,13 @@ type WorkerPool interface {
76
76
StopAndWait ()
77
77
}
78
78
79
+ type ReqWorkerPool interface {
80
+ Submit (req * protocol.Message , task func ())
81
+ StopAndWaitFor (deadline time.Duration )
82
+ Stop ()
83
+ StopAndWait ()
84
+ }
85
+
79
86
// Server is rpcx server that use TCP or UDP.
80
87
type Server struct {
81
88
ln net.Listener
@@ -90,6 +97,7 @@ type Server struct {
90
97
EnableProfile bool // enable profile and statsview or not
91
98
AsyncWrite bool // set true if your server only serves few clients
92
99
pool WorkerPool
100
+ reqPool ReqWorkerPool
93
101
94
102
serviceMapMu sync.RWMutex
95
103
serviceMap map [string ]* service
@@ -365,7 +373,15 @@ func (s *Server) sendResponse(ctx *share.Context, conn net.Conn, err error, req,
365
373
366
374
data := res .EncodeSlicePointer ()
367
375
if s .AsyncWrite {
368
- if s .pool != nil {
376
+ if s .reqPool != nil {
377
+ s .reqPool .Submit (req , func () {
378
+ if s .writeTimeout != 0 {
379
+ conn .SetWriteDeadline (time .Now ().Add (s .writeTimeout ))
380
+ }
381
+ conn .Write (* data )
382
+ protocol .PutData (data )
383
+ })
384
+ } else if s .pool != nil {
369
385
s .pool .Submit (func () {
370
386
if s .writeTimeout != 0 {
371
387
conn .SetWriteDeadline (time .Now ().Add (s .writeTimeout ))
@@ -514,7 +530,11 @@ func (s *Server) serveConn(conn net.Conn) {
514
530
continue
515
531
}
516
532
517
- if s .pool != nil {
533
+ if s .reqPool != nil {
534
+ s .reqPool .Submit (req , func () {
535
+ s .processOneRequest (ctx , req , conn )
536
+ })
537
+ } else if s .pool != nil {
518
538
s .pool .Submit (func () {
519
539
s .processOneRequest (ctx , req , conn )
520
540
})
@@ -921,6 +941,10 @@ func (s *Server) Close() error {
921
941
s .pool .StopAndWaitFor (10 * time .Second )
922
942
}
923
943
944
+ if s .reqPool != nil {
945
+ s .reqPool .StopAndWaitFor (10 * time .Second )
946
+ }
947
+
924
948
return err
925
949
}
926
950
0 commit comments