Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzc committed May 12, 2022
1 parent b3bd5ec commit 4c93077
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions net/conn.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net

import (
"io"
"errors"
"net"
"time"

Expand Down Expand Up @@ -70,45 +70,27 @@ func (conn *Conn) WriteChunks(c [][]byte) (n int, err error) {
}

func (conn *Conn) ReadBytes() ([]byte, error) {
// ret := make([]byte, 0)
// buf := make([]byte, BUF_SIZE)

// for {
// n, err := conn.Read(buf)
// if err != nil {
// switch err.(type) {
// case *net.OpError:
// return nil, errors.New("timed out")
// default:
// return nil, err
// }
// }
// ret = append(ret, buf[:n]...)

// if n == 0 {
// return nil, io.EOF
// }

// if n < BUF_SIZE {
// break
// }
// }
buf := make([]byte, 0, 4096) // big buffer
tmp := make([]byte, 256) // using small tmo buffer for demonstrating
ret := make([]byte, 0)
buf := make([]byte, BUF_SIZE)

for {
n, err := conn.Read(tmp)
n, err := conn.Read(buf)
if err != nil {
if err != io.EOF {
switch err.(type) {
case *net.OpError:
return nil, errors.New("timed out")
default:
return nil, err
}
}
ret = append(ret, buf[:n]...)

if n < BUF_SIZE {
break
}

buf = append(buf, tmp[:n]...)
}

return buf, nil
return ret, nil
}

func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
Expand Down

0 comments on commit 4c93077

Please sign in to comment.