close stream and delete from conn.streams

merge_conn
fangdingjun 6 years ago
parent 563e006303
commit 58e1343da1

@ -198,7 +198,7 @@ func onServerStreamClose(ptr unsafe.Pointer, streamID C.int) C.int {
//conn.lock.Lock() //conn.lock.Lock()
delete(conn.streams, int(streamID)) delete(conn.streams, int(streamID))
//conn.lock.Unlock() //conn.lock.Unlock()
s.Close() go s.Close()
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR
} }
@ -406,7 +406,7 @@ func onClientStreamClose(ptr unsafe.Pointer, streamID C.int) C.int {
stream, ok := conn.streams[int(streamID)] stream, ok := conn.streams[int(streamID)]
if ok { if ok {
stream.Close() go stream.Close()
//conn.lock.Lock() //conn.lock.Lock()
delete(conn.streams, int(streamID)) delete(conn.streams, int(streamID))
//go stream.Close() //go stream.Close()

@ -68,16 +68,18 @@ func (c *ClientConn) Error() error {
// Close close the http2 connection // Close close the http2 connection
func (c *ClientConn) Close() error { func (c *ClientConn) Close() error {
c.lock.Lock()
defer c.lock.Unlock()
if c.closed { if c.closed {
return nil return nil
} }
//log.Println("close client connection")
c.closed = true c.closed = true
for _, s := range c.streams { for _, s := range c.streams {
s.Close() s.Close()
} }
c.lock.Lock()
defer c.lock.Unlock()
//log.Println("close client connection")
C.nghttp2_session_terminate_session(c.session, 0) C.nghttp2_session_terminate_session(c.session, 0)
C.nghttp2_session_del(c.session) C.nghttp2_session_del(c.session)
close(c.exitch) close(c.exitch)
@ -428,20 +430,21 @@ func (c *ServerConn) serve(s *ServerStream) {
// Close close the server connection // Close close the server connection
func (c *ServerConn) Close() error { func (c *ServerConn) Close() error {
c.lock.Lock()
defer c.lock.Unlock()
if c.closed { if c.closed {
return nil return nil
} }
c.closed = true
for _, s := range c.streams { for _, s := range c.streams {
s.Close() s.Close()
} }
c.lock.Lock()
defer c.lock.Unlock()
C.nghttp2_session_terminate_session(c.session, 0) C.nghttp2_session_terminate_session(c.session, 0)
C.nghttp2_session_del(c.session) C.nghttp2_session_del(c.session)
close(c.exitch) close(c.exitch)
c.conn.Close() c.conn.Close()
c.closed = true
return nil return nil
} }

@ -89,11 +89,11 @@ func (s *ClientStream) Close() error {
s.cdp = nil s.cdp = nil
} }
//s.conn.lock.Lock() s.conn.lock.Lock()
//defer s.conn.lock.Unlock() defer s.conn.lock.Unlock()
//if _, ok := s.conn.streams[s.streamID]; ok { if _, ok := s.conn.streams[s.streamID]; ok {
//delete(s.conn.streams, s.streamID) delete(s.conn.streams, s.streamID)
//} }
return nil return nil
} }
@ -209,6 +209,12 @@ func (s *ServerStream) Close() error {
C.free(unsafe.Pointer(s.cdp)) C.free(unsafe.Pointer(s.cdp))
s.cdp = nil s.cdp = nil
} }
s.conn.lock.Lock()
s.conn.lock.Unlock()
if _, ok := s.conn.streams[s.streamID]; ok {
delete(s.conn.streams, s.streamID)
}
//log.Printf("stream %d closed", s.streamID) //log.Printf("stream %d closed", s.streamID)
return nil return nil
} }

Loading…
Cancel
Save