-
Notifications
You must be signed in to change notification settings - Fork 3
/
client_send.go
67 lines (52 loc) · 1.16 KB
/
client_send.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package rtmp
import (
"io"
)
func (c *Client) sendLoop() {
for {
m, open := <-c.outMessages
if !open {
log.Debug("client send: channel closed, exiting")
return
}
log.Trace("client send: processing message: %#v", m)
var cs *OutboundChunkStream = c.outChunkStreams[m.ChunkStreamId]
if cs == nil {
cs = NewOutboundChunkStream(m.ChunkStreamId)
}
h := cs.NewOutboundHeader(m)
var n int64 = 0
var err error
var ws uint32 = 0
var rem uint32 = m.Length
for rem > 0 {
log.Trace("client send: send header: %+v", h)
_, err = h.Write(c)
if err != nil {
if c.IsAlive() {
log.Warn("unable to send header: %v", err)
c.Reset()
}
return
}
ws = rem
if ws > c.outChunkSize {
ws = c.outChunkSize
}
log.Trace("client send: send bytes: %d", ws)
n, err = io.CopyN(c, m.Buffer, int64(ws))
if err != nil {
if c.IsAlive() {
log.Warn("unable to send message")
c.Reset()
}
return
}
rem -= uint32(n)
// Set the header to continuation only for the
// next iteration (if it happens).
h.Format = HEADER_FORMAT_CONTINUATION
}
log.Trace("client send: send complete")
}
}