39 lines
644 B
Go
39 lines
644 B
Go
package suricata
|
|
|
|
import (
|
|
"bytes"
|
|
"sync"
|
|
)
|
|
|
|
// A thread-safe Buffer wrapper to enable concurrent access to log output.
|
|
type buffer struct {
|
|
b bytes.Buffer
|
|
m sync.Mutex
|
|
}
|
|
|
|
func (b *buffer) Read(p []byte) (n int, err error) {
|
|
b.m.Lock()
|
|
defer b.m.Unlock()
|
|
return b.b.Read(p)
|
|
}
|
|
func (b *buffer) Write(p []byte) (n int, err error) {
|
|
b.m.Lock()
|
|
defer b.m.Unlock()
|
|
return b.b.Write(p)
|
|
}
|
|
func (b *buffer) String() string {
|
|
b.m.Lock()
|
|
defer b.m.Unlock()
|
|
return b.b.String()
|
|
}
|
|
func (b *buffer) Reset() {
|
|
b.m.Lock()
|
|
defer b.m.Unlock()
|
|
b.b.Reset()
|
|
}
|
|
func (b *buffer) Bytes() []byte {
|
|
b.m.Lock()
|
|
defer b.m.Unlock()
|
|
return b.b.Bytes()
|
|
}
|