MCPcopy Index your code
hub / github.com/coder/coder / writeTail

Method writeTail

agent/agentproc/headtail.go:117–142  ·  view source on GitHub ↗

writeTail appends data to the tail ring buffer. The caller must hold b.mu.

(p []byte)

Source from the content-addressed store, hash-verified

115// writeTail appends data to the tail ring buffer. The caller
116// must hold b.mu.
117func (b *HeadTailBuffer) writeTail(p []byte) {
118 if b.maxTail <= 0 {
119 return
120 }
121
122 // Lazily allocate the tail buffer on first use.
123 if b.tail == nil {
124 b.tail = make([]byte, b.maxTail)
125 }
126
127 for len(p) > 0 {
128 // Write as many bytes as fit starting at tailPos.
129 space := b.maxTail - b.tailPos
130 take := space
131 if take > len(p) {
132 take = len(p)
133 }
134 copy(b.tail[b.tailPos:b.tailPos+take], p[:take])
135 p = p[take:]
136 b.tailPos += take
137 if b.tailPos >= b.maxTail {
138 b.tailPos = 0
139 b.tailFull = true
140 }
141 }
142}
143
144// tailBytes returns the current tail contents in order. The
145// caller must hold b.mu.

Callers 1

WriteMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected