[rhmessaging-commits] rhmessaging commits: r1460 - in store/trunk/cpp: tests/jrnl and 1 other directory.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Tue Dec 11 18:20:58 EST 2007
Author: kpvdr
Date: 2007-12-11 18:20:58 -0500 (Tue, 11 Dec 2007)
New Revision: 1460
Modified:
store/trunk/cpp/lib/jrnl/data_tok.cpp
store/trunk/cpp/lib/jrnl/deq_rec.cpp
store/trunk/cpp/lib/jrnl/enq_map.cpp
store/trunk/cpp/lib/jrnl/enq_rec.cpp
store/trunk/cpp/lib/jrnl/file_hdr.hpp
store/trunk/cpp/lib/jrnl/jcntl.cpp
store/trunk/cpp/lib/jrnl/jdir.cpp
store/trunk/cpp/lib/jrnl/jexception.cpp
store/trunk/cpp/lib/jrnl/jexception.hpp
store/trunk/cpp/lib/jrnl/jinf.cpp
store/trunk/cpp/lib/jrnl/jrec.cpp
store/trunk/cpp/lib/jrnl/nlfh.cpp
store/trunk/cpp/lib/jrnl/pmgr.cpp
store/trunk/cpp/lib/jrnl/rmgr.cpp
store/trunk/cpp/lib/jrnl/txn_map.cpp
store/trunk/cpp/lib/jrnl/txn_rec.cpp
store/trunk/cpp/lib/jrnl/wmgr.cpp
store/trunk/cpp/tests/jrnl/unit_test_jexception.cpp
Log:
More tidyup - added std::string back into jexception class, also switched instances of std::stringstream for std::ostringstream.
Modified: store/trunk/cpp/lib/jrnl/data_tok.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/data_tok.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/data_tok.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -145,10 +145,10 @@
{
if (_wstate != ENQ && rstate != UNREAD)
{
- std::stringstream ss;
- ss << "Attempted to change read state to " << rstate_str(rstate);
- ss << " while write state is not enqueued (wstate ENQ); wstate=" << wstate_str() << ".";
- throw new jexception(jerrno::JERR_DTOK_ILLEGALSTATE, ss.str().c_str(), "data_tok",
+ std::ostringstream oss;
+ oss << "Attempted to change read state to " << rstate_str(rstate);
+ oss << " while write state is not enqueued (wstate ENQ); wstate=" << wstate_str() << ".";
+ throw new jexception(jerrno::JERR_DTOK_ILLEGALSTATE, oss.str(), "data_tok",
"set_rstate");
}
_rstate = rstate;
Modified: store/trunk/cpp/lib/jrnl/deq_rec.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/deq_rec.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/deq_rec.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -386,14 +386,14 @@
std::string&
deq_rec::str(std::string& str) const
{
- std::stringstream ss;
- ss << "deq_rec: m=" << _deq_hdr._magic;
- ss << " v=" << (int)_deq_hdr._version;
- ss << " rid=" << _deq_hdr._rid;
- ss << " drid=" << _deq_hdr._deq_rid;
+ std::ostringstream oss;
+ oss << "deq_rec: m=" << _deq_hdr._magic;
+ oss << " v=" << (int)_deq_hdr._version;
+ oss << " rid=" << _deq_hdr._rid;
+ oss << " drid=" << _deq_hdr._deq_rid;
if (_xidp)
- ss << " xid=\"" << _xidp << "\"";
- str.append(ss.str());
+ oss << " xid=\"" << _xidp << "\"";
+ str.append(oss.str());
return str;
}
@@ -415,12 +415,12 @@
jrec::chk_hdr(_deq_hdr);
if (_deq_hdr._magic != RHM_JDAT_DEQ_MAGIC)
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "deq magic: rid=0x" << std::setw(16) << _deq_hdr._rid;
- ss << ": expected=0x" << std::setw(8) << RHM_JDAT_DEQ_MAGIC;
- ss << " read=0x" << std::setw(2) << (int)_deq_hdr._magic;
- throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "deq_rec", "chk_hdr");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "deq magic: rid=0x" << std::setw(16) << _deq_hdr._rid;
+ oss << ": expected=0x" << std::setw(8) << RHM_JDAT_DEQ_MAGIC;
+ oss << " read=0x" << std::setw(2) << (int)_deq_hdr._magic;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "deq_rec", "chk_hdr");
}
}
Modified: store/trunk/cpp/lib/jrnl/enq_map.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/enq_map.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/enq_map.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -67,9 +67,9 @@
pthread_mutex_unlock(&_mutex);
if (ret.second == false)
{
- std::stringstream ss;
- ss << std::hex << "rid=0x" << rid << " fid=0x" << fid;
- throw jexception(jerrno::JERR_MAP_DUPLICATE, ss.str().c_str(), "enq_map", "insert");
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid << " fid=0x" << fid;
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "enq_map", "insert");
}
}
@@ -81,15 +81,15 @@
pthread_mutex_unlock(&_mutex);
if (itr == _map.end()) // not found in map
{
- std::stringstream ss;
- ss << std::hex << "rid=0x" << rid;
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "enq_map", "get_fid");
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "get_fid");
}
if (itr->second.second) // locked
{
- std::stringstream ss;
- ss << std::hex << "rid=0x" << rid;
- throw jexception(jerrno::JERR_MAP_LOCKED, ss.str().c_str(), "enq_map", "get_fid");
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "enq_map", "get_fid");
}
return itr->second.first;
}
@@ -102,16 +102,16 @@
if (itr == _map.end()) // not found in map
{
pthread_mutex_unlock(&_mutex);
- std::stringstream ss;
- ss << std::hex << "rid=0x" << rid;
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "enq_map", "get_remove_fid");
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "get_remove_fid");
}
if (itr->second.second && !txn_flag) // locked, but not a commit/abort
{
pthread_mutex_unlock(&_mutex);
- std::stringstream ss;
- ss << std::hex << "rid=0x" << rid;
- throw jexception(jerrno::JERR_MAP_LOCKED, ss.str().c_str(), "enq_map", "get_remove_fid");
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "enq_map", "get_remove_fid");
}
u_int16_t fid = itr->second.first;
_map.erase(itr);
@@ -140,9 +140,9 @@
if (itr == _map.end()) // not found in map
{
pthread_mutex_unlock(&_mutex);
- std::stringstream ss;
- ss << std::hex << "rid=0x" << rid;
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "enq_map", "get_remove_fid");
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "get_remove_fid");
}
itr->second.second = true;
pthread_mutex_unlock(&_mutex);
@@ -156,9 +156,9 @@
if (itr == _map.end()) // not found in map
{
pthread_mutex_unlock(&_mutex);
- std::stringstream ss;
- ss << std::hex << "rid=0x" << rid;
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "enq_map", "get_remove_fid");
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "get_remove_fid");
}
itr->second.second = false;
pthread_mutex_unlock(&_mutex);
@@ -172,9 +172,9 @@
pthread_mutex_unlock(&_mutex);
if (itr == _map.end()) // not found in map
{
- std::stringstream ss;
- ss << std::hex << "rid=0x" << rid;
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "enq_map", "get_fid");
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "enq_map", "get_fid");
}
return itr->second.second;
}
Modified: store/trunk/cpp/lib/jrnl/enq_rec.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/enq_rec.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/enq_rec.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -539,14 +539,14 @@
std::string&
enq_rec::str(std::string& str) const
{
- std::stringstream ss;
- ss << "enq_rec: m=" << _enq_hdr._magic;
- ss << " v=" << (int)_enq_hdr._version;
- ss << " rid=" << _enq_hdr._rid;
+ std::ostringstream oss;
+ oss << "enq_rec: m=" << _enq_hdr._magic;
+ oss << " v=" << (int)_enq_hdr._version;
+ oss << " rid=" << _enq_hdr._rid;
if (_xidp)
- ss << " xid=\"" << _xidp << "\"";
- ss << " len=" << _enq_hdr._dsize;
- str.append(ss.str());
+ oss << " xid=\"" << _xidp << "\"";
+ oss << " len=" << _enq_hdr._dsize;
+ str.append(oss.str());
return str;
}
@@ -583,12 +583,12 @@
jrec::chk_hdr(_enq_hdr);
if (_enq_hdr._magic != RHM_JDAT_ENQ_MAGIC)
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "enq magic: rid=0x" << std::setw(16) << _enq_hdr._rid;
- ss << ": expected=0x" << std::setw(8) << RHM_JDAT_ENQ_MAGIC;
- ss << " read=0x" << std::setw(2) << (int)_enq_hdr._magic;
- throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "enq_rec", "chk_hdr");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "enq magic: rid=0x" << std::setw(16) << _enq_hdr._rid;
+ oss << ": expected=0x" << std::setw(8) << RHM_JDAT_ENQ_MAGIC;
+ oss << " read=0x" << std::setw(2) << (int)_enq_hdr._magic;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "enq_rec", "chk_hdr");
}
}
Modified: store/trunk/cpp/lib/jrnl/file_hdr.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/file_hdr.hpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/file_hdr.hpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -176,9 +176,9 @@
timespec ts;
if (::clock_gettime(CLOCK_REALTIME, &ts))
{
- std::stringstream ss;
- ss << "errno=" << errno;
- throw jexception(jerrno::JERR__RTCLOCK, ss.str().c_str(), "file_hdr", "set_time");
+ std::ostringstream oss;
+ oss << "errno=" << errno;
+ throw jexception(jerrno::JERR__RTCLOCK, oss.str(), "file_hdr", "set_time");
}
_ts_sec = ts.tv_sec;
_ts_nsec = ts.tv_nsec;
Modified: store/trunk/cpp/lib/jrnl/jcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/jcntl.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -111,9 +111,9 @@
::memset(_datafh, 0, sizeof(lfh*) * _num_jfiles);
for (u_int16_t i=0; i<_num_jfiles; i++)
{
- std::stringstream ss;
- ss << _jdir << "/" << _base_filename;
- _datafh[i] = ::new lfh(ss.str(), i, _jfsize_sblks, NULL);
+ std::ostringstream oss;
+ oss << _jdir << "/" << _base_filename;
+ _datafh[i] = ::new lfh(oss.str(), i, _jfsize_sblks, NULL);
}
// TODO: Check the following comment/note (may be obsolete):
@@ -162,9 +162,9 @@
::memset(_datafh, 0, sizeof(lfh*) * _num_jfiles);
for (u_int16_t i=0; i<_num_jfiles; i++)
{
- std::stringstream ss;
- ss << _jdir << "/" << _base_filename;
- _datafh[i] = ::new lfh(ss.str(), i, _jfsize_sblks, &_rcvdat);
+ std::ostringstream oss;
+ oss << _jdir << "/" << _base_filename;
+ _datafh[i] = ::new lfh(oss.str(), i, _jfsize_sblks, &_rcvdat);
}
// TODO: Check the following comment/note (may be obsolete):
@@ -369,9 +369,9 @@
timespec ts;
if (::clock_gettime(CLOCK_REALTIME, &ts))
{
- std::stringstream ss;
- ss << "errno=" << errno;
- throw jexception(jerrno::JERR__RTCLOCK, ss.str().c_str(), "jcntl", "write_infofile");
+ std::ostringstream oss;
+ oss << "errno=" << errno;
+ throw jexception(jerrno::JERR__RTCLOCK, oss.str(), "jcntl", "write_infofile");
}
jinf ji(_jid, _jdir.dirname(), _base_filename, _num_jfiles, _jfsize_sblks, ts);
ji.write();
@@ -586,10 +586,10 @@
rd._eo = read_pos;
return false;
}
- std::stringstream ss;
- ss << std::hex << std::setfill('0') << "Magic=0x" << std::setw(8) << h._magic;
- ss << " fid=" << fid << " foffs=0x" << std::setw(8) << read_pos;
- throw jexception(jerrno::JERR_JCNTL_UNKNOWNMAGIC, ss.str().c_str(), "jcntl",
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0') << "Magic=0x" << std::setw(8) << h._magic;
+ oss << " fid=" << fid << " foffs=0x" << std::setw(8) << read_pos;
+ throw jexception(jerrno::JERR_JCNTL_UNKNOWNMAGIC, oss.str(), "jcntl",
"rcvr_get_next_record");
}
return true;
@@ -641,12 +641,12 @@
}
if (!ifsp->is_open())
{
- std::stringstream ss;
- ss << _jdir.dirname() << "/" << _base_filename << ".";
- ss << std::hex << std::setfill('0') << std::setw(4) << fid << "." << JRNL_DATA_EXTENSION;
- ifsp->open(ss.str().c_str(), std::ios_base::in | std::ios_base::binary);
+ std::ostringstream oss;
+ oss << _jdir.dirname() << "/" << _base_filename << ".";
+ oss << std::hex << std::setfill('0') << std::setw(4) << fid << "." << JRNL_DATA_EXTENSION;
+ ifsp->open(oss.str().c_str(), std::ios_base::in | std::ios_base::binary);
if (!ifsp->good())
- throw jexception(jerrno::JERR__FILEIO, ss.str().c_str(), "jcntl", "jfile_cycle");
+ throw jexception(jerrno::JERR__FILEIO, oss.str(), "jcntl", "jfile_cycle");
// Read file header
file_hdr fhdr;
@@ -681,12 +681,12 @@
rd._eo = read_pos;
return false;
}
- std::stringstream ss;
- ss << std::hex << std::setfill('0') << "Magic=0x" << std::setw(8) << h._magic;
- ss << " fid=0x" << std::setw(4) << fid << " rid=0x" << std::setw(8) << h._rid;
- ss << " foffs=0x" << std::setw(8) << read_pos;
- ss << " expected_fid=0x" << std::setw(4) << expected_fid;
- throw jexception(jerrno::JERR_JCNTL_OWIMISMATCH, ss.str().c_str(), "jcntl",
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0') << "Magic=0x" << std::setw(8) << h._magic;
+ oss << " fid=0x" << std::setw(4) << fid << " rid=0x" << std::setw(8) << h._rid;
+ oss << " foffs=0x" << std::setw(8) << read_pos;
+ oss << " expected_fid=0x" << std::setw(4) << expected_fid;
+ throw jexception(jerrno::JERR_JCNTL_OWIMISMATCH, oss.str(), "jcntl",
"check_owi");
}
if (rd._h_rid < h._rid)
@@ -707,14 +707,13 @@
(JRNL_SBLK_SIZE - (sblk_offs/JRNL_DBLK_SIZE)) <<
" filler record(s) required." << std::endl;
const u_int32_t xmagic = RHM_JDAT_EMPTY_MAGIC;
- std::stringstream ss;
- ss << _jdir.dirname() << "/" << _base_filename << ".";
- ss << std::hex << std::setfill('0') << std::setw(4) << fid << "." << JRNL_DATA_EXTENSION;
- std::ofstream ofsp(ss.str().c_str(),
+ std::ostringstream oss;
+ oss << _jdir.dirname() << "/" << _base_filename << ".";
+ oss << std::hex << std::setfill('0') << std::setw(4) << fid << "." << JRNL_DATA_EXTENSION;
+ std::ofstream ofsp(oss.str().c_str(),
std::ios_base::in | std::ios_base::out | std::ios_base::binary);
if (!ofsp.good())
- throw jexception(jerrno::JERR__FILEIO, ss.str().c_str(), "jcntl",
- "check_journal_alignment");
+ throw jexception(jerrno::JERR__FILEIO, oss.str(), "jcntl", "check_journal_alignment");
ofsp.seekp(rec_offset);
void* buff = ::malloc(JRNL_DBLK_SIZE);
assert(buff != NULL);
Modified: store/trunk/cpp/lib/jrnl/jdir.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jdir.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/jdir.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -85,9 +85,9 @@
{
if (::mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
{
- std::stringstream ss;
- ss << "dir=\"" << dirname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_MKDIR, ss.str().c_str(), "jdir", "create_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_MKDIR, oss.str(), "jdir", "create_dir");
}
}
}
@@ -123,9 +123,9 @@
create_dir(dirname);
return;
}
- std::stringstream ss;
- ss << "dir=\"" << dirname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_OPENDIR, ss.str().c_str(), "jdir", "clear_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_OPENDIR, oss.str(), "jdir", "clear_dir");
}
#ifndef RHM_JOWRITE
struct dirent* entry;
@@ -145,17 +145,16 @@
bak_dir = create_bak_dir(dirname, base_filename);
found = true;
}
- std::stringstream oldname;
+ std::ostringstream oldname;
oldname << dirname << "/" << entry->d_name;
- std::stringstream newname;
+ std::ostringstream newname;
newname << bak_dir << "/" << entry->d_name;
if (::rename(oldname.str().c_str(), newname.str().c_str()))
{
- std::stringstream ss;
- ss << "file=\"" << oldname.str() << "\" dest=\"" <<
+ std::ostringstream oss;
+ oss << "file=\"" << oldname.str() << "\" dest=\"" <<
newname.str() << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_FMOVE, ss.str().c_str(), "jdir",
- "clear_dir");
+ throw jexception(jerrno::JERR_JDIR_FMOVE, oss.str(), "jdir", "clear_dir");
}
}
}
@@ -165,17 +164,17 @@
// While commented out, there is no error capture from reading dir entries.
// if (errno)
// {
-// std::stringstream ss;
-// ss << "dir=\"" << dirname << "\" errno=" << errno;
+// std::ostringstream oss;
+// oss << "dir=\"" << dirname << "\" errno=" << errno;
// ::closedir(dir); // Try to close, it makes no sense to trap errors here...
-// throw jexception(jerrno::JERR_JDIR_READDIR, ss.str().c_str(), "jdir", "clear_dir");
+// throw jexception(jerrno::JERR_JDIR_READDIR, oss.str(), "jdir", "clear_dir");
// }
#endif
if (::closedir(dir))
{
- std::stringstream ss;
- ss << "dir=\"" << dirname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_CLOSEDIR, ss.str().c_str(), "jdir", "clear_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_CLOSEDIR, oss.str(), "jdir", "clear_dir");
}
}
@@ -200,21 +199,21 @@
{
if (!is_dir(dirname))
{
- std::stringstream ss;
- ss << "dir=\"" << dirname << "\"";
- throw jexception(jerrno::JERR_JDIR_NOTDIR, ss.str().c_str(), "jdir", "verify_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\"";
+ throw jexception(jerrno::JERR_JDIR_NOTDIR, oss.str(), "jdir", "verify_dir");
}
// Read jinf file, then verify all journal files are present
jinf ji(dirname + "/" + base_filename + "." + JRNL_INFO_EXTENSION, true);
for (u_int16_t fnum=0; fnum < ji.num_jfiles(); fnum++)
{
- std::stringstream ss;
- ss << dirname << "/" << base_filename << ".";
- ss << std::setw(4) << std::setfill('0') << std::hex << fnum;
- ss << "." << JRNL_DATA_EXTENSION;
- if (!exists(ss.str()))
- throw jexception(jerrno::JERR_JDIR_NOSUCHFILE, ss.str().c_str(), "jdir", "verify_dir");
+ std::ostringstream oss;
+ oss << dirname << "/" << base_filename << ".";
+ oss << std::setw(4) << std::setfill('0') << std::hex << fnum;
+ oss << "." << JRNL_DATA_EXTENSION;
+ if (!exists(oss.str()))
+ throw jexception(jerrno::JERR_JDIR_NOSUCHFILE, oss.str(), "jdir", "verify_dir");
}
}
@@ -244,9 +243,9 @@
if (errno == ENOENT) // dir does not exist.
return;
- std::stringstream ss;
- ss << "dir=\"" << dirname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_OPENDIR, ss.str().c_str(), "jdir", "delete_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_OPENDIR, oss.str(), "jdir", "delete_dir");
}
else
{
@@ -258,10 +257,9 @@
std::string full_name(dirname + "/" + entry->d_name);
if (::stat(full_name.c_str(), &s))
{
- std::stringstream ss;
- ss << "stat: file=\"" << full_name << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_STAT, ss.str().c_str(), "jdir",
- "delete_dir");
+ std::ostringstream oss;
+ oss << "stat: file=\"" << full_name << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_STAT, oss.str(), "jdir", "delete_dir");
}
// FIXME: This fn does not handle symbolic links correctly and throws up
// For some reason, S_ISLNK() fails to identify links correctly.
@@ -269,10 +267,9 @@
{
if(::unlink(full_name.c_str()))
{
- std::stringstream ss;
- ss << "unlink: file=\"" << entry->d_name << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_UNLINK, ss.str().c_str(), "jdir",
- "delete_dir");
+ std::ostringstream oss;
+ oss << "unlink: file=\"" << entry->d_name << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_UNLINK, oss.str(), "jdir", "delete_dir");
}
}
else if (S_ISDIR(s.st_mode)) // This is a dir
@@ -281,11 +278,10 @@
}
else // all other types, throw up!
{
- std::stringstream ss;
- ss << "file=\"" << entry->d_name << "\" is not a dir, file or slink.";
- ss << " (mode=0x" << std::hex << s.st_mode << std::dec << ")";
- throw jexception(jerrno::JERR_JDIR_BADFTYPE, ss.str().c_str(), "jdir",
- "delete_dir");
+ std::ostringstream oss;
+ oss << "file=\"" << entry->d_name << "\" is not a dir, file or slink.";
+ oss << " (mode=0x" << std::hex << s.st_mode << std::dec << ")";
+ throw jexception(jerrno::JERR_JDIR_BADFTYPE, oss.str(), "jdir", "delete_dir");
}
}
}
@@ -293,26 +289,26 @@
// While commented out, there is no error capture from reading dir entries.
// if (errno)
// {
-// std::stringstream ss;
-// ss << "dir=\"" << dirname << "\" errno=" << errno;
+// std::ostringstream oss;
+// oss << "dir=\"" << dirname << "\" errno=" << errno;
// ::closedir(dir); // Try to close, it makes no sense to trap errors here...
-// throw jexception(jerrno::JERR_JDIR_READDIR, ss.str().c_str(), "jdir", "delete_dir");
+// throw jexception(jerrno::JERR_JDIR_READDIR, oss.str(), "jdir", "delete_dir");
// }
}
// Now dir is empty, close and delete it
if (::closedir(dir))
{
- std::stringstream ss;
- ss << "dir=\"" << dirname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_CLOSEDIR, ss.str().c_str(), "jdir", "delete_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_CLOSEDIR, oss.str(), "jdir", "delete_dir");
}
if (!children_only)
if (::rmdir(dirname.c_str()))
{
- std::stringstream ss;
- ss << "dir=\"" << dirname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_RMDIR, ss.str().c_str(), "jdir", "delete_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_RMDIR, oss.str(), "jdir", "delete_dir");
}
}
@@ -324,9 +320,9 @@
long dir_num = 0L;
if (!dir)
{
- std::stringstream ss;
- ss << "dir=\"" << dirname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_OPENDIR, ss.str().c_str(), "jdir", "create_bak_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_OPENDIR, oss.str(), "jdir", "create_bak_dir");
}
struct dirent* entry;
while ((entry = ::readdir(dir)) != NULL)
@@ -336,9 +332,9 @@
{
if (::strlen(entry->d_name) == base_filename.size() + 10) // Format: basename.bak.XXXX
{
- std::stringstream ss;
- ss << "_" << base_filename << ".bak.";
- if (::strncmp(entry->d_name, ss.str().c_str(), base_filename.size() + 6) == 0)
+ std::ostringstream oss;
+ oss << "_" << base_filename << ".bak.";
+ if (::strncmp(entry->d_name, oss.str().c_str(), base_filename.size() + 6) == 0)
{
long this_dir_num = ::strtol(entry->d_name + base_filename.size() + 6,
NULL, 16);
@@ -352,25 +348,25 @@
// While commented out, there is no error capture from reading dir entries.
// if (errno)
// {
-// std::stringstream ss;
-// ss << "dir=\"" << dirname << "\" errno=" << errno;
+// std::ostringstream oss;
+// oss << "dir=\"" << dirname << "\" errno=" << errno;
// ::closedir(dir); // Try to close, it makes no sense to trap errors here...
-// throw jexception(jerrno::JERR_JDIR_READDIR, ss.str().c_str(), "jdir", "clear_dir");
+// throw jexception(jerrno::JERR_JDIR_READDIR, oss.str(), "jdir", "clear_dir");
// }
if (::closedir(dir))
{
- std::stringstream ss;
- ss << "dir=\"" << dirname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_CLOSEDIR, ss.str().c_str(), "jdir", "create_bak_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_CLOSEDIR, oss.str(), "jdir", "create_bak_dir");
}
- std::stringstream dn;
+ std::ostringstream dn;
dn << dirname << "/_" << base_filename << ".bak." << std::hex << std::setw(4) <<
std::setfill('0') << ++dir_num;
if (::mkdir(dn.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH))
{
- std::stringstream ss;
- ss << "dir=\"" << dn.str() << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_MKDIR, ss.str().c_str(), "jdir", "create_bak_dir");
+ std::ostringstream oss;
+ oss << "dir=\"" << dn.str() << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_MKDIR, oss.str(), "jdir", "create_bak_dir");
}
return std::string(dn.str());
}
@@ -381,9 +377,9 @@
struct stat s;
if (::stat(name, &s))
{
- std::stringstream ss;
- ss << "file=\"" << name << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_STAT, ss.str().c_str(), "jdir", "is_dir");
+ std::ostringstream oss;
+ oss << "file=\"" << name << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_STAT, oss.str(), "jdir", "is_dir");
}
return S_ISDIR(s.st_mode);
}
@@ -403,9 +399,9 @@
if (errno == ENOENT) // No such dir or file
return false;
// Throw for any other condition
- std::stringstream ss;
- ss << "file=\"" << name << "\" errno=" << errno;
- throw jexception(jerrno::JERR_JDIR_STAT, ss.str().c_str(), "jdir", "is_dir");
+ std::ostringstream oss;
+ oss << "file=\"" << name << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_JDIR_STAT, oss.str(), "jdir", "is_dir");
}
return true;
}
Modified: store/trunk/cpp/lib/jrnl/jexception.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jexception.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/jexception.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -46,143 +46,97 @@
jexception::jexception() throw ():
std::exception(),
_err_code(0)
-{
- ::sprintf(_what_msg, "jexception 0x0000");
- *_additional_info = '\0';
- *_throwing_class = '\0';
- *_throwing_fn = '\0';
-}
+{}
jexception::jexception(const u_int32_t err_code) throw ():
std::exception(),
_err_code(err_code)
-{
- ::sprintf(_what_msg, "jexception 0x%04X ", err_code);
- ::strncat(_what_msg, jerrno::err_msg(err_code), CATLEN(_what_msg));
- *_additional_info = '\0';
- *_throwing_class = '\0';
- *_throwing_fn = '\0';
-}
+{}
jexception::jexception(const char* additional_info) throw ():
std::exception(),
- _err_code(0)
-{
- ::sprintf(_what_msg, "jexception ");
- if (additional_info)
- {
- ::strncpy(_additional_info, additional_info, MAX_MSG_SIZE - 1);
- _additional_info[MAX_MSG_SIZE - 1] = '\0';
- ::strncat(_what_msg, _additional_info, CATLEN(_what_msg));
- }
- else
- *_additional_info = '\0';
- *_throwing_class = '\0';
- *_throwing_fn = '\0';
-}
+ _err_code(0),
+ _additional_info(additional_info)
+{}
+jexception::jexception(const std::string& additional_info) throw ():
+ std::exception(),
+ _err_code(0),
+ _additional_info(additional_info)
+{}
+
jexception::jexception(const u_int32_t err_code, const char* additional_info) throw ():
std::exception(),
- _err_code(err_code)
-{
- ::sprintf(_what_msg, "jexception 0x%04X ", err_code);
- ::strncat(_what_msg, jerrno::err_msg(err_code), CATLEN(_what_msg));
- if (additional_info)
- {
- ::strncpy(_additional_info, additional_info, MAX_MSG_SIZE - 1);
- _additional_info[MAX_MSG_SIZE - 1] = '\0';
- ::strncat(_what_msg, " (", CATLEN(_what_msg));
- ::strncat(_what_msg, _additional_info, CATLEN(_what_msg));
- ::strncat(_what_msg, ")", CATLEN(_what_msg));
- }
- else
- *_additional_info = '\0';
- *_throwing_class = '\0';
- *_throwing_fn = '\0';
-}
+ _err_code(err_code),
+ _additional_info(additional_info)
+{}
+jexception::jexception(const u_int32_t err_code, const std::string& additional_info) throw ():
+ std::exception(),
+ _err_code(err_code),
+ _additional_info(additional_info)
+{}
+
jexception::jexception(const u_int32_t err_code, const char* throwing_class,
const char* throwing_fn) throw ():
std::exception(),
- _err_code(err_code)
-{
- ::sprintf(_what_msg, "jexception 0x%04X ", err_code);
- *_additional_info = '\0';
- if (throwing_class)
- {
- ::strncpy(_throwing_class, throwing_class, MAX_THROWING_SIZE - 1);
- _throwing_class[MAX_THROWING_SIZE - 1] = '\0';
- ::strncat(_what_msg, _throwing_class, CATLEN(_what_msg));
- if (throwing_fn)
- ::strncat(_what_msg, "::", CATLEN(_what_msg));
- else
- ::strncat(_what_msg, " ", CATLEN(_what_msg));
- }
- else
- *_throwing_class = '\0';
- if (throwing_fn)
- {
- ::strncpy(_throwing_fn, throwing_fn, MAX_THROWING_SIZE - 1);
- _throwing_fn[MAX_THROWING_SIZE - 1] = '\0';
- ::strncat(_what_msg, _throwing_fn, CATLEN(_what_msg));
- ::strncat(_what_msg, "() ", CATLEN(_what_msg));
- }
- else
- *_throwing_fn = '\0';
- if (throwing_class || throwing_fn)
- ::strncat(_what_msg, "threw ", CATLEN(_what_msg));
- ::strncat(_what_msg, jerrno::err_msg(err_code), CATLEN(_what_msg));
-}
+ _err_code(err_code),
+ _throwing_class(throwing_class),
+ _throwing_fn(throwing_fn)
+{}
+jexception::jexception(const u_int32_t err_code, const std::string& throwing_class,
+ const std::string& throwing_fn) throw ():
+ std::exception(),
+ _err_code(err_code),
+ _throwing_class(throwing_class),
+ _throwing_fn(throwing_fn)
+{}
+
jexception::jexception(const u_int32_t err_code, const char* additional_info,
const char* throwing_class, const char* throwing_fn) throw ():
std::exception(),
- _err_code(err_code)
-{
- ::sprintf(_what_msg, "jexception 0x%04X ", err_code);
- if (throwing_class)
- {
- ::strncpy(_throwing_class, throwing_class, MAX_THROWING_SIZE - 1);
- _throwing_class[MAX_THROWING_SIZE - 1] = '\0';
- ::strncat(_what_msg, _throwing_class, CATLEN(_what_msg));
- if (throwing_fn)
- ::strncat(_what_msg, "::", CATLEN(_what_msg));
- else
- ::strncat(_what_msg, " ", CATLEN(_what_msg));
- }
- else
- *_throwing_class = '\0';
- if (throwing_fn)
- {
- ::strncpy(_throwing_fn, throwing_fn, MAX_THROWING_SIZE - 1);
- _throwing_fn[MAX_THROWING_SIZE - 1] = '\0';
- ::strncat(_what_msg, _throwing_fn, CATLEN(_what_msg));
- ::strncat(_what_msg, "() ", CATLEN(_what_msg));
- }
- else
- *_throwing_fn = '\0';
- if (throwing_class || throwing_fn)
- ::strncat(_what_msg, "threw ", CATLEN(_what_msg));
- ::strncat(_what_msg, jerrno::err_msg(err_code), CATLEN(_what_msg));
- if (additional_info)
- {
- ::strncpy(_additional_info, additional_info, MAX_MSG_SIZE - 1);
- _additional_info[MAX_MSG_SIZE - 1] = '\0';
- ::strncat(_what_msg, " (", CATLEN(_what_msg));
- ::strncat(_what_msg, _additional_info, CATLEN(_what_msg));
- ::strncat(_what_msg, ")", CATLEN(_what_msg));
- }
- else
- *_additional_info = '\0';
-}
+ _err_code(err_code),
+ _additional_info(additional_info),
+ _throwing_class(throwing_class),
+ _throwing_fn(throwing_fn)
+{}
+jexception::jexception(const u_int32_t err_code, const std::string& additional_info,
+ const std::string& throwing_class, const std::string& throwing_fn) throw ():
+ std::exception(),
+ _err_code(err_code),
+ _additional_info(additional_info),
+ _throwing_class(throwing_class),
+ _throwing_fn(throwing_fn)
+{}
+
jexception::~jexception() throw ()
{}
const char*
jexception::what() const throw ()
{
- return _what_msg;
+ const bool ai = !_additional_info.empty();
+ const bool tc = !_throwing_class.empty();
+ const bool tf = !_throwing_fn.empty();
+ std::ostringstream oss;
+ oss << "jexception 0x" << std::hex << std::setfill('0') << std::setw(4) << _err_code << " ";
+ if (tc)
+ {
+ oss << _throwing_class;
+ if (tf)
+ oss << "::";
+ else
+ oss << " ";
+ }
+ if (tf)
+ oss << _throwing_class << "() ";
+ if (tc || tf)
+ oss << "threw " << jerrno::err_msg(_err_code);
+ if (ai)
+ oss << " (" << _additional_info << ")";
+ return oss.str().c_str();
}
std::ostream&
Modified: store/trunk/cpp/lib/jrnl/jexception.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jexception.hpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/jexception.hpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -52,20 +52,17 @@
#define MALLOC_CHK(ptr, var, cls, fn) if(ptr == NULL) { \
clean(); \
- std::stringstream ss; \
- ss << var << ": malloc() failed: " << FORMAT_SYSERR(errno); \
- throw jexception(jerrno::JERR__MALLOC, ss.str().c_str(), cls, fn); \
+ std::ostringstream oss; \
+ oss << var << ": malloc() failed: " << FORMAT_SYSERR(errno); \
+ throw jexception(jerrno::JERR__MALLOC, oss.str(), cls, fn); \
}
#define PTHREAD_CHK(err, pfn, cls, fn) if(err != 0) { \
- std::stringstream ss; \
- ss << pfn << " failed: " << FORMAT_SYSERR(err); \
- throw jexception(jerrno::JERR__PTHREAD, ss.str().c_str(), cls, fn); \
+ std::ostringstream oss; \
+ oss << pfn << " failed: " << FORMAT_SYSERR(err); \
+ throw jexception(jerrno::JERR__PTHREAD, oss.str(), cls, fn); \
}
-#define MAX_MSG_SIZE 1024
-#define MAX_THROWING_SIZE 128
-
namespace rhm
{
namespace journal
@@ -78,27 +75,38 @@
{
private:
u_int32_t _err_code;
- char _what_msg[MAX_MSG_SIZE];
- char _additional_info[MAX_MSG_SIZE];
- char _throwing_class[MAX_THROWING_SIZE];
- char _throwing_fn[MAX_THROWING_SIZE];
+ std::string _additional_info;
+ std::string _throwing_class;
+ std::string _throwing_fn;
public:
jexception() throw ();
+
jexception(const u_int32_t err_code) throw ();
+
jexception(const char* additional_info) throw ();
+ jexception(const std::string& additional_info) throw ();
+
jexception(const u_int32_t err_code, const char* additional_info) throw ();
+ jexception(const u_int32_t err_code, const std::string& additional_info) throw ();
+
jexception(const u_int32_t err_code, const char* throwing_class, const char* throwing_fn)
throw ();
+ jexception(const u_int32_t err_code, const std::string& throwing_class,
+ const std::string& throwing_fn) throw ();
+
jexception(const u_int32_t err_code, const char* additional_info,
const char* throwing_class, const char* throwing_fn) throw ();
+ jexception(const u_int32_t err_code, const std::string& additional_info,
+ const std::string& throwing_class, const std::string& throwing_fn) throw ();
+
virtual ~jexception() throw ();
virtual const char* what() const throw (); // override std::exception::what()
inline const u_int32_t err_code() const throw () { return _err_code; }
- inline const char* additional_info() const throw () { return _additional_info; }
- inline const char* throwing_class() const throw () { return _throwing_class; }
- inline const char* throwing_fn() const throw () { return _throwing_fn; }
+ inline const std::string additional_info() const throw () { return _additional_info; }
+ inline const std::string throwing_class() const throw () { return _throwing_class; }
+ inline const std::string throwing_fn() const throw () { return _throwing_fn; }
friend std::ostream& operator<<(std::ostream& os, const jexception& je);
friend std::ostream& operator<<(std::ostream& os, const jexception* jePtr);
Modified: store/trunk/cpp/lib/jrnl/jinf.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jinf.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/jinf.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -94,63 +94,63 @@
jinf::validate()
{
bool err = false;
- std::stringstream ss;
+ std::ostringstream oss;
if (_jver != RHM_JDAT_VERSION)
{
- ss << "RHM_JDAT_VERSION mismatch: " << _jver;
- ss << "; required=" << RHM_JDAT_VERSION << std::endl;
+ oss << "RHM_JDAT_VERSION mismatch: " << _jver;
+ oss << "; required=" << RHM_JDAT_VERSION << std::endl;
err = true;
}
if (_num_jfiles < JRNL_MIN_NUM_FILES)
{
- ss << "Number of journal files too small: found=" << _num_jfiles;
- ss << "; minimum=" << JRNL_MIN_NUM_FILES << std::endl;
+ oss << "Number of journal files too small: found=" << _num_jfiles;
+ oss << "; minimum=" << JRNL_MIN_NUM_FILES << std::endl;
err = true;
}
if (_jfsize_sblks < JRNL_MIN_FILE_SIZE)
{
- ss << "Journal file size too small: found=" << _jfsize_sblks;
- ss << "; minimum=" << JRNL_MIN_FILE_SIZE << " (sblks)" << std::endl;
+ oss << "Journal file size too small: found=" << _jfsize_sblks;
+ oss << "; minimum=" << JRNL_MIN_FILE_SIZE << " (sblks)" << std::endl;
err = true;
}
if (_sblk_size_dblks != JRNL_SBLK_SIZE)
{
- ss << "JRNL_SBLK_SIZE mismatch: " << _sblk_size_dblks;
- ss << "; required=" << JRNL_SBLK_SIZE << std::endl;
+ oss << "JRNL_SBLK_SIZE mismatch: " << _sblk_size_dblks;
+ oss << "; required=" << JRNL_SBLK_SIZE << std::endl;
err = true;
}
if (_dblk_size != JRNL_DBLK_SIZE)
{
- ss << "JRNL_DBLK_SIZE mismatch: " << _dblk_size;
- ss << "; required=" << JRNL_DBLK_SIZE << std::endl;
+ oss << "JRNL_DBLK_SIZE mismatch: " << _dblk_size;
+ oss << "; required=" << JRNL_DBLK_SIZE << std::endl;
err = true;
}
if (_wmgr_page_size_dblks != JRNL_WMGR_PAGE_SIZE)
{
- ss << "JRNL_WMGR_PAGE_SIZE mismatch: " << _wmgr_page_size_dblks;
- ss << "; required=" << JRNL_WMGR_PAGE_SIZE << std::endl;
+ oss << "JRNL_WMGR_PAGE_SIZE mismatch: " << _wmgr_page_size_dblks;
+ oss << "; required=" << JRNL_WMGR_PAGE_SIZE << std::endl;
err = true;
}
if (_wmgr_num_pages != JRNL_WMGR_PAGES)
{
- ss << "JRNL_WMGR_PAGES mismatch: " << _wmgr_num_pages;
- ss << "; required=" << JRNL_WMGR_PAGES << std::endl;
+ oss << "JRNL_WMGR_PAGES mismatch: " << _wmgr_num_pages;
+ oss << "; required=" << JRNL_WMGR_PAGES << std::endl;
err = true;
}
if (_rmgr_page_size_dblks != JRNL_RMGR_PAGE_SIZE)
{
- ss << "JRNL_RMGR_PAGE_SIZE mismatch: " << _rmgr_page_size_dblks;
- ss << "; required=" << JRNL_RMGR_PAGE_SIZE << std::endl;
+ oss << "JRNL_RMGR_PAGE_SIZE mismatch: " << _rmgr_page_size_dblks;
+ oss << "; required=" << JRNL_RMGR_PAGE_SIZE << std::endl;
err = true;
}
if (_rmgr_num_pages != JRNL_RMGR_PAGES)
{
- ss << "JRNL_RMGR_PAGES mismatch: " << _rmgr_num_pages;
- ss << "; required=" << JRNL_RMGR_PAGES << std::endl;
+ oss << "JRNL_RMGR_PAGES mismatch: " << _rmgr_num_pages;
+ oss << "; required=" << JRNL_RMGR_PAGES << std::endl;
err = true;
}
if (err)
- throw jexception(jerrno::JERR_JINF_CVALIDFAIL, ss.str().c_str(), "jinf", "validate");
+ throw jexception(jerrno::JERR_JINF_CVALIDFAIL, oss.str(), "jinf", "validate");
_valid_flag = true;
}
@@ -165,13 +165,13 @@
validate();
for (u_int16_t fnum=0; fnum < _num_jfiles; fnum++)
{
- std::stringstream ss;
- ss << _jdir << "/" << _base_filename << ".";
- ss << std::setw(4) << std::setfill('0') << std::hex << fnum;
- ss << "." << JRNL_DATA_EXTENSION;
- std::ifstream jifs(ss.str().c_str());
+ std::ostringstream oss;
+ oss << _jdir << "/" << _base_filename << ".";
+ oss << std::setw(4) << std::setfill('0') << std::hex << fnum;
+ oss << "." << JRNL_DATA_EXTENSION;
+ std::ifstream jifs(oss.str().c_str());
if (!jifs.good())
- throw jexception(jerrno::JERR__FILEIO, ss.str().c_str(), "jinf", "analyze");
+ throw jexception(jerrno::JERR__FILEIO, oss.str(), "jinf", "analyze");
file_hdr fhdr;
jifs.read((char*)&fhdr, sizeof(fhdr));
if (fhdr._magic != RHM_JDAT_FILE_MAGIC)
@@ -199,11 +199,11 @@
void
jinf::write()
{
- std::stringstream fn;
- fn << _jdir << "/" << _base_filename << "." << JRNL_INFO_EXTENSION;
- std::ofstream of(fn.str().c_str(), std::ofstream::out | std::ofstream::trunc);
+ std::ostringstream oss;
+ oss << _jdir << "/" << _base_filename << "." << JRNL_INFO_EXTENSION;
+ std::ofstream of(oss.str().c_str(), std::ofstream::out | std::ofstream::trunc);
if (!of.good())
- throw jexception(jerrno::JERR__FILEIO, fn.str().c_str(), "jcntl", "write_infofile");
+ throw jexception(jerrno::JERR__FILEIO, oss.str(), "jcntl", "write_infofile");
of << xml_str();
of.close();
}
@@ -227,64 +227,65 @@
const std::string
jinf::to_string() const
{
- std::stringstream ss;
- ss << std::setfill('0');
- ss << "Journal ID \"" << _jid << "\" initialized " << (_tm_ptr->tm_year + 1900) << "/";
- ss << std::setw(2) << (_tm_ptr->tm_mon + 1) << "/" << std::setw(2) << _tm_ptr->tm_mday << " ";
- ss << std::setw(2) << _tm_ptr->tm_hour << ":" << std::setw(2) << _tm_ptr->tm_min << ":";
- ss << std::setw(2) << _tm_ptr->tm_sec << "." << std::setw(9) << _ts.tv_nsec << ":" << std::endl;
- ss << " Journal directory: \"" << _jdir << "\"" << std::endl;
- ss << " Journal base filename: \"" << _base_filename << "\"" << std::endl;
- ss << " Journal version: " << (unsigned)_jver << std::endl;
- ss << " Number of journal files: " << _num_jfiles << std::endl;
- ss << " Journal file size: " << _jfsize_sblks << " sblks" << std::endl;
- ss << " Softblock size (JRNL_SBLK_SIZE): " << _sblk_size_dblks << " dblks" << std::endl;
- ss << " Datablock size (JRNL_DBLK_SIZE): " << _dblk_size << " bytes" << std::endl;
- ss << " Write page size (JRNL_WMGR_PAGE_SIZE): " << _wmgr_page_size_dblks << " dblks" <<
+ std::ostringstream oss;
+ oss << std::setfill('0');
+ oss << "Journal ID \"" << _jid << "\" initialized " << (_tm_ptr->tm_year + 1900) << "/";
+ oss << std::setw(2) << (_tm_ptr->tm_mon + 1) << "/" << std::setw(2) << _tm_ptr->tm_mday << " ";
+ oss << std::setw(2) << _tm_ptr->tm_hour << ":" << std::setw(2) << _tm_ptr->tm_min << ":";
+ oss << std::setw(2) << _tm_ptr->tm_sec << "." << std::setw(9) << _ts.tv_nsec << ":" <<
std::endl;
- ss << " Number of write pages (JRNL_WMGR_PAGES): " << _wmgr_num_pages << std::endl;
- ss << " Read page size (JRNL_RMGR_PAGE_SIZE): " << _rmgr_page_size_dblks << " dblks" <<
+ oss << " Journal directory: \"" << _jdir << "\"" << std::endl;
+ oss << " Journal base filename: \"" << _base_filename << "\"" << std::endl;
+ oss << " Journal version: " << (unsigned)_jver << std::endl;
+ oss << " Number of journal files: " << _num_jfiles << std::endl;
+ oss << " Journal file size: " << _jfsize_sblks << " sblks" << std::endl;
+ oss << " Softblock size (JRNL_SBLK_SIZE): " << _sblk_size_dblks << " dblks" << std::endl;
+ oss << " Datablock size (JRNL_DBLK_SIZE): " << _dblk_size << " bytes" << std::endl;
+ oss << " Write page size (JRNL_WMGR_PAGE_SIZE): " << _wmgr_page_size_dblks << " dblks" <<
std::endl;
- ss << " Number of read pages (JRNL_RMGR_PAGES): " << _rmgr_num_pages << std::endl;
- return ss.str();
+ oss << " Number of write pages (JRNL_WMGR_PAGES): " << _wmgr_num_pages << std::endl;
+ oss << " Read page size (JRNL_RMGR_PAGE_SIZE): " << _rmgr_page_size_dblks << " dblks" <<
+ std::endl;
+ oss << " Number of read pages (JRNL_RMGR_PAGES): " << _rmgr_num_pages << std::endl;
+ return oss.str();
}
const std::string
jinf::xml_str() const
{
- std::stringstream ss;
+ std::ostringstream oss;
// TODO: I'm sure a more elegant way can be found to do this, but direct and simple
// seems like a good start!
- ss << std::setfill('0');
- ss << "<?xml version=\"1.0\" ?>" << std::endl;
- ss << "<jrnl>" << std::endl;
- ss << " <journal_version value=\"" << (unsigned)_jver << "\" />" << std::endl;
- ss << " <journal_id>" << std::endl;
- ss << " <id_string value=\"" << _jid << "\" />" << std::endl;
- ss << " <directory value=\"" << _jdir << "\" />" << std::endl;
- ss << " <base_filename value=\"" << _base_filename << "\" />" << std::endl;
- ss << " </journal_id>" << std::endl;
- ss << " <creation_time>" << std::endl;
- ss << " <seconds value=\"" << _ts.tv_sec << "\" />" << std::endl;
- ss << " <nanoseconds value=\"" << _ts.tv_nsec << "\" />" << std::endl;
- ss << " <string vlaue=\"" << (_tm_ptr->tm_year + 1900) << "/";
- ss << std::setw(2) << (_tm_ptr->tm_mon + 1) << "/" << std::setw(2) << _tm_ptr->tm_mday << " ";
- ss << std::setw(2) << _tm_ptr->tm_hour << ":" << std::setw(2) << _tm_ptr->tm_min << ":";
- ss << std::setw(2) << _tm_ptr->tm_sec << "." << std::setw(9) << _ts.tv_nsec;
- ss << "\" />" << std::endl;
- ss << " </creation_time>" << std::endl;
- ss << " <journal_file_geometry>" << std::endl;
- ss << " <number_jrnl_files value=\"" << _num_jfiles << "\" />" << std::endl;
- ss << " <jrnl_file_size_sblks value=\"" << _jfsize_sblks << "\" />" << std::endl;
- ss << " <JRNL_SBLK_SIZE value=\"" << _sblk_size_dblks << "\" />" << std::endl;
- ss << " <JRNL_DBLK_SIZE value=\"" << _dblk_size << "\" />" << std::endl;
- ss << " <JRNL_WMGR_PAGE_SIZE value=\"" << _wmgr_page_size_dblks << "\" />" << std::endl;
- ss << " <JRNL_WMGR_PAGES value=\"" << _wmgr_num_pages << "\" />" << std::endl;
- ss << " <JRNL_RMGR_PAGE_SIZE value=\"" << _rmgr_page_size_dblks << "\" />" << std::endl;
- ss << " <JRNL_RMGR_PAGES value=\"" << _rmgr_num_pages << "\" />" << std::endl;
- ss << " </journal_file_geometry>" << std::endl;
- ss << "</jrnl>" << std::endl;
- return ss.str();
+ oss << std::setfill('0');
+ oss << "<?xml version=\"1.0\" ?>" << std::endl;
+ oss << "<jrnl>" << std::endl;
+ oss << " <journal_version value=\"" << (unsigned)_jver << "\" />" << std::endl;
+ oss << " <journal_id>" << std::endl;
+ oss << " <id_string value=\"" << _jid << "\" />" << std::endl;
+ oss << " <directory value=\"" << _jdir << "\" />" << std::endl;
+ oss << " <base_filename value=\"" << _base_filename << "\" />" << std::endl;
+ oss << " </journal_id>" << std::endl;
+ oss << " <creation_time>" << std::endl;
+ oss << " <seconds value=\"" << _ts.tv_sec << "\" />" << std::endl;
+ oss << " <nanoseconds value=\"" << _ts.tv_nsec << "\" />" << std::endl;
+ oss << " <string vlaue=\"" << (_tm_ptr->tm_year + 1900) << "/";
+ oss << std::setw(2) << (_tm_ptr->tm_mon + 1) << "/" << std::setw(2) << _tm_ptr->tm_mday << " ";
+ oss << std::setw(2) << _tm_ptr->tm_hour << ":" << std::setw(2) << _tm_ptr->tm_min << ":";
+ oss << std::setw(2) << _tm_ptr->tm_sec << "." << std::setw(9) << _ts.tv_nsec;
+ oss << "\" />" << std::endl;
+ oss << " </creation_time>" << std::endl;
+ oss << " <journal_file_geometry>" << std::endl;
+ oss << " <number_jrnl_files value=\"" << _num_jfiles << "\" />" << std::endl;
+ oss << " <jrnl_file_size_sblks value=\"" << _jfsize_sblks << "\" />" << std::endl;
+ oss << " <JRNL_SBLK_SIZE value=\"" << _sblk_size_dblks << "\" />" << std::endl;
+ oss << " <JRNL_DBLK_SIZE value=\"" << _dblk_size << "\" />" << std::endl;
+ oss << " <JRNL_WMGR_PAGE_SIZE value=\"" << _wmgr_page_size_dblks << "\" />" << std::endl;
+ oss << " <JRNL_WMGR_PAGES value=\"" << _wmgr_num_pages << "\" />" << std::endl;
+ oss << " <JRNL_RMGR_PAGE_SIZE value=\"" << _rmgr_page_size_dblks << "\" />" << std::endl;
+ oss << " <JRNL_RMGR_PAGES value=\"" << _rmgr_num_pages << "\" />" << std::endl;
+ oss << " </journal_file_geometry>" << std::endl;
+ oss << "</jrnl>" << std::endl;
+ return oss.str();
}
void
Modified: store/trunk/cpp/lib/jrnl/jrec.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jrec.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/jrec.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -51,19 +51,19 @@
{
if (hdr._magic == 0)
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "enq magic NULL: rid=0x" << hdr._rid;
- throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "jrec", "chk_hdr");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "enq magic NULL: rid=0x" << hdr._rid;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "jrec", "chk_hdr");
}
if (hdr._version != RHM_JDAT_VERSION)
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "version: rid=0x" << hdr._rid;
- ss << ": expected=0x" << std::setw(2) << (int)RHM_JDAT_VERSION;
- ss << " read=0x" << std::setw(2) << (int)hdr._version;
- throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "jrec", "chk_hdr");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "version: rid=0x" << hdr._rid;
+ oss << ": expected=0x" << std::setw(2) << (int)RHM_JDAT_VERSION;
+ oss << " read=0x" << std::setw(2) << (int)hdr._version;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "jrec", "chk_hdr");
}
#if defined (JRNL_LITTLE_ENDIAN)
u_int8_t endian_flag = RHM_LENDIAN_FLAG;
@@ -72,12 +72,12 @@
#endif
if (hdr._eflag != endian_flag)
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "endian_flag: rid=" << hdr._rid;
- ss << ": expected=0x" << std::setw(2) << (int)endian_flag;
- ss << " read=0x" << std::setw(2) << (int)hdr._eflag;
- throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "jrec", "chk_hdr");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "endian_flag: rid=" << hdr._rid;
+ oss << ": expected=0x" << std::setw(2) << (int)endian_flag;
+ oss << " read=0x" << std::setw(2) << (int)hdr._eflag;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "jrec", "chk_hdr");
}
}
@@ -86,11 +86,11 @@
{
if (hdr._rid != rid)
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "rid mismatch: expected=0x" << rid;
- ss << " read=0x" << hdr._rid;
- throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "jrec", "chk_hdr");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "rid mismatch: expected=0x" << rid;
+ oss << " read=0x" << hdr._rid;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "jrec", "chk_hdr");
}
}
@@ -99,20 +99,20 @@
{
if (tail._xmagic != ~hdr._magic)
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "magic: rid=0x" << hdr._rid;
- ss << ": expected=0x" << ~hdr._magic;
- ss << " read=0x" << tail._xmagic;
- throw jexception(jerrno::JERR_JREC_BADRECTAIL, ss.str().c_str(), "jrec", "chk_tail");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "magic: rid=0x" << hdr._rid;
+ oss << ": expected=0x" << ~hdr._magic;
+ oss << " read=0x" << tail._xmagic;
+ throw jexception(jerrno::JERR_JREC_BADRECTAIL, oss.str(), "jrec", "chk_tail");
}
if (tail._rid != hdr._rid)
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "rid: rid=0x" << hdr._rid;
- ss << ": read=0x" << tail._rid;
- throw jexception(jerrno::JERR_JREC_BADRECTAIL, ss.str().c_str(), "jrec", "chk_tail");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "rid: rid=0x" << hdr._rid;
+ oss << ": read=0x" << tail._rid;
+ throw jexception(jerrno::JERR_JREC_BADRECTAIL, oss.str(), "jrec", "chk_tail");
}
}
Modified: store/trunk/cpp/lib/jrnl/nlfh.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/nlfh.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/nlfh.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -95,13 +95,12 @@
nlfh::initialize(const std::string& fbasename, const u_int16_t fid,
const u_int32_t jfsize_sblks, const rcvdat* const ro)
{
- std::stringstream ss;
-
_fid = fid;
- ss << fbasename << ".";
- ss << std::setw(4) << std::setfill('0') << std::hex << fid;
- ss << "." << JRNL_DATA_EXTENSION;
- _fname = ss.str();
+ std::ostringstream oss;
+ oss << fbasename << ".";
+ oss << std::setw(4) << std::setfill('0') << std::hex << fid;
+ oss << "." << JRNL_DATA_EXTENSION;
+ _fname = oss.str();
#ifdef RHM_JOWRITE
// In test mode, only create file if it does not exist
@@ -144,9 +143,10 @@
void* nullbuf = NULL;
if (::posix_memalign(&nullbuf, sblksize, writesize))
{
- ss << ": posix_memalign() failed: size=" << writesize << " blk_size=" << sblksize;
- ss << " errno=" << errno;
- throw jexception(jerrno::JERR__MALLOC, ss.str().c_str(), "nlfh", "initialize");
+ std::ostringstream oss;
+ oss << ": posix_memalign() failed: size=" << writesize << " blk_size=" << sblksize;
+ oss << " errno=" << errno;
+ throw jexception(jerrno::JERR__MALLOC, oss.str(), "nlfh", "initialize");
}
::memset(nullbuf, 0, writesize);
@@ -154,9 +154,10 @@
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // 0644 -rw-r--r--
if (fh < 0)
{
- ss << ": open() failed:" << "\" errno=" << errno;
+ std::ostringstream oss;
+ oss << ": open() failed:" << "\" errno=" << errno;
::free(nullbuf);
- throw jexception(jerrno::JERR_NLFH_OPENWR, ss.str().c_str(), "nlfh", "initialize");
+ throw jexception(jerrno::JERR_NLFH_OPENWR, oss.str(), "nlfh", "initialize");
}
while (nsblks > 0)
@@ -165,11 +166,11 @@
JRNL_WMGR_PAGE_SIZE : nsblks;
if (::write(fh, (void*)nullbuf, this_write_sblks * sblksize) == -1)
{
- std::stringstream ss;
- ss << ": wr_size=" << (this_write_sblks * sblksize) << " errno=" << errno;
+ std::ostringstream oss;
+ oss << ": wr_size=" << (this_write_sblks * sblksize) << " errno=" << errno;
::close(fh);
::free(nullbuf);
- throw jexception(jerrno::JERR_NLFH_WRITE, ss.str().c_str(), "nlfh",
+ throw jexception(jerrno::JERR_NLFH_WRITE, oss.str(), "nlfh",
"initialize");
}
nsblks -= this_write_sblks;
@@ -179,8 +180,9 @@
::free(nullbuf);
if (::close(fh))
{
- ss << ": errno=" << errno;
- throw jexception(jerrno::JERR_NLFH_CLOSE, ss.str().c_str(), "nlfh", "initialize");
+ std::ostringstream oss;
+ oss << ": errno=" << errno;
+ throw jexception(jerrno::JERR_NLFH_CLOSE, oss.str(), "nlfh", "initialize");
}
}
#ifdef RHM_JOWRITE
@@ -248,9 +250,9 @@
{
if (_rec_enqcnt < s)
{
- std::stringstream ss;
- ss << "_rec_enqcnt=" << _rec_enqcnt << " decr=" << s;
- throw jexception(jerrno::JERR__UNDERFLOW, ss.str().c_str(), "nlfh", "subtr_enqcnt");
+ std::ostringstream oss;
+ oss << "_rec_enqcnt=" << _rec_enqcnt << " decr=" << s;
+ throw jexception(jerrno::JERR__UNDERFLOW, oss.str(), "nlfh", "subtr_enqcnt");
}
_rec_enqcnt -= s;
return _rec_enqcnt;
@@ -261,11 +263,10 @@
{
if (_rd_subm_cnt_dblks + a > _wr_subm_cnt_dblks)
{
- std::stringstream ss;
- ss << "_rd_subm_cnt_dblks=" << _rd_subm_cnt_dblks << " incr=" << a;
- ss << " _wr_subm_cnt_dblks=" << _wr_subm_cnt_dblks;
- throw jexception(jerrno::JERR_NFLH_RDOFFSOVFL, ss.str().c_str(), "nlfh",
- "add_rd_subm_cnt_dblks");
+ std::ostringstream oss;
+ oss << "_rd_subm_cnt_dblks=" << _rd_subm_cnt_dblks << " incr=" << a;
+ oss << " _wr_subm_cnt_dblks=" << _wr_subm_cnt_dblks;
+ throw jexception(jerrno::JERR_NFLH_RDOFFSOVFL, oss.str(), "nlfh", "add_rd_subm_cnt_dblks");
}
_rd_subm_cnt_dblks += a;
return _rd_subm_cnt_dblks;
@@ -276,10 +277,10 @@
{
if (_rd_cmpl_cnt_dblks + a > _rd_subm_cnt_dblks)
{
- std::stringstream ss;
- ss << "_rd_cmpl_cnt_dblks=" << _rd_cmpl_cnt_dblks << " incr=" << a;
- ss << " _rd_subm_cnt_dblks=" << _rd_subm_cnt_dblks;
- throw jexception(jerrno::JERR_NFLH_CMPLOFFSOVFL, ss.str().c_str(), "nlfh",
+ std::ostringstream oss;
+ oss << "_rd_cmpl_cnt_dblks=" << _rd_cmpl_cnt_dblks << " incr=" << a;
+ oss << " _rd_subm_cnt_dblks=" << _rd_subm_cnt_dblks;
+ throw jexception(jerrno::JERR_NFLH_CMPLOFFSOVFL, oss.str(), "nlfh",
"add_rd_cmpl_cnt_dblks");
}
_rd_cmpl_cnt_dblks += a;
@@ -291,10 +292,10 @@
{
if (_wr_subm_cnt_dblks + a > _ffull_dblks) // Allow for file header
{
- std::stringstream ss;
- ss << "_wr_subm_cnt_dblks=" << _wr_subm_cnt_dblks << " incr=" << a;
- ss << " fsize=" << _ffull_dblks << " dblks";
- throw jexception(jerrno::JERR_NLFH_FILEOFFSOVFL, ss.str().c_str(), "nlfh",
+ std::ostringstream oss;
+ oss << "_wr_subm_cnt_dblks=" << _wr_subm_cnt_dblks << " incr=" << a;
+ oss << " fsize=" << _ffull_dblks << " dblks";
+ throw jexception(jerrno::JERR_NLFH_FILEOFFSOVFL, oss.str(), "nlfh",
"add_wr_subm_cnt_dblks");
}
_wr_subm_cnt_dblks += a;
@@ -306,10 +307,10 @@
{
if (_wr_cmpl_cnt_dblks + a > _wr_subm_cnt_dblks)
{
- std::stringstream ss;
- ss << "_wr_cmpl_cnt_dblks=" << _wr_cmpl_cnt_dblks << " incr=" << a;
- ss << " _wr_subm_cnt_dblks=" << _wr_subm_cnt_dblks;
- throw jexception(jerrno::JERR_NFLH_CMPLOFFSOVFL, ss.str().c_str(), "nlfh",
+ std::ostringstream oss;
+ oss << "_wr_cmpl_cnt_dblks=" << _wr_cmpl_cnt_dblks << " incr=" << a;
+ oss << " _wr_subm_cnt_dblks=" << _wr_subm_cnt_dblks;
+ throw jexception(jerrno::JERR_NFLH_CMPLOFFSOVFL, oss.str(), "nlfh",
"add_wr_cmpl_cnt_dblks");
}
_wr_cmpl_cnt_dblks += a;
@@ -320,10 +321,10 @@
const std::string&
nlfh::status_str(std::string& s) const
{
- std::stringstream ss;
- ss << "fid=" << _fid << " ws=" << _wr_subm_cnt_dblks << " wc=" << _wr_cmpl_cnt_dblks;
- ss << " rs=" << _rd_subm_cnt_dblks << " rc=" << _rd_cmpl_cnt_dblks;
- s.assign(ss.str());
+ std::ostringstream oss;
+ oss << "fid=" << _fid << " ws=" << _wr_subm_cnt_dblks << " wc=" << _wr_cmpl_cnt_dblks;
+ oss << " rs=" << _rd_subm_cnt_dblks << " rc=" << _rd_cmpl_cnt_dblks;
+ s.assign(oss.str());
return s;
}
@@ -335,17 +336,17 @@
_rd_fh = ::open(_fname.c_str(), O_RDONLY | O_DIRECT);
if (_rd_fh < 0)
{
- std::stringstream ss;
- ss << "file=\"" << _fname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_NLFH_OPENRD, ss.str().c_str(), "nlfh", "open");
+ std::ostringstream oss;
+ oss << "file=\"" << _fname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_NLFH_OPENRD, oss.str(), "nlfh", "open");
}
_wr_fh = ::open(_fname.c_str(), O_WRONLY | O_DIRECT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // 0644 -rw-r--r--
if (_wr_fh < 0)
{
- std::stringstream ss;
- ss << "file=\"" << _fname << "\" errno=" << errno;
- throw jexception(jerrno::JERR_NLFH_OPENWR, ss.str().c_str(), "nlfh", "open");
+ std::ostringstream oss;
+ oss << "file=\"" << _fname << "\" errno=" << errno;
+ throw jexception(jerrno::JERR_NLFH_OPENWR, oss.str(), "nlfh", "open");
}
}
Modified: store/trunk/cpp/lib/jrnl/pmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/pmgr.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/pmgr.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -131,8 +131,6 @@
void
pmgr::initialize()
{
- std::stringstream ss;
-
// As static use of this class keeps old values around, clean up first...
_pg_index = 0;
_pg_cntr = 0;
@@ -145,9 +143,10 @@
if (::posix_memalign(&_page_base_ptr, _sblksize, pagesize))
{
clean();
- ss << "posix_memalign(): blksize=" << _sblksize << " size=" << pagesize;
- ss << " errno=" << errno;
- throw jexception(jerrno::JERR__MALLOC, ss.str().c_str(), "pmgr", "initialize");
+ std::ostringstream oss;
+ oss << "posix_memalign(): blksize=" << _sblksize << " size=" << pagesize;
+ oss << " errno=" << errno;
+ throw jexception(jerrno::JERR__MALLOC, oss.str(), "pmgr", "initialize");
}
// 2. Allocate array of page pointers
_page_ptr_arr = (void**)::malloc(_pages * sizeof(void*));
@@ -182,8 +181,9 @@
// 8. Initialize AIO context
if (int ret = ::io_queue_init(max_aio_evts, &_ioctx))
{
- ss << "io_queue_init() failed: " << strerror(-ret) << " (" << ret << ")";
- throw jexception(jerrno::JERR__AIO, ss.str().c_str(), "pmgr", "initialize");
+ std::ostringstream oss;
+ oss << "io_queue_init() failed: " << strerror(-ret) << " (" << ret << ")";
+ throw jexception(jerrno::JERR__AIO, oss.str(), "pmgr", "initialize");
}
}
Modified: store/trunk/cpp/lib/jrnl/rmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rmgr.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/rmgr.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -156,10 +156,10 @@
consume_filler();
break;
default:
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "Magic=0x" << std::setw(8) << _hdr._magic << std::dec;
- throw jexception(jerrno::JERR_RMGR_UNKNOWNMAGIC, ss.str().c_str(), "rmgr", "get");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "Magic=0x" << std::setw(8) << _hdr._magic << std::dec;
+ throw jexception(jerrno::JERR_RMGR_UNKNOWNMAGIC, oss.str(), "rmgr", "get");
} // switch(_hdr._magic)
} // while */
}
@@ -205,11 +205,10 @@
consume_filler();
break;
default:
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "Magic=0x" << std::setw(8) << _hdr._magic << std::dec;
- throw jexception(jerrno::JERR_RMGR_UNKNOWNMAGIC, ss.str().c_str(), "rmgr",
- "discard");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "Magic=0x" << std::setw(8) << _hdr._magic << std::dec;
+ throw jexception(jerrno::JERR_RMGR_UNKNOWNMAGIC, oss.str(), "rmgr", "discard");
} // switch
} // while */
}
@@ -323,13 +322,13 @@
{
if (_hdr._rid != dtokp->rid())
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "rid=0x" << std::setw(16) << _hdr._rid;
- ss << "; dtok_rid=" << std::setw(16) << dtokp->rid();
- ss << "; dtok_id=0x" << std::setw(8) << dtokp->id();
- throw jexception(jerrno::JERR_RMGR_RIDMISMATCH, ss.str().c_str(),
- "rmgr", "read");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "rid=0x" << std::setw(16) << _hdr._rid;
+ oss << "; dtok_rid=" << std::setw(16) << dtokp->rid();
+ oss << "; dtok_id=0x" << std::setw(8) << dtokp->id();
+ throw jexception(jerrno::JERR_RMGR_RIDMISMATCH, oss.str(), "rmgr",
+ "read");
}
}
else
@@ -340,12 +339,12 @@
// check:
// if (fid != _page_cb_arr[_pg_index]._fid)
// {
-// std::stringstream ss;
-// ss << std::hex << std::setfill('0');
-// ss << "rid=0x" << std::setw(16) << _hdr._rid;
-// ss << "; emap_fid=0x" << std::setw(4) << fid;
-// ss << "; current_fid=" << _rrfc.fid();
-// throw jexception(jerrno::JERR_RMGR_FIDMISMATCH, ss.str().c_str(), "rmgr",
+// std::ostringstream oss;
+// oss << std::hex << std::setfill('0');
+// oss << "rid=0x" << std::setw(16) << _hdr._rid;
+// oss << "; emap_fid=0x" << std::setw(4) << fid;
+// oss << "; current_fid=" << _rrfc.fid();
+// throw jexception(jerrno::JERR_RMGR_FIDMISMATCH, oss.str(), "rmgr",
// "read");
// }
#endif
@@ -373,10 +372,10 @@
consume_filler();
break;
default:
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "Magic=0x" << std::setw(8) << _hdr._magic << std::dec;
- throw jexception(jerrno::JERR_RMGR_UNKNOWNMAGIC, ss.str().c_str(), "rmgr", "read");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "Magic=0x" << std::setw(8) << _hdr._magic << std::dec;
+ throw jexception(jerrno::JERR_RMGR_UNKNOWNMAGIC, oss.str(), "rmgr", "read");
}
}
}
@@ -389,9 +388,9 @@
{
if (ret == -EINTR) // No events
return 0;
- std::stringstream ss;
- ss << "io_getevents() failed: " << strerror(-ret) << " (" << ret << ")";
- throw jexception(jerrno::JERR__AIO, ss.str().c_str(), "rmgr", "get_events");
+ std::ostringstream oss;
+ oss << "io_getevents() failed: " << strerror(-ret) << " (" << ret << ")";
+ throw jexception(jerrno::JERR__AIO, oss.str(), "rmgr", "get_events");
}
u_int32_t tot_data_toks = 0;
@@ -399,9 +398,9 @@
{
if (_aio_evt_rem == 0)
{
- std::stringstream ss;
- ss << "_aio_evt_rem; evt " << (i + 1) << " of " << ret;
- throw jexception(jerrno::JERR__UNDERFLOW, ss.str().c_str(), "rmgr", "get_events");
+ std::ostringstream oss;
+ oss << "_aio_evt_rem; evt " << (i + 1) << " of " << ret;
+ throw jexception(jerrno::JERR__UNDERFLOW, oss.str(), "rmgr", "get_events");
}
_aio_evt_rem--;
iocb* iocbp = _ioevt_arr[i].obj; // This I/O control block (iocb)
@@ -409,13 +408,13 @@
long aioret = (long)_ioevt_arr[i].res;
if (aioret < 0)
{
- std::stringstream ss;
- ss << "AIO read operation failed: " << strerror(-aioret) << " (" << aioret << ")";
- ss << " [pg=" << pcbp->_index << " buf=" << iocbp->u.c.buf;
- ss << " rsize=0x" << std::hex << iocbp->u.c.nbytes;
- ss << " offset=0x" << iocbp->u.c.offset << std::dec;
- ss << " fh=" << iocbp->aio_fildes << "]";
- throw jexception(jerrno::JERR__AIO, ss.str().c_str(), "rmgr", "get_events");
+ std::ostringstream oss;
+ oss << "AIO read operation failed: " << strerror(-aioret) << " (" << aioret << ")";
+ oss << " [pg=" << pcbp->_index << " buf=" << iocbp->u.c.buf;
+ oss << " rsize=0x" << std::hex << iocbp->u.c.nbytes;
+ oss << " offset=0x" << iocbp->u.c.offset << std::dec;
+ oss << " fh=" << iocbp->aio_fildes << "]";
+ throw jexception(jerrno::JERR__AIO, oss.str(), "rmgr", "get_events");
}
// Transfer all data tokens
@@ -473,13 +472,12 @@
{
if (!dtokp->is_readable())
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "dtok_id=0x" << std::setw(8) << dtokp->id();
- ss << "; dtok_rid=0x" << std::setw(16) << dtokp->rid();
- ss << "; dtok_wstate=" << dtokp->wstate_str();
- throw jexception(jerrno::JERR_RMGR_ENQSTATE, ss.str().c_str(), "rmgr",
- "pre_read_check");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "dtok_id=0x" << std::setw(8) << dtokp->id();
+ oss << "; dtok_rid=0x" << std::setw(16) << dtokp->rid();
+ oss << "; dtok_wstate=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_RMGR_ENQSTATE, oss.str(), "rmgr", "pre_read_check");
}
}
@@ -557,9 +555,9 @@
}
else
{
- std::stringstream ss;
- ss << "Record type found = \"" << (char*)&h._magic << "\"";
- throw jexception(jerrno::JERR_RMGR_BADRECTYPE, ss.str().c_str(), "rmgr", "consume_xid_rec");
+ std::ostringstream oss;
+ oss << "Record type found = \"" << (char*)&h._magic << "\"";
+ throw jexception(jerrno::JERR_RMGR_BADRECTYPE, oss.str(), "rmgr", "consume_xid_rec");
}
dtokp->set_dblocks_read(0);
skip(dtokp);
Modified: store/trunk/cpp/lib/jrnl/txn_map.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_map.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/txn_map.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -90,9 +90,9 @@
pthread_mutex_unlock(&_mutex);
if (itr == _map.end()) // not found in map
{
- std::stringstream ss;
- ss << std::hex << "xid=\"" << xid << "\"";
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "txn_map", "get_tdata_list");
+ std::ostringstream oss;
+ oss << std::hex << "xid=\"" << xid << "\"";
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "txn_map", "get_tdata_list");
}
return itr->second;
}
@@ -105,9 +105,9 @@
if (itr == _map.end()) // not found in map
{
pthread_mutex_unlock(&_mutex);
- std::stringstream ss;
- ss << std::hex << "xid=\"" << xid << "\"";
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "txn_map",
+ std::ostringstream oss;
+ oss << std::hex << "xid=\"" << xid << "\"";
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "txn_map",
"get_remove_tdata_list");
}
txn_data_list list = itr->second;
@@ -135,9 +135,9 @@
pthread_mutex_unlock(&_mutex);
if (itr == _map.end()) // not found in map
{
- std::stringstream ss;
- ss << std::hex << "xid=\"" << xid << "\"";
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "txn_map", "get_rid_count");
+ std::ostringstream oss;
+ oss << std::hex << "xid=\"" << xid << "\"";
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "txn_map", "get_rid_count");
}
return itr->second.size();
}
@@ -150,9 +150,9 @@
if (itr == _map.end()) // not found in map
{
pthread_mutex_unlock(&_mutex);
- std::stringstream ss;
- ss << std::hex << "xid=\"" << xid << "\"";
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "txn_map", "is_txn_synced");
+ std::ostringstream oss;
+ oss << std::hex << "xid=\"" << xid << "\"";
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "txn_map", "is_txn_synced");
}
bool is_synced = true;
for (tdl_itr litr = itr->second.begin(); litr < itr->second.end(); litr++)
@@ -191,9 +191,9 @@
pthread_mutex_unlock(&_mutex);
if (ok && !found)
{
- std::stringstream ss;
- ss << std::hex << "xid=\"" << xid << "\" rid=" << rid;
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "txn_map", "set_aio_compl");
+ std::ostringstream oss;
+ oss << std::hex << "xid=\"" << xid << "\" rid=" << rid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "txn_map", "set_aio_compl");
}
return ok;
}
Modified: store/trunk/cpp/lib/jrnl/txn_rec.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_rec.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/txn_rec.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -375,15 +375,15 @@
std::string&
txn_rec::str(std::string& str) const
{
- std::stringstream ss;
+ std::ostringstream oss;
if (_txn_hdr._magic == RHM_JDAT_TXA_MAGIC)
- ss << "dtxa_rec: m=" << _txn_hdr._magic;
+ oss << "dtxa_rec: m=" << _txn_hdr._magic;
else
- ss << "dtxc_rec: m=" << _txn_hdr._magic;
- ss << " v=" << (int)_txn_hdr._version;
- ss << " rid=" << _txn_hdr._rid;
- ss << " xid=\"" << _xidp << "\"";
- str.append(ss.str());
+ oss << "dtxc_rec: m=" << _txn_hdr._magic;
+ oss << " v=" << (int)_txn_hdr._version;
+ oss << " rid=" << _txn_hdr._rid;
+ oss << " xid=\"" << _xidp << "\"";
+ str.append(oss.str());
return str;
}
@@ -405,13 +405,13 @@
jrec::chk_hdr(_txn_hdr);
if (_txn_hdr._magic != RHM_JDAT_TXA_MAGIC && _txn_hdr._magic != RHM_JDAT_TXC_MAGIC)
{
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- ss << "dtx magic: rid=0x" << std::setw(16) << _txn_hdr._rid;
- ss << ": expected=(0x" << std::setw(8) << RHM_JDAT_TXA_MAGIC;
- ss << " or 0x" << RHM_JDAT_TXC_MAGIC;
- ss << ") read=0x" << std::setw(2) << (int)_txn_hdr._magic;
- throw jexception(jerrno::JERR_JREC_BADRECHDR, ss.str().c_str(), "txn_rec", "chk_hdr");
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "dtx magic: rid=0x" << std::setw(16) << _txn_hdr._rid;
+ oss << ": expected=(0x" << std::setw(8) << RHM_JDAT_TXA_MAGIC;
+ oss << " or 0x" << RHM_JDAT_TXC_MAGIC;
+ oss << ") read=0x" << std::setw(2) << (int)_txn_hdr._magic;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "txn_rec", "chk_hdr");
}
}
Modified: store/trunk/cpp/lib/jrnl/wmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wmgr.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/lib/jrnl/wmgr.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -133,9 +133,9 @@
cont = true;
else
{
- std::stringstream ss;
- ss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
- throw jexception(jerrno::JERR_WMGR_ENQDISCONT, ss.str().c_str(), "wmgr", "enqueue");
+ std::ostringstream oss;
+ oss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_ENQDISCONT, oss.str(), "wmgr", "enqueue");
}
}
else
@@ -269,9 +269,9 @@
cont = true;
else
{
- std::stringstream ss;
- ss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
- throw jexception(jerrno::JERR_WMGR_DEQDISCONT, ss.str().c_str(), "wmgr", "dequeue");
+ std::ostringstream oss;
+ oss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_DEQDISCONT, oss.str(), "wmgr", "dequeue");
}
}
else
@@ -420,9 +420,9 @@
cont = true;
else
{
- std::stringstream ss;
- ss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
- throw jexception(jerrno::JERR_WMGR_DEQDISCONT, ss.str().c_str(), "wmgr", "abort");
+ std::ostringstream oss;
+ oss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_DEQDISCONT, oss.str(), "wmgr", "abort");
}
}
else
@@ -481,9 +481,9 @@
std::pair<std::set<std::string>::iterator, bool> res = _txn_pending_set.insert(xid);
if (!res.second)
{
- std::stringstream ss;
- ss << std::hex << "_txn_pending_set: xid=\"" << xid << "\"";
- throw jexception(jerrno::JERR_MAP_DUPLICATE, ss.str().c_str(), "wmgr", "abort");
+ std::ostringstream oss;
+ oss << std::hex << "_txn_pending_set: xid=\"" << xid << "\"";
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "wmgr", "abort");
}
#endif
@@ -566,9 +566,9 @@
cont = true;
else
{
- std::stringstream ss;
- ss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
- throw jexception(jerrno::JERR_WMGR_DEQDISCONT, ss.str().c_str(), "wmgr", "commit");
+ std::ostringstream oss;
+ oss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_DEQDISCONT, oss.str(), "wmgr", "commit");
}
}
else
@@ -623,9 +623,9 @@
std::pair<std::set<std::string>::iterator, bool> res = _txn_pending_set.insert(xid);
if (!res.second)
{
- std::stringstream ss;
- ss << std::hex << "_txn_pending_set: xid=\"" << xid << "\"";
- throw jexception(jerrno::JERR_MAP_DUPLICATE, ss.str().c_str(), "wmgr", "commit");
+ std::ostringstream oss;
+ oss << std::hex << "_txn_pending_set: xid=\"" << xid << "\"";
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "wmgr", "commit");
}
#endif
@@ -714,9 +714,9 @@
{
if (_page_cb_arr[_pg_index]._state != IN_USE)
{
- std::stringstream ss;
- ss << "pg_index=" << _pg_index << " state=" << _page_cb_arr[_pg_index].state_str();
- throw jexception(jerrno::JERR_WMGR_BADPGSTATE, ss.str().c_str(), "wmgr",
+ std::ostringstream oss;
+ oss << "pg_index=" << _pg_index << " state=" << _page_cb_arr[_pg_index].state_str();
+ throw jexception(jerrno::JERR_WMGR_BADPGSTATE, oss.str(), "wmgr",
"write_flush");
}
@@ -768,9 +768,9 @@
{
if (ret == -EINTR) // No events
return 0;
- std::stringstream ss;
- ss << "io_getevents() failed: " << strerror(-ret) << " (" << ret << ")";
- throw jexception(jerrno::JERR__AIO, ss.str().c_str(), "wmgr", "get_events");
+ std::ostringstream oss;
+ oss << "io_getevents() failed: " << strerror(-ret) << " (" << ret << ")";
+ throw jexception(jerrno::JERR__AIO, oss.str(), "wmgr", "get_events");
}
u_int32_t tot_data_toks = 0;
@@ -778,9 +778,9 @@
{
if (_aio_evt_rem == 0)
{
- std::stringstream ss;
- ss << "_aio_evt_rem; evt " << (i + 1) << " of " << ret;
- throw jexception(jerrno::JERR__UNDERFLOW, ss.str().c_str(), "wmgr", "get_events");
+ std::ostringstream oss;
+ oss << "_aio_evt_rem; evt " << (i + 1) << " of " << ret;
+ throw jexception(jerrno::JERR__UNDERFLOW, oss.str(), "wmgr", "get_events");
}
_aio_evt_rem--;
iocb* iocbp = _ioevt_arr[i].obj; // This I/O control block (iocb)
@@ -788,11 +788,11 @@
long aioret = (long)_ioevt_arr[i].res;
if (aioret < 0)
{
- std::stringstream ss;
- ss << "AIO write operation failed: " << strerror(-aioret) << " (" << aioret << ")";
- ss << " [pg=" << pcbp->_index << " size=" << iocbp->u.c.nbytes;
- ss << " offset=" << iocbp->u.c.offset << " fh=" << iocbp->aio_fildes << "]";
- throw jexception(jerrno::JERR__AIO, ss.str().c_str(), "wmgr", "get_events");
+ std::ostringstream oss;
+ oss << "AIO write operation failed: " << strerror(-aioret) << " (" << aioret << ")";
+ oss << " [pg=" << pcbp->_index << " size=" << iocbp->u.c.nbytes;
+ oss << " offset=" << iocbp->u.c.offset << " fh=" << iocbp->aio_fildes << "]";
+ throw jexception(jerrno::JERR__AIO, oss.str(), "wmgr", "get_events");
}
if (pcbp) // Page writes have pcb
{
@@ -819,9 +819,9 @@
it = _txn_pending_set.find(dtp->xid());
if (it == _txn_pending_set.end())
{
- std::stringstream ss;
- ss << std::hex << "_txn_pending_set: abort xid=\"" << dtp->xid() << "\"";
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "wmgr",
+ std::ostringstream oss;
+ oss << std::hex << "_txn_pending_set: abort xid=\"" << dtp->xid() << "\"";
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "wmgr",
"get_events");
}
_txn_pending_set.erase(it);
@@ -833,18 +833,18 @@
it = _txn_pending_set.find(dtp->xid());
if (it == _txn_pending_set.end())
{
- std::stringstream ss;
- ss << std::hex << "_txn_pending_set: commit xid=\"" << dtp->xid() << "\"";
- throw jexception(jerrno::JERR_MAP_NOTFOUND, ss.str().c_str(), "wmgr",
+ std::ostringstream oss;
+ oss << std::hex << "_txn_pending_set: commit xid=\"" << dtp->xid() << "\"";
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "wmgr",
"get_events");
}
_txn_pending_set.erase(it);
#endif
break;
default:
- std::stringstream ss;
- ss << "dtok_id=" << dtp->id() << "dtok_state=" << dtp->wstate_str();
- throw jexception(jerrno::JERR_WMGR_BADDTOKSTATE, ss.str().c_str(), "wmgr",
+ std::ostringstream oss;
+ oss << "dtok_id=" << dtp->id() << "dtok_state=" << dtp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_BADDTOKSTATE, oss.str(), "wmgr",
"get_events");
}
_dtoklp->push_back(dtp);
@@ -904,10 +904,10 @@
if (::posix_memalign(&_fhdr_base_ptr, _sblksize, _sblksize * num_jfiles))
{
clean();
- std::stringstream ss;
- ss << "posix_memalign(): blksize=" << _sblksize << " size=" << _sblksize;
- ss << " errno=" << errno;
- throw jexception(jerrno::JERR__MALLOC, ss.str().c_str(), "wmgr", "initialize");
+ std::ostringstream oss;
+ oss << "posix_memalign(): blksize=" << _sblksize << " size=" << _sblksize;
+ oss << " errno=" << errno;
+ throw jexception(jerrno::JERR__MALLOC, oss.str(), "wmgr", "initialize");
}
_fhdr_ptr_arr = (void**)::malloc(_pages * sizeof(void*));
MALLOC_CHK(_fhdr_ptr_arr, "_fhdr_ptr_arr", "wmgr", "initialize");
@@ -944,11 +944,10 @@
return RHM_IORES_AIO_WAIT;
else
{
- std::stringstream ss;
- ss << "op=" << _op_str[op] << " index=" << _pg_index << " state=";
- ss << _page_cb_arr[_pg_index].state_str();
- throw jexception(jerrno::JERR_WMGR_BADPGSTATE, ss.str().c_str(), "wmgr",
- "pre_write_check");
+ std::ostringstream oss;
+ oss << "op=" << _op_str[op] << " index=" << _pg_index << " state=";
+ oss << _page_cb_arr[_pg_index].state_str();
+ throw jexception(jerrno::JERR_WMGR_BADPGSTATE, oss.str(), "wmgr", "pre_write_check");
}
}
@@ -958,20 +957,20 @@
case WMGR_ENQUEUE:
if (!dtokp->is_writable())
{
- std::stringstream ss;
- ss << "op=" << _op_str[op] << " dtok_id=" << dtokp->id();
- ss << " dtok_state=" << dtokp->wstate_str();
- throw jexception(jerrno::JERR_WMGR_BADDTOKSTATE, ss.str().c_str(), "wmgr",
+ std::ostringstream oss;
+ oss << "op=" << _op_str[op] << " dtok_id=" << dtokp->id();
+ oss << " dtok_state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_BADDTOKSTATE, oss.str(), "wmgr",
"pre_write_check");
}
break;
case WMGR_DEQUEUE:
if (!dtokp->is_dequeueable())
{
- std::stringstream ss;
- ss << "op=" << _op_str[op] << " dtok_id=" << dtokp->id();
- ss << " dtok_state=" << dtokp->wstate_str();
- throw jexception(jerrno::JERR_WMGR_BADDTOKSTATE, ss.str().c_str(), "wmgr",
+ std::ostringstream oss;
+ oss << "op=" << _op_str[op] << " dtok_id=" << dtokp->id();
+ oss << " dtok_state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_BADDTOKSTATE, oss.str(), "wmgr",
"pre_write_check");
}
break;
Modified: store/trunk/cpp/tests/jrnl/unit_test_jexception.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_jexception.cpp 2007-12-11 22:41:25 UTC (rev 1459)
+++ store/trunk/cpp/tests/jrnl/unit_test_jexception.cpp 2007-12-11 23:20:58 UTC (rev 1460)
@@ -54,120 +54,192 @@
{
jexception e1;
BOOST_CHECK_EQUAL(e1.err_code(), (u_int32_t)0);
- BOOST_CHECK(::strlen(e1.additional_info()) == 0);
- BOOST_CHECK(::strlen(e1.throwing_class()) == 0);
- BOOST_CHECK(::strlen(e1.throwing_fn()) == 0);
+ BOOST_CHECK(e1.additional_info().size() == 0);
+ BOOST_CHECK(e1.throwing_class().size() == 0);
+ BOOST_CHECK(e1.throwing_fn().size() == 0);
BOOST_CHECK(::strlen(e1.what()) > 0);
throw e1;
}
catch (const jexception& e)
{
BOOST_CHECK_EQUAL(e.err_code(), (u_int32_t)0);
- BOOST_CHECK(::strlen(e.additional_info()) == 0);
- BOOST_CHECK(::strlen(e.throwing_class()) == 0);
- BOOST_CHECK(::strlen(e.throwing_fn()) == 0);
+ BOOST_CHECK(e.additional_info().size() == 0);
+ BOOST_CHECK(e.throwing_class().size() == 0);
+ BOOST_CHECK(e.throwing_fn().size() == 0);
BOOST_CHECK(::strlen(e.what()) > 0);
}
}
void test_constructor_2()
{
- u_int32_t err_code = 2;
+ const u_int32_t err_code = 2;
try
{
jexception e2(err_code);
BOOST_CHECK_EQUAL(e2.err_code(), err_code);
- BOOST_CHECK(::strlen(e2.additional_info()) == 0);
- BOOST_CHECK(::strlen(e2.throwing_class()) == 0);
- BOOST_CHECK(::strlen(e2.throwing_fn()) == 0);
+ BOOST_CHECK(e2.additional_info().size() == 0);
+ BOOST_CHECK(e2.throwing_class().size() == 0);
+ BOOST_CHECK(e2.throwing_fn().size() == 0);
BOOST_CHECK(::strlen(e2.what()) > 0);
throw e2;
}
catch (const jexception& e)
{
BOOST_CHECK_EQUAL(e.err_code(), err_code);
- BOOST_CHECK(::strlen(e.additional_info()) == 0);
- BOOST_CHECK(::strlen(e.throwing_class()) == 0);
- BOOST_CHECK(::strlen(e.throwing_fn()) == 0);
+ BOOST_CHECK(e.additional_info().size() == 0);
+ BOOST_CHECK(e.throwing_class().size() == 0);
+ BOOST_CHECK(e.throwing_fn().size() == 0);
BOOST_CHECK(::strlen(e.what()) > 0);
}
}
-void test_constructor_3()
+void test_constructor_3a()
{
const char* err_msg = "exception3";
try
{
jexception e3(err_msg);
BOOST_CHECK_EQUAL(e3.err_code(), (u_int32_t)0);
- BOOST_CHECK(::strcmp(e3.additional_info(), err_msg) == 0);
- BOOST_CHECK(::strlen(e3.throwing_class()) == 0);
- BOOST_CHECK(::strlen(e3.throwing_fn()) == 0);
+ BOOST_CHECK(e3.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e3.throwing_class().size() == 0);
+ BOOST_CHECK(e3.throwing_fn().size() == 0);
BOOST_CHECK(::strlen(e3.what()) > 0);
throw e3;
}
catch (const jexception& e)
{
BOOST_CHECK_EQUAL(e.err_code(), (u_int32_t)0);
- BOOST_CHECK(::strcmp(e.additional_info(), err_msg) == 0);
- BOOST_CHECK(::strlen(e.throwing_class()) == 0);
- BOOST_CHECK(::strlen(e.throwing_fn()) == 0);
+ BOOST_CHECK(e.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e.throwing_class().size() == 0);
+ BOOST_CHECK(e.throwing_fn().size() == 0);
BOOST_CHECK(::strlen(e.what()) > 0);
}
}
-void test_constructor_4()
+void test_constructor_3b()
{
- u_int32_t err_code = 4;
+ const std::string err_msg("exception3");
+ try
+ {
+ jexception e3(err_msg);
+ BOOST_CHECK_EQUAL(e3.err_code(), (u_int32_t)0);
+ BOOST_CHECK(e3.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e3.throwing_class().size() == 0);
+ BOOST_CHECK(e3.throwing_fn().size() == 0);
+ BOOST_CHECK(::strlen(e3.what()) > 0);
+ throw e3;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), (u_int32_t)0);
+ BOOST_CHECK(e.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e.throwing_class().size() == 0);
+ BOOST_CHECK(e.throwing_fn().size() == 0);
+ BOOST_CHECK(::strlen(e.what()) > 0);
+ }
+}
+
+void test_constructor_4a()
+{
+ const u_int32_t err_code = 4;
const char* err_msg = "exception4";
try
{
jexception e4(err_code, err_msg);
BOOST_CHECK_EQUAL(e4.err_code(), err_code);
- BOOST_CHECK(::strcmp(e4.additional_info(), err_msg) == 0);
- BOOST_CHECK(::strlen(e4.throwing_class()) == 0);
- BOOST_CHECK(::strlen(e4.throwing_fn()) == 0);
+ BOOST_CHECK(e4.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e4.throwing_class().size() == 0);
+ BOOST_CHECK(e4.throwing_fn().size() == 0);
BOOST_CHECK(::strlen(e4.what()) > 0);
throw e4;
}
catch (const jexception& e)
{
BOOST_CHECK_EQUAL(e.err_code(), err_code);
- BOOST_CHECK(::strcmp(e.additional_info(), err_msg) == 0);
- BOOST_CHECK(::strlen(e.throwing_class()) == 0);
- BOOST_CHECK(::strlen(e.throwing_fn()) == 0);
+ BOOST_CHECK(e.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e.throwing_class().size() == 0);
+ BOOST_CHECK(e.throwing_fn().size() == 0);
BOOST_CHECK(::strlen(e.what()) > 0);
}
}
-void test_constructor_5()
+void test_constructor_4b()
{
- u_int32_t err_code = 5;
+ const u_int32_t err_code = 4;
+ const std::string err_msg("exception4");
+ try
+ {
+ jexception e4(err_code, err_msg);
+ BOOST_CHECK_EQUAL(e4.err_code(), err_code);
+ BOOST_CHECK(e4.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e4.throwing_class().size() == 0);
+ BOOST_CHECK(e4.throwing_fn().size() == 0);
+ BOOST_CHECK(::strlen(e4.what()) > 0);
+ throw e4;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), err_code);
+ BOOST_CHECK(e.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e.throwing_class().size() == 0);
+ BOOST_CHECK(e.throwing_fn().size() == 0);
+ BOOST_CHECK(::strlen(e.what()) > 0);
+ }
+}
+
+void test_constructor_5a()
+{
+ const u_int32_t err_code = 5;
const char* err_class = "class5";
const char* err_fn = "fn5";
try
{
jexception e5(err_code, err_class, err_fn);
BOOST_CHECK_EQUAL(e5.err_code(), err_code);
- BOOST_CHECK(::strlen(e5.additional_info()) == 0);
- BOOST_CHECK(::strcmp(e5.throwing_class(), err_class) == 0);
- BOOST_CHECK(::strcmp(e5.throwing_fn(), err_fn) == 0);
+ BOOST_CHECK(e5.additional_info().size() == 0);
+ BOOST_CHECK(e5.throwing_class().compare(err_class) == 0);
+ BOOST_CHECK(e5.throwing_fn().compare(err_fn) == 0);
BOOST_CHECK(::strlen(e5.what()) > 0);
throw e5;
}
catch (const jexception& e)
{
BOOST_CHECK_EQUAL(e.err_code(), err_code);
- BOOST_CHECK(::strlen(e.additional_info()) == 0);
- BOOST_CHECK(::strcmp(e.throwing_class(), err_class) == 0);
- BOOST_CHECK(::strcmp(e.throwing_fn(), err_fn) == 0);
+ BOOST_CHECK(e.additional_info().size() == 0);
+ BOOST_CHECK(e.throwing_class().compare(err_class) == 0);
+ BOOST_CHECK(e.throwing_fn().compare(err_fn) == 0);
BOOST_CHECK(::strlen(e.what()) > 0);
}
}
-void test_constructor_6()
+void test_constructor_5b()
{
- u_int32_t err_code = 6;
+ const u_int32_t err_code = 5;
+ const std::string err_class("class5");
+ const std::string err_fn("fn5");
+ try
+ {
+ jexception e5(err_code, err_class, err_fn);
+ BOOST_CHECK_EQUAL(e5.err_code(), err_code);
+ BOOST_CHECK(e5.additional_info().size() == 0);
+ BOOST_CHECK(e5.throwing_class().compare(err_class) == 0);
+ BOOST_CHECK(e5.throwing_fn().compare(err_fn) == 0);
+ BOOST_CHECK(::strlen(e5.what()) > 0);
+ throw e5;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), err_code);
+ BOOST_CHECK(e.additional_info().size() == 0);
+ BOOST_CHECK(e.throwing_class().compare(err_class) == 0);
+ BOOST_CHECK(e.throwing_fn().compare(err_fn) == 0);
+ BOOST_CHECK(::strlen(e.what()) > 0);
+ }
+}
+
+void test_constructor_6a()
+{
+ const u_int32_t err_code = 6;
const char* err_msg = "exception6";
const char* err_class = "class6";
const char* err_fn = "fn6";
@@ -175,31 +247,57 @@
{
jexception e6(err_code, err_msg, err_class, err_fn);
BOOST_CHECK_EQUAL(e6.err_code(), err_code);
- BOOST_CHECK(::strcmp(e6.additional_info(), err_msg) == 0);
- BOOST_CHECK(::strcmp(e6.throwing_class(), err_class) == 0);
- BOOST_CHECK(::strcmp(e6.throwing_fn(), err_fn) == 0);
+ BOOST_CHECK(e6.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e6.throwing_class().compare(err_class) == 0);
+ BOOST_CHECK(e6.throwing_fn().compare(err_fn) == 0);
BOOST_CHECK(::strlen(e6.what()) > 0);
throw e6;
}
catch (const jexception& e)
{
BOOST_CHECK_EQUAL(e.err_code(), err_code);
- BOOST_CHECK(::strcmp(e.additional_info(), err_msg) == 0);
- BOOST_CHECK(::strcmp(e.throwing_class(), err_class) == 0);
- BOOST_CHECK(::strcmp(e.throwing_fn(), err_fn) == 0);
+ BOOST_CHECK(e.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e.throwing_class().compare(err_class) == 0);
+ BOOST_CHECK(e.throwing_fn().compare(err_fn) == 0);
BOOST_CHECK(::strlen(e.what()) > 0);
}
}
+void test_constructor_6b()
+{
+ const u_int32_t err_code = 6;
+ const std::string err_msg("exception6");
+ const std::string err_class("class6");
+ const std::string err_fn("fn6");
+ try
+ {
+ jexception e6(err_code, err_msg, err_class, err_fn);
+ BOOST_CHECK_EQUAL(e6.err_code(), err_code);
+ BOOST_CHECK(e6.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e6.throwing_class().compare(err_class) == 0);
+ BOOST_CHECK(e6.throwing_fn().compare(err_fn) == 0);
+ BOOST_CHECK(::strlen(e6.what()) > 0);
+ throw e6;
+ }
+ catch (const jexception& e)
+ {
+ BOOST_CHECK_EQUAL(e.err_code(), err_code);
+ BOOST_CHECK(e.additional_info().compare(err_msg) == 0);
+ BOOST_CHECK(e.throwing_class().compare(err_class) == 0);
+ BOOST_CHECK(e.throwing_fn().compare(err_fn) == 0);
+ BOOST_CHECK(::strlen(e.what()) > 0);
+ }
+}
+
void test_msg_scope()
{
try
{
// These will go out of scope as soon as jexception is thrown...
- std::string msg("Error message");
- std::string cls("class");
- std::string fn("function");
- throw jexception(100, msg.c_str(), cls.c_str(), fn.c_str());
+ const std::string msg("Error message");
+ const std::string cls("class");
+ const std::string fn("function");
+ throw jexception(100, msg, cls, fn);
}
catch (const jexception& e)
{
@@ -209,93 +307,6 @@
}
}
-void test_long_null_strings()
-{
- // msg 1500 chars long; every 50th char is a '*'
- const char* long_msg =
- "Long_message_456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*";
- // throwing class and function 250 chars long
- const char* long_throwing_class =
- "Long_throwing_class_12345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*";
- const char* long_throwing_fn =
- "Long_throwing_function_45678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*"
- "1234567890123456789012345678901234567890123456789*";
-
-
- throw_exception(jexception(long_msg), MAX_MSG_SIZE - 1, MAX_MSG_SIZE - 1);
- throw_exception(jexception((const char*)NULL), 11, 0);
-
- throw_exception(jexception(0x1234, long_msg), MAX_MSG_SIZE - 1, MAX_MSG_SIZE - 1);
- throw_exception(jexception(0x1234, NULL), 18 + ::strlen(jerrno::err_msg(0x1234)), 0);
-
- throw_exception(jexception(0x1234, long_throwing_class, long_throwing_fn),
- 29 + (2 * (MAX_THROWING_SIZE - 1)) + ::strlen(jerrno::err_msg(0x1234)),
- MAX_THROWING_SIZE - 1, MAX_THROWING_SIZE - 1);
- throw_exception(jexception(0x1234, long_throwing_class, NULL),
- 25 + MAX_THROWING_SIZE - 1 + ::strlen(jerrno::err_msg(0x1234)), MAX_THROWING_SIZE - 1,
- 0);
- throw_exception(jexception(0x1234, NULL, long_throwing_fn),
- 27 + MAX_THROWING_SIZE - 1 + ::strlen(jerrno::err_msg(0x1234)), 0,
- MAX_THROWING_SIZE - 1);
- throw_exception(jexception(0x1234, NULL, NULL), 18 + ::strlen(jerrno::err_msg(0x1234)), 0, 0);
-
- throw_exception(jexception(0x1234, long_msg, long_throwing_class, long_throwing_fn),
- MAX_MSG_SIZE - 1, MAX_MSG_SIZE - 1, MAX_THROWING_SIZE - 1, MAX_THROWING_SIZE - 1);
- throw_exception(jexception(0x1234, long_msg, long_throwing_class, NULL), MAX_MSG_SIZE - 1,
- MAX_MSG_SIZE - 1, MAX_THROWING_SIZE - 1, 0);
- throw_exception(jexception(0x1234, long_msg, NULL, long_throwing_fn), MAX_MSG_SIZE - 1,
- MAX_MSG_SIZE - 1, 0, MAX_THROWING_SIZE - 1);
- throw_exception(jexception(0x1234, long_msg, NULL, NULL), MAX_MSG_SIZE - 1, MAX_MSG_SIZE - 1, 0,
- 0);
- throw_exception(jexception(0x1234, NULL, long_throwing_class, long_throwing_fn),
- 29 + (2 * (MAX_THROWING_SIZE - 1)) + ::strlen(jerrno::err_msg(0x1234)), 0,
- MAX_THROWING_SIZE - 1, MAX_THROWING_SIZE - 1);
- throw_exception(jexception(0x1234, NULL, long_throwing_class, NULL),
- 25 + MAX_THROWING_SIZE - 1 + ::strlen(jerrno::err_msg(0x1234)), 0,
- MAX_THROWING_SIZE - 1, 0);
- throw_exception(jexception(0x1234, NULL, NULL, long_throwing_fn),
- 27 + MAX_THROWING_SIZE - 1 + ::strlen(jerrno::err_msg(0x1234)), 0, 0,
- MAX_THROWING_SIZE - 1);
- throw_exception(jexception(0x1234, NULL, NULL, NULL), 18 + ::strlen(jerrno::err_msg(0x1234)),
- 0, 0, 0);
-}
-
// Helper functions
void throw_exception(const jexception& e, size_t what_len, size_t ai_len)
@@ -315,9 +326,9 @@
catch (const jexception& e)
{
BOOST_CHECK_EQUAL(::strlen(e.what()), what_len);
- BOOST_CHECK_EQUAL(::strlen(e.additional_info()), ai_len);
- BOOST_CHECK_EQUAL(::strlen(e.throwing_class()), tc_len);
- BOOST_CHECK_EQUAL(::strlen(e.throwing_fn()), tf_len);
+ BOOST_CHECK_EQUAL(e.additional_info().size(), ai_len);
+ BOOST_CHECK_EQUAL(e.throwing_class().size(), tc_len);
+ BOOST_CHECK_EQUAL(e.throwing_fn().size(), tf_len);
}
}
@@ -333,12 +344,15 @@
ts->add(BOOST_TEST_CASE(&test_constructor_1));
ts->add(BOOST_TEST_CASE(&test_constructor_2));
- ts->add(BOOST_TEST_CASE(&test_constructor_3));
- ts->add(BOOST_TEST_CASE(&test_constructor_4));
- ts->add(BOOST_TEST_CASE(&test_constructor_5));
- ts->add(BOOST_TEST_CASE(&test_constructor_6));
+ ts->add(BOOST_TEST_CASE(&test_constructor_3a));
+ ts->add(BOOST_TEST_CASE(&test_constructor_3b));
+ ts->add(BOOST_TEST_CASE(&test_constructor_4a));
+ ts->add(BOOST_TEST_CASE(&test_constructor_4b));
+ ts->add(BOOST_TEST_CASE(&test_constructor_5a));
+ ts->add(BOOST_TEST_CASE(&test_constructor_5b));
+ ts->add(BOOST_TEST_CASE(&test_constructor_6a));
+ ts->add(BOOST_TEST_CASE(&test_constructor_6b));
ts->add(BOOST_TEST_CASE(&test_msg_scope));
- ts->add(BOOST_TEST_CASE(&test_long_null_strings));
return ts;
}
More information about the rhmessaging-commits
mailing list