not pass byte slice through channel on read loop

master
fangdingjun 6 years ago
parent 462ab85e7f
commit af990484d4

@ -374,42 +374,28 @@ func (c *Conn) errorNotify(err error) {
} }
func (c *Conn) readloop() { func (c *Conn) readloop() {
buf := make([]byte, 16*1024)
var ret C.ssize_t
var err error
datach := make(chan []byte)
go func() {
var n int
var err1 error
for { for {
select { select {
case <-c.exitch: case <-c.exitch:
return return
default: default:
} }
buf := make([]byte, 16*1024)
n, err1 = c.conn.Read(buf)
if err1 != nil {
c.errorNotify(err1)
break
}
datach <- buf[:n]
}
}()
for { n, err := c.conn.Read(buf)
select { if err != nil {
case <-c.exitch: c.errorNotify(err)
return return
case d := <-datach: }
c.lock.Lock() c.lock.Lock()
if c.closed { if c.closed {
c.lock.Unlock() c.lock.Unlock()
return return
} }
ret = C.nghttp2_session_mem_recv(c.session,
(*C.uchar)(unsafe.Pointer(&d[0])), C.size_t(len(d))) ret := C.nghttp2_session_mem_recv(c.session,
(*C.uchar)(unsafe.Pointer(&buf[0])), C.size_t(n))
c.lock.Unlock() c.lock.Unlock()
if int(ret) < 0 { if int(ret) < 0 {
err = fmt.Errorf("http2 recv error: %s", C.GoString(C.nghttp2_strerror(C.int(ret)))) err = fmt.Errorf("http2 recv error: %s", C.GoString(C.nghttp2_strerror(C.int(ret))))
@ -418,7 +404,6 @@ func (c *Conn) readloop() {
} }
} }
} }
}
func (c *Conn) writeloop() { func (c *Conn) writeloop() {
var ret C.int var ret C.int

Loading…
Cancel
Save