From a03fa624f765af35cb3979debc0b1b71617b4a6e Mon Sep 17 00:00:00 2001 From: John Date: Fri, 20 Jul 2018 18:14:21 +0800 Subject: [PATCH] =?UTF-8?q?gtcp=E8=AF=BB=E5=8F=96=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/net/gtcp/gtcp_conn.go | 10 +++++++--- geg/net/gtcp/gtcp_func.go | 14 ++++++++++++++ geg/net/gtcp/gtcp_pool2.go | 2 -- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 geg/net/gtcp/gtcp_func.go diff --git a/g/net/gtcp/gtcp_conn.go b/g/net/gtcp/gtcp_conn.go index 27a287905..e11a2d94f 100644 --- a/g/net/gtcp/gtcp_conn.go +++ b/g/net/gtcp/gtcp_conn.go @@ -11,6 +11,7 @@ import ( "time" "io" "bufio" + "fmt" ) // 封装的链接对象 @@ -83,7 +84,10 @@ func (c *Conn) Receive(length int, retry...Retry) ([]byte, error) { } else { buffer = make([]byte, gDEFAULT_READ_BUFFER_SIZE) } + for { + time.Sleep(time.Second) + fmt.Println(c.reader.Buffered()) size, err = c.reader.Read(buffer[index:]) if size > 0 { index += size @@ -94,9 +98,9 @@ func (c *Conn) Receive(length int, retry...Retry) ([]byte, error) { } } else { // 否则读取所有缓冲区数据,直到没有可读数据为止 - if c.reader.Buffered() < 1 { - break - } + //if c.reader.Buffered() < 1 { + // break + //} // 如果长度超过了自定义的读取缓冲区,那么自动增长 if index >= gDEFAULT_READ_BUFFER_SIZE { buffer = append(buffer, make([]byte, gDEFAULT_READ_BUFFER_SIZE)...) diff --git a/geg/net/gtcp/gtcp_func.go b/geg/net/gtcp/gtcp_func.go new file mode 100644 index 000000000..21e54e355 --- /dev/null +++ b/geg/net/gtcp/gtcp_func.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + "gitee.com/johng/gf/g/net/gtcp" +) + +func main() { + data, err := gtcp.SendReceive("www.baidu.com:80", []byte("GET / HTTP/1.1\n\n"), -1) + if err != nil { + panic(err) + } + fmt.Println(string(data)) +} \ No newline at end of file diff --git a/geg/net/gtcp/gtcp_pool2.go b/geg/net/gtcp/gtcp_pool2.go index 8c0b927f4..5fea0d1ea 100644 --- a/geg/net/gtcp/gtcp_pool2.go +++ b/geg/net/gtcp/gtcp_pool2.go @@ -42,6 +42,4 @@ func main() { } time.Sleep(time.Second) } - - select{} } \ No newline at end of file