close reader/writer when deleting request

This commit is contained in:
John Eikenberry 2016-08-19 11:52:43 -07:00
parent 352ba90280
commit 7e76fd5451
2 changed files with 14 additions and 1 deletions

View File

@ -68,7 +68,8 @@ func (rs *RequestServer) getRequest(handle string) (Request, bool) {
func (rs *RequestServer) closeRequest(handle string) {
rs.openRequestLock.Lock()
defer rs.openRequestLock.Unlock()
if _, ok := rs.openRequests[handle]; ok {
if r, ok := rs.openRequests[handle]; ok {
r.close()
delete(rs.openRequests, handle)
}
}

View File

@ -88,6 +88,18 @@ func (r Request) getEOD() bool {
return r.state.endofdir
}
// Close reader/writer if possible
func (r Request) close() {
rd := r.getReader()
if c, ok := rd.(io.Closer); ok {
c.Close()
}
wt := r.getWriter()
if c, ok := wt.(io.Closer); ok {
c.Close()
}
}
// push packet_data into fifo
func (r Request) pushPacket(pd packet_data) {
r.packets <- pd