diff --git a/evio.go b/evio.go index 8e31287..f5548a9 100644 --- a/evio.go +++ b/evio.go @@ -115,6 +115,8 @@ type Events struct { Detached func(c Conn, rwc io.ReadWriteCloser) (action Action) // PreWrite fires just before any data is written to any client socket. PreWrite func() + // PostWrite fires just after any data is written to any client socket. + PostWrite func(c Conn) // Data fires when a connection sends the server data. // The in parameter is the incoming data. // Use the out return value to write data to the connection. diff --git a/evio_std.go b/evio_std.go index 4eb3e27..ba01691 100644 --- a/evio_std.go +++ b/evio_std.go @@ -384,6 +384,9 @@ func stdloopRead(s *stdserver, l *stdloop, c *stdconn, in []byte) error { s.events.PreWrite() } c.conn.Write(out) + if s.events.PostWrite != nil { + s.events.PostWrite(c) + } } switch action { case Shutdown: @@ -405,6 +408,9 @@ func stdloopReadUDP(s *stdserver, l *stdloop, c *stdudpconn) error { s.events.PreWrite() } s.lns[c.addrIndex].pconn.WriteTo(out, c.remoteAddr) + if s.events.PostWrite != nil { + s.events.PostWrite(c) + } } switch action { case Shutdown: @@ -439,6 +445,9 @@ func stdloopAccept(s *stdserver, l *stdloop, c *stdconn) error { s.events.PreWrite() } c.conn.Write(out) + if s.events.PostWrite != nil { + s.events.PostWrite(c) + } } if opts.TCPKeepAlive > 0 { if c, ok := c.conn.(*net.TCPConn); ok { diff --git a/evio_unix.go b/evio_unix.go index 6efbca1..30c87c4 100644 --- a/evio_unix.go +++ b/evio_unix.go @@ -333,6 +333,9 @@ func loopUDPRead(s *server, l *loop, lnidx, fd int) error { s.events.PreWrite() } syscall.Sendto(fd, out, 0, sa) + if s.events.PostWrite != nil { + s.events.PostWrite(c) + } } switch action { case Shutdown: @@ -391,6 +394,9 @@ func loopWrite(s *server, l *loop, c *conn) error { if len(c.out) == 0 && c.action == None { l.poll.ModRead(c.fd) } + if len(c.out) == 0 && s.events.PostWrite != nil { + s.events.PostWrite(c) + } return nil }