mirror of https://github.com/schollz/croc.git
update
This commit is contained in:
parent
7d5d7e6cfb
commit
02196654d9
|
@ -32,9 +32,8 @@ func (c Comm) Close() {
|
|||
c.connection.Close()
|
||||
}
|
||||
|
||||
|
||||
func (c Comm) Write(b []byte) (int, error) {
|
||||
c.connection.Write([]byte(fmt.Sprintf("%0.5d", len(b))))
|
||||
c.connection.Write([]byte(fmt.Sprintf("%0.6d", len(b))))
|
||||
n, err := c.connection.Write(b)
|
||||
if n != len(b) {
|
||||
err = fmt.Errorf("wanted to write %d but wrote %d", n, len(b))
|
||||
|
@ -44,8 +43,8 @@ func (c Comm) Write(b []byte) (int, error) {
|
|||
}
|
||||
|
||||
func (c Comm) Read() (buf []byte, numBytes int, bs []byte, err error) {
|
||||
// read until we get 5 bytes
|
||||
tmp := make([]byte, 5)
|
||||
// read until we get 6 bytes
|
||||
tmp := make([]byte, 6)
|
||||
n, err := c.connection.Read(tmp)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -59,7 +58,7 @@ func (c Comm) Read() (buf []byte, numBytes int, bs []byte, err error) {
|
|||
for {
|
||||
// see if we have enough bytes
|
||||
bs = bytes.Trim(bs, "\x00")
|
||||
if len(bs) == 5 {
|
||||
if len(bs) == 6 {
|
||||
break
|
||||
}
|
||||
n, err := c.connection.Read(tmp)
|
||||
|
|
Loading…
Reference in New Issue