FreeRDP/FreeRDP — pull request #1879 by awakecoding (2014-06-02 02:06:59+00:00)
Title: Async Transport BIO full duplex support

This pull request fixes issue #1876

* Add new simple TCP BIO (full duplex)
* Add new simple TLS BIO (full duplex)
* Fix TSG BIO for full duplex support
* Implement core winsock functions
* Add debugger output support in WLog

The core of the issue for full duplex support is the usage of the retry flags in the BIO data structure: most built-in BIOs start a read/write operation by resetting all flags, including the "retry" flag which is shared by read/write retry types. This means that calls to BIO_should_retry can randomly fail if read/write operations are done in parallel (full duplex), as the flags can be reset at any time.

The retry flag is only checked when a read/write operation returns 0 or a negative value. If BIO_should_retry returns false in those conditions, then the previous status code is considered as a fatal error. The trick was to roll our own TCP and TLS BIOs that always set the retry flag unless a fatal error has occurred, and to reset just the flags of interest instead of all flags on every operation.