wait for buffer to be drained before closing
Merge pull request #351 from nkzawa/patch-6

wait for buffer to be drained before closing
Fixed transport close deferring logic.

Transport can still be upgrading after deferring until the drain event.
Merge pull request #352 from rase-/fix/defer-until-drain

Fixed transport close deferring logic.