@@ -60,14 +60,43 @@ const errorOnInvalidFD = false
6060const waitttl = wrapttl
6161
6262type FdSwapper interface {
63- // Cur returns the current FD.
64- Cur () int
6563 // Swap closes existing FDs; uses new fd.
6664 Swap (fd int ) error
6765 // Dispose closes all existing FDs.
6866 Dispose () error
69- // Stat returns csv (fd, age, read, written, lastRead, lastWrite) stats.
70- Stat () string
67+ // Stat returns EpStat (fd, age, read, written, lastRead, lastWrite).
68+ Stat () EpStat
69+ }
70+
71+ type EpStat struct {
72+ // Fd is the file descriptor of the endpoint.
73+ Fd int
74+ // Alive indicates whether the endpoint is alive.
75+ Alive bool
76+ // Age is the age of the endpoint.
77+ Age string
78+ // Read is the number of bytes read from the endpoint.
79+ Read string
80+ // Written is the number of bytes written to the endpoint.
81+ Written string
82+ // LastRead is the last time the endpoint was read from.
83+ LastRead string
84+ // LastWrite is the last time the endpoint was written to.
85+ LastWrite string
86+ }
87+
88+ func (s EpStat ) String () string {
89+ if s .Fd == 0 {
90+ return "<nil>"
91+ }
92+ return fmt .Sprintf ("Fd: %d,Alive: %t,Age: %s,R: %s,W: %s,LastRead: %s,LastWrite: %s" ,
93+ s .Fd ,
94+ s .Alive ,
95+ s .Age ,
96+ s .Read ,
97+ s .Written ,
98+ s .LastRead ,
99+ s .LastWrite )
71100}
72101
73102type SeamlessEndpoint interface {
@@ -243,14 +272,10 @@ func createInboundDispatcher(e *endpoint, f *fds) (linkDispatcher, error) {
243272 return d , nil
244273}
245274
246- func (e * endpoint ) Cur () int {
247- return e .fd ()
248- }
249-
250- func (e * endpoint ) Stat () string {
275+ func (e * endpoint ) Stat () (zz EpStat ) {
251276 fds := e .fds .Load ()
252277 if fds == nil {
253- return "<nil>"
278+ return
254279 }
255280
256281 t := time .Now ()
@@ -260,13 +285,15 @@ func (e *endpoint) Stat() string {
260285
261286 age := t .Sub (time .UnixMilli (fds .since .Load ()))
262287
263- return fmt .Sprintf ("Fd: %d, Age: %s, R: %s, W: %s, LastRead: %s, LastWrite%s" ,
264- fds .tunFd , // f.tun() returns invalidfd if f.tunFd is closed
265- core .FmtPeriod (age ),
266- core .FmtBytes (uint64 (fds .read .Load ())),
267- core .FmtBytes (uint64 (fds .written .Load ())),
268- core .FmtUnixMillisAsPeriod (fds .lastRead .Load ()),
269- core .FmtUnixMillisAsPeriod (fds .lastWrite .Load ()))
288+ return EpStat {
289+ Fd : fds .tunFd , // f.tun() returns invalidfd if f.tunFd is closed
290+ Alive : ! fds .closed .Load (),
291+ Age : core .FmtPeriod (age ),
292+ Read : core .FmtBytes (uint64 (fds .read .Load ())),
293+ Written : core .FmtBytes (uint64 (fds .written .Load ())),
294+ LastRead : core .FmtUnixMillisAsPeriod (fds .lastRead .Load ()),
295+ LastWrite : core .FmtUnixMillisAsPeriod (fds .lastWrite .Load ()),
296+ }
270297}
271298
272299func (e * endpoint ) Dispose () (err error ) {
0 commit comments