not pass byte slice through channel on read loop

master
fangdingjun 6 years ago
parent 462ab85e7f
commit af990484d4

@ -374,48 +374,33 @@ 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 {
select {
case <-c.exitch:
return
default:
}
buf := make([]byte, 16*1024)
n, err1 = c.conn.Read(buf)
if err1 != nil {
c.errorNotify(err1)
break
}
datach <- buf[:n]
}
}()
for { for {
select { select {
case <-c.exitch: case <-c.exitch:
return return
case d := <-datach: default:
c.lock.Lock() }
if c.closed {
c.lock.Unlock() n, err := c.conn.Read(buf)
return if err != nil {
} c.errorNotify(err)
ret = C.nghttp2_session_mem_recv(c.session, return
(*C.uchar)(unsafe.Pointer(&d[0])), C.size_t(len(d))) }
c.lock.Lock()
if c.closed {
c.lock.Unlock() c.lock.Unlock()
if int(ret) < 0 { return
err = fmt.Errorf("http2 recv error: %s", C.GoString(C.nghttp2_strerror(C.int(ret)))) }
c.errorNotify(err)
return ret := C.nghttp2_session_mem_recv(c.session,
} (*C.uchar)(unsafe.Pointer(&buf[0])), C.size_t(n))
c.lock.Unlock()
if int(ret) < 0 {
err = fmt.Errorf("http2 recv error: %s", C.GoString(C.nghttp2_strerror(C.int(ret))))
c.errorNotify(err)
return
} }
} }
} }

Loading…
Cancel
Save