Fix various problems identified with flushing batched messages:
- Flush triggered by disabling batching failed to flip buffer before writing and also failed to clear the buffer after writing was complete. This resulted in duplicated and/or corrupted messages.
- The flush triggered by session close was too late since no writes are permitted once the close process starts. This resulted in an exception being thrown.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk@1640690 13f79535-47bb-0310-9956-ffa450edef68