Fix a compile error on MSVC
Fix an issue that extra flush call writes buffer twice

Issue: #1
Merge branch 'Issue1_DoubleFlush'