#include <df.h>


Definition at line 360 of file df.h.
Public Member Functions | |
| blk_StdIOWriter (df_BlockManager &a_mgr, const string &a_fName) | |
| virtual | ~blk_StdIOWriter () |
Private Member Functions | |
| virtual void | Seek (const UInt32_t a_offset) |
| Seek forward for the specified number of bytes. | |
| virtual void | Write (const UInt8_t *a_data, const UInt32_t a_size) |
| Write one block of data to stdout. | |
Private Attributes | |
| log_CLASSID_m | |
| int | m_fHandle |
| UInt32_t | m_seqNumber |
Static Private Attributes | |
| static UInt32_t | m_numActive = 0 |
| static cmn_Mutex | m_numActive_x |
| blk_StdIOWriter::blk_StdIOWriter | ( | df_BlockManager & | a_mgr, | |
| const string & | a_fName | |||
| ) |
Definition at line 48 of file blk_stdiowriter.cpp.
References dbg_NORM, errno, log_DBG_m, log_FUNC_A_m, m_fHandle, m_numActive, m_numActive_x, m_seqNumber, and O_BINARY.
00051 : blk_BufferWriter(a_mgr), 00052 m_seqNumber(0) { 00053 00054 log_FUNC_A_m(blk_StdIOWriter, "fName=" << a_fName); 00055 00056 if (a_fName.empty()) { 00057 log_DBG_m(dbg_NORM, "Using stdout for DF output"); 00058 m_fHandle = dup(fileno(stdout)); 00059 if (m_fHandle == -1) { 00060 throw ivd_SysError(errno, "dup()", true); 00061 } 00062 #if TGT_OS_windows 00063 setmode(m_fHandle, O_BINARY); 00064 #endif 00065 } 00066 else { 00067 m_fHandle = open(a_fName.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_BINARY); 00068 if (m_fHandle == -1) { 00069 throw ivd_SysError(errno, "open()", true); 00070 } 00071 } 00072 00073 cmn_MutexLock l(m_numActive_x); 00074 m_numActive++; 00075 m_seqNumber = m_numActive; 00076 }
| blk_StdIOWriter::~blk_StdIOWriter | ( | ) | [virtual] |
Definition at line 78 of file blk_stdiowriter.cpp.
References errno, log_ERR_m, log_FUNC_m, m_fHandle, m_numActive, and m_numActive_x.
00078 { 00079 log_FUNC_m(~blk_StdIOWriter); 00080 00081 cmn_MutexLock l(m_numActive_x); 00082 m_numActive--; 00083 00084 if (fsync(m_fHandle) != 0) { 00085 log_ERR_m( 00086 "fsync() failed. Ignored. Error: " << errno); 00087 } 00088 00089 /* if (m_fHandle != _fileno(stdout)) */ { 00090 if (close(m_fHandle) != 0) { 00091 log_ERR_m( 00092 "close() failed. Ignored. Error: " << errno); 00093 } 00094 } 00095 }
| void blk_StdIOWriter::Seek | ( | const UInt32_t | a_offset | ) | [private, virtual] |
Seek forward for the specified number of bytes.
Used mainly to skip file if migration of a file is aborted. Will just write zeros
Reimplemented from blk_BufferWriter.
Definition at line 103 of file blk_stdiowriter.cpp.
References dbg_DETAIL, errno, log_DBG_m, log_FUNC_m, and m_fHandle.
00103 { 00104 log_FUNC_m(Seek); 00105 00106 log_DBG_m(dbg_DETAIL, 00107 "Seek forward for " << (a_offset/1024) << " kiB."); 00108 00109 UInt8_t zeros[4096]; 00110 memset(zeros, 0, 4096); 00111 00112 UInt32_t bytesLeft = a_offset; 00113 while (bytesLeft > 0) { 00114 UInt32_t bufSize = bytesLeft < 4096 ? bytesLeft : 4096; 00115 Int32_t bytesWritten = write(m_fHandle, zeros, bufSize); 00116 if (bytesWritten == -1) { 00117 throw ivd_SysError(errno, "write()", true); 00118 } 00119 bytesLeft -= bytesWritten; 00120 } 00121 }
Write one block of data to stdout.
Implements blk_BufferWriter.
Definition at line 126 of file blk_stdiowriter.cpp.
References dbg_DETAIL, errno, log_DBG_m, log_FUNC_m, and m_fHandle.
00126 { 00127 log_FUNC_m(Write); 00128 00129 log_DBG_m(dbg_DETAIL, "About to write " << a_size << " bytes"); 00130 Int32_t bytesWritten = write(m_fHandle, a_data, a_size); 00131 log_DBG_m(dbg_DETAIL, "Written " << a_size << " bytes"); 00132 if (bytesWritten == -1) { 00133 throw ivd_SysError(errno, "write()", true); 00134 } 00135 }
blk_StdIOWriter::log_CLASSID_m [private] |
int blk_StdIOWriter::m_fHandle [private] |
Definition at line 374 of file df.h.
Referenced by blk_StdIOWriter(), Seek(), Write(), and ~blk_StdIOWriter().
UInt32_t blk_StdIOWriter::m_numActive = 0 [static, private] |
cmn_Mutex blk_StdIOWriter::m_numActive_x [static, private] |
UInt32_t blk_StdIOWriter::m_seqNumber [private] |
1.5.6