-
Notifications
You must be signed in to change notification settings - Fork 1
/
job.go
50 lines (40 loc) · 841 Bytes
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package elio
import (
"fmt"
)
// Job job interface
type Job interface {
String() string
Work() error
}
// WriteJob write job
type WriteJob struct {
session *Session
out []byte
}
// String string
func (j *WriteJob) String() string {
return fmt.Sprintf("WriteJob::%p", j)
}
// Work work
func (j *WriteJob) Work() (err error) {
defer func() {
j.session.DecRef()
}()
var out []byte
var written int
outs := j.session.outQueue.Fetch()
if 0 < len(outs) {
for _, o := range outs {
out = append(out, o.(*ByteBuffer).Bytes()...)
PutByteBuffer(o.(*ByteBuffer))
}
written, err = j.session.io.ioModel.Write(j.session, out)
if len(out) == written {
} else {
AppError().Str(LogSession, j.session.String()).
Err(err).Msgf("writing failed with fd:%v written:%d", j.session.fd, written)
}
}
return err
}