asio :: streambufの使用で問題が発生しましたが、クラスを誤って使用しているかどうかを誰かに教えてもらいたいと思っています。このサンプルコードを実行すると、segfaultsになります。なんで?
さらに混乱させるために、このコードはWindows(Visual Studio 2008)では機能しますが、Linux(gcc 4.4.1では)では機能しません。
#include <boost/asio.hpp>
using namespace std;
int main()
{
boost::asio::streambuf Stream;
// Put 4 bytes into the streambuf...
int SetValue = 0xaabbccdd;
Stream.sputn(reinterpret_cast<const char*>(&SetValue), sizeof(SetValue));
// Consume 3 of the bytes...
Stream.consume(3);
cout << Stream.size() << endl; // should output 1
// Get the last byte...
char GetValue;
// --------- The next line segfaults the program ----------
Stream.sgetn(reinterpret_cast<char*>(&GetValue), sizeof(GetValue));
cout << Stream.size() << endl; // should output 0
return 0;
}