mirror of https://github.com/pkg/sftp.git
close reader/writer when deleting request
This commit is contained in:
parent
352ba90280
commit
7e76fd5451
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
12
request.go
12
request.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue