From 6e095ea8a3c74c8a2a5ea1f24e4419fc7c10c32c Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 11 Dec 2003 05:00:18 +0000 Subject: [PATCH] buffer writes --- stepmania/src/RageFileDriverDirect.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/stepmania/src/RageFileDriverDirect.cpp b/stepmania/src/RageFileDriverDirect.cpp index 50074d1121..585d0081c0 100644 --- a/stepmania/src/RageFileDriverDirect.cpp +++ b/stepmania/src/RageFileDriverDirect.cpp @@ -169,6 +169,8 @@ private: int fd; CString path; /* for Copy */ + CString write_buf; + public: RageFileObjDirect( const CString &path, int fd_, RageFile &p ); virtual ~RageFileObjDirect(); @@ -341,10 +343,23 @@ RageFileObjDirect::RageFileObjDirect( const CString &path_, int fd_, RageFile &p path = path_; fd = fd_; ASSERT( fd != -1 ); + + if( parent.GetOpenMode() == RageFile::WRITE ) + write_buf.reserve( 1024*64 ); } RageFileObjDirect::~RageFileObjDirect() { + if( write_buf.size() ) + { + int ret = write( fd, write_buf.data(), write_buf.size() ); + if( ret == -1 ) + { + LOG->Warn("Error writing %s: %s", this->path.c_str(), strerror(errno) ); + SetError( strerror(errno) ); + } + } + if( fd != -1 ) close( fd ); } @@ -363,14 +378,8 @@ int RageFileObjDirect::Read( void *buf, size_t bytes ) int RageFileObjDirect::Write( const void *buf, size_t bytes ) { - int ret = write( fd, buf, bytes ); - if( ret == -1 ) - { - SetError( strerror(errno) ); - return -1; - } - - return ret; + write_buf.append( (const char *)buf, (const char *)buf+bytes ); + return bytes; } void RageFileObjDirect::Rewind()