Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions evio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions evio_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions evio_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
}

Expand Down