mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-29 04:22:24 +00:00
filch: a few minor comments
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
parent
a184e05290
commit
51a12d1307
@ -21,6 +21,7 @@ type Options struct {
|
|||||||
ReplaceStderr bool // dup over fd 2 so everything written to stderr comes here
|
ReplaceStderr bool // dup over fd 2 so everything written to stderr comes here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A Filch uses two alternating files as a simplistic ring buffer.
|
||||||
type Filch struct {
|
type Filch struct {
|
||||||
OrigStderr *os.File
|
OrigStderr *os.File
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ type Filch struct {
|
|||||||
recovered int64
|
recovered int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TryReadline implements the logtail.Buffer interface.
|
||||||
func (f *Filch) TryReadLine() ([]byte, error) {
|
func (f *Filch) TryReadLine() ([]byte, error) {
|
||||||
f.mu.Lock()
|
f.mu.Lock()
|
||||||
defer f.mu.Unlock()
|
defer f.mu.Unlock()
|
||||||
@ -75,6 +77,7 @@ func (f *Filch) scan() ([]byte, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write implements the logtail.Buffer interface.
|
||||||
func (f *Filch) Write(b []byte) (int, error) {
|
func (f *Filch) Write(b []byte) (int, error) {
|
||||||
f.mu.Lock()
|
f.mu.Lock()
|
||||||
defer f.mu.Unlock()
|
defer f.mu.Unlock()
|
||||||
@ -88,6 +91,7 @@ func (f *Filch) Write(b []byte) (int, error) {
|
|||||||
return f.cur.Write(b)
|
return f.cur.Write(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes the Filch, releasing all os resources.
|
||||||
func (f *Filch) Close() (err error) {
|
func (f *Filch) Close() (err error) {
|
||||||
f.mu.Lock()
|
f.mu.Lock()
|
||||||
defer f.mu.Unlock()
|
defer f.mu.Unlock()
|
||||||
@ -109,6 +113,7 @@ func (f *Filch) Close() (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates a new filch around two log files, each starting with filePrefix.
|
||||||
func New(filePrefix string, opts Options) (f *Filch, err error) {
|
func New(filePrefix string, opts Options) (f *Filch, err error) {
|
||||||
var f1, f2 *os.File
|
var f1, f2 *os.File
|
||||||
defer func() {
|
defer func() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user