mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
copy tcp writing into byte array
This commit is contained in:
parent
b0164920c7
commit
9d2f07f478
1 changed files with 6 additions and 2 deletions
|
@ -33,8 +33,12 @@ func (c Comm) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Comm) Write(b []byte) (int, error) {
|
func (c Comm) Write(b []byte) (int, error) {
|
||||||
n, err := c.connection.Write(append([]byte(fmt.Sprintf("%0.5d", len(b))), b...))
|
tmpCopy := make([]byte, len(b)+5)
|
||||||
if n != len(b)+5 {
|
// Copy the buffer so it doesn't get changed while read by the recipient.
|
||||||
|
copy(tmpCopy[:5], []byte(fmt.Sprintf("%0.5d", len(b))))
|
||||||
|
copy(tmpCopy[5:], b)
|
||||||
|
n, err := c.connection.Write(tmpCopy)
|
||||||
|
if n != len(tmpCopy) {
|
||||||
err = fmt.Errorf("wanted to write %d but wrote %d", len(b), n)
|
err = fmt.Errorf("wanted to write %d but wrote %d", len(b), n)
|
||||||
}
|
}
|
||||||
// log.Printf("wanted to write %d but wrote %d", n, len(b))
|
// log.Printf("wanted to write %d but wrote %d", n, len(b))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue