MCPcopy Create free account
hub / github.com/DOSNetwork/core / writeTo

Function writeTo

p2p/client.go:543–567  ·  view source on GitHub ↗
(bytes []byte, conn net.Conn)

Source from the content-addressed store, hash-verified

541}
542
543func writeTo(bytes []byte, conn net.Conn) (err error) {
544 prefix := make([]byte, headerSize)
545 bytesWrite, totalBytesWrtie := 0, 0
546
547 size := len(bytes)
548 //TestPoint
549 //size = msgSizeLimit + 1
550 if size > msgSizeLimit {
551 err = errors.Errorf("SizeLimit %d size %d: %w",
552 msgSizeLimit, size, ErrMsgOverSize)
553 return
554 }
555 binary.BigEndian.PutUint32(prefix, uint32(size))
556 bytes = append(prefix, bytes...)
557 //TestPoint
558 //conn.Close()
559 for totalBytesWrtie < len(bytes) && err == nil {
560 if bytesWrite, err = conn.Write(bytes[totalBytesWrtie:]); err != nil {
561 err = errors.Errorf("conn write: %w", err)
562 return
563 }
564 totalBytesWrtie += bytesWrite
565 }
566 return
567}
568
569//read shold not be called in multiple go routine
570func readFrom(conn net.Conn) (buffer []byte, err error) {

Callers 2

sendIDMethod · 0.85
sendPipeMethod · 0.85

Calls 1

WriteMethod · 0.45

Tested by

no test coverage detected