Internal change.

PiperOrigin-RevId: 233124342
Change-Id: Id4b4857af89815ffb9254cc30df4244b2768d9f2
This commit is contained in:
Christopher Koch 2019-02-08 14:13:17 -08:00 committed by Shentubot
parent 9c9386d2a8
commit b2aa213dd2
1 changed files with 17 additions and 2 deletions

View File

@ -175,13 +175,23 @@ type Server struct {
// wg is a wait group for all outstanding clients.
wg sync.WaitGroup
// afterRPCCallback is called after each RPC is successfully completed.
afterRPCCallback func()
}
// NewServer returns a new server.
func NewServer() *Server {
return NewServerWithCallback(nil)
}
// NewServerWithCallback returns a new server, who upon completion of each RPC
// calls the given function.
func NewServerWithCallback(afterRPCCallback func()) *Server {
return &Server{
methods: make(map[string]registeredMethod),
clients: make(map[*unet.Socket]clientState),
methods: make(map[string]registeredMethod),
clients: make(map[*unet.Socket]clientState),
afterRPCCallback: afterRPCCallback,
}
}
@ -274,6 +284,11 @@ func (s *Server) handleOne(client *unet.Socket) error {
return err
}
defer func() {
if s.afterRPCCallback != nil {
s.afterRPCCallback()
}
}()
// Explicitly close all these files after the call.
//
// This is also explicitly a reference to the files after the call,