24 Nov
2010
24 Nov
'10
9:20 p.m.
I understand that I add data to the streambuf, while async_write is in progress, but it's done in the same thread, and seems to be legitimate.
Well, after a more close look at the implementation of streambuf, I realized that this was absolutely invalid approach. When async_write() gets streamuf, its data() (actually a pointer to an element of std::vector) is passed to the underlying implementation.
From this point, any additional data put into the streambuf, might cause a resizing of the underlying std::vector, and such a resize invalidates the ptr previously returned from data(). I really don't understand why it never fails on Windows. Maybe just because WSASend works very quickly :).