feat: improve application access and money precision
This commit is contained in:
Vendored
+14
-2
@@ -79,6 +79,7 @@ type Server struct {
|
||||
// If nil, logging goes to os.Stderr via the log package's
|
||||
// standard logger.
|
||||
ErrorLog *log.Logger
|
||||
OnClose func(*Conn)
|
||||
}
|
||||
|
||||
// A conn represents the server side of a Cmpp connection.
|
||||
@@ -393,7 +394,12 @@ func (c *conn) serve() {
|
||||
}
|
||||
}()
|
||||
|
||||
defer c.close()
|
||||
defer func() {
|
||||
c.close()
|
||||
if c.server.OnClose != nil {
|
||||
c.server.OnClose(c.Conn)
|
||||
}
|
||||
}()
|
||||
|
||||
// start a goroutine for sending active test.
|
||||
startActiveTest(c)
|
||||
@@ -468,6 +474,12 @@ func (srv *Server) listenAndServe() error {
|
||||
// ListenAndServe listens on the TCP network address addr
|
||||
// and then calls Serve with handler to handle requests.
|
||||
func ListenAndServe(addr string, typ Type, t time.Duration, n int32, logWriter io.Writer, handlers ...Handler) error {
|
||||
return ListenAndServeWithClose(addr, typ, t, n, logWriter, nil, handlers...)
|
||||
}
|
||||
|
||||
// ListenAndServeWithClose behaves like ListenAndServe and invokes onClose once
|
||||
// after an accepted client connection ends, including abrupt TCP disconnects.
|
||||
func ListenAndServeWithClose(addr string, typ Type, t time.Duration, n int32, logWriter io.Writer, onClose func(*Conn), handlers ...Handler) error {
|
||||
if addr == "" {
|
||||
return ErrEmptyServerAddr
|
||||
}
|
||||
@@ -492,7 +504,7 @@ func ListenAndServe(addr string, typ Type, t time.Duration, n int32, logWriter i
|
||||
}
|
||||
server := &Server{Addr: addr, Handler: handler, Typ: typ,
|
||||
T: t, N: n,
|
||||
ErrorLog: log.New(logWriter, "cmppserver: ", log.LstdFlags)}
|
||||
ErrorLog: log.New(logWriter, "cmppserver: ", log.LstdFlags), OnClose: onClose}
|
||||
return server.listenAndServe()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user