Bugfix: Check stream when close socket
slight modification
Merge pull request #17 from bufferx/bugfix-stream-maybe-none

Bugfix: Check stream when close socket