Timeout blocking read call.

This commit is contained in:
Arijit Das
2020-06-01 15:07:11 +05:30
parent 28899ea1e1
commit 803257c710
2 changed files with 14 additions and 12 deletions
+1 -2
View File
@@ -8,11 +8,10 @@ import (
"time"
)
var wg *sync.WaitGroup
var wg sync.WaitGroup
// Start initialize loop for sending data from inputs to outputs
func Start(plugins *InOutPlugins, stop chan int) {
wg = &sync.WaitGroup{}
if Settings.middleware != "" {
middleware := NewMiddleware(Settings.middleware)
+13 -10
View File
@@ -21,19 +21,22 @@ func NewTestInput() (i *TestInput) {
}
func (i *TestInput) Read(data []byte) (int, error) {
buf := <-i.data
select {
case buf := <-i.data:
var header []byte
var header []byte
if !i.skipHeader {
header = payloadHeader(RequestPayload, uuid(), time.Now().UnixNano(), -1)
copy(data[0:len(header)], header)
copy(data[len(header):], buf)
} else {
copy(data, buf)
}
if !i.skipHeader {
header = payloadHeader(RequestPayload, uuid(), time.Now().UnixNano(), -1)
copy(data[0:len(header)], header)
copy(data[len(header):], buf)
} else {
copy(data, buf)
return len(buf) + len(header), nil
case <-time.After(10* time.Second):
return 0, nil
}
return len(buf) + len(header), nil
}
func (i *TestInput) EmitBytes(data []byte) {