MCPcopy Create free account
hub / github.com/cloudwego/netpoll / WriteBuffer

Method WriteBuffer

nocopy_linkbuffer.go:502–538  ·  view source on GitHub ↗

WriteBuffer will not submit(e.g. Flush) data to ensure normal use of MallocLen. you must actively submit before read the data. The argument buf can't be used after calling WriteBuffer. (set it to nil)

(buf *LinkBuffer)

Source from the content-addressed store, hash-verified

500// you must actively submit before read the data.
501// The argument buf can't be used after calling WriteBuffer. (set it to nil)
502func (b *UnsafeLinkBuffer) WriteBuffer(buf *LinkBuffer) (err error) {
503 if buf == nil {
504 return
505 }
506 bufLen, bufMallocLen := buf.Len(), buf.MallocLen()
507 if bufLen+bufMallocLen <= 0 {
508 return nil
509 }
510 b.write.next = buf.read
511 b.write = buf.write
512
513 // close buf, prevents reuse.
514 for buf.head != buf.read {
515 nd := buf.head
516 buf.head = buf.head.next
517 nd.Release()
518 }
519 for buf.write = buf.write.next; buf.write != nil; {
520 nd := buf.write
521 buf.write = buf.write.next
522 nd.Release()
523 }
524 buf.length, buf.mallocSize, buf.head, buf.read, buf.flush, buf.write = 0, 0, nil, nil, nil, nil
525
526 // DON'T MODIFY THE CODE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING !
527 //
528 // You may encounter a chain of bugs and not be able to
529 // find out within a week that they are caused by modifications here.
530 //
531 // After release buf, continue to adjust b.
532 b.write.next = nil
533 if bufLen > 0 {
534 b.recalLen(bufLen)
535 }
536 b.mallocSize += bufMallocLen
537 return nil
538}
539
540// WriteString implements Writer.
541func (b *UnsafeLinkBuffer) WriteString(s string) (n int, err error) {

Callers 3

AppendMethod · 0.95
TestLinkBufferReferFunction · 0.45

Calls 4

recalLenMethod · 0.95
LenMethod · 0.65
MallocLenMethod · 0.65
ReleaseMethod · 0.65

Tested by 2

TestLinkBufferReferFunction · 0.36