summaryrefslogtreecommitdiff
path: root/src/iodevice.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/iodevice.cc')
-rw-r--r--src/iodevice.cc70
1 files changed, 19 insertions, 51 deletions
diff --git a/src/iodevice.cc b/src/iodevice.cc
index c2bc9ee..851bfb1 100644
--- a/src/iodevice.cc
+++ b/src/iodevice.cc
@@ -1,9 +1,10 @@
-/** --------------------------------------------------------------------
+/**
* @file iodevice.cc
* @brief Implementation of the IODevice class.
* @author Andreas Aardal Hanssen
* @date 2002, 2003
- * ----------------------------------------------------------------- **/
+ */
+
#include "iodevice.h"
#include "convert.h" // BincStream
@@ -13,10 +14,9 @@
#include <unistd.h>
-using namespace ::std;
-using namespace ::Binc;
+using namespace Binc;
+using std::ostream;
-//------------------------------------------------------------------------
IODevice::IODevice(int f)
: flags(f | IsEnabled)
, maxInputBufferSize(0)
@@ -31,15 +31,13 @@ IODevice::IODevice(int f)
, dumpfd(0)
{}
-//------------------------------------------------------------------------
IODevice::~IODevice(void) {}
-//------------------------------------------------------------------------
IODevice &IODevice::operator<<(ostream &(*source)(ostream &))
{
if (!(flags & IsEnabled) || outputLevel > outputLevelLimit) return *this;
- static std::ostream &(*endl_funcptr)(ostream &) = endl;
+ static ostream &(*endl_funcptr)(ostream &) = std::endl;
if (source != endl_funcptr) return *this;
@@ -47,21 +45,20 @@ IODevice &IODevice::operator<<(ostream &(*source)(ostream &))
if (dumpfd) ::write(dumpfd, "\r\n", 2);
- if (flags & FlushesOnEndl)
+ if (flags & FlushesOnEndl) {
flush();
- else if (flags & HasOutputLimit)
+ } else if (flags & HasOutputLimit) {
if (outputBuffer.getSize() > maxOutputBufferSize) flush();
+ }
return *this;
}
-//------------------------------------------------------------------------
bool IODevice::canRead(void) const
{
return false;
}
-//------------------------------------------------------------------------
void IODevice::clear()
{
if (!(flags & IsEnabled)) return;
@@ -70,7 +67,6 @@ void IODevice::clear()
outputBuffer.clear();
}
-//------------------------------------------------------------------------
bool IODevice::flush()
{
if (!(flags & IsEnabled)) return true;
@@ -90,31 +86,26 @@ bool IODevice::flush()
return true;
}
-//------------------------------------------------------------------------
void IODevice::setFlags(unsigned int f)
{
flags |= f;
}
-//------------------------------------------------------------------------
void IODevice::clearFlags(unsigned int f)
{
flags &= ~f;
}
-//------------------------------------------------------------------------
void IODevice::setMaxInputBufferSize(unsigned int max)
{
maxInputBufferSize = max;
}
-//------------------------------------------------------------------------
void IODevice::setMaxOutputBufferSize(unsigned int max)
{
maxOutputBufferSize = max;
}
-//------------------------------------------------------------------------
void IODevice::setTimeout(unsigned int t)
{
timeout = t;
@@ -125,52 +116,43 @@ void IODevice::setTimeout(unsigned int t)
flags &= ~HasTimeout;
}
-//------------------------------------------------------------------------
unsigned int IODevice::getTimeout(void) const
{
return timeout;
}
-//------------------------------------------------------------------------
void IODevice::setOutputLevel(LogLevel level)
{
outputLevel = level;
}
-//------------------------------------------------------------------------
IODevice::LogLevel IODevice::getOutputLevel(void) const
{
return outputLevel;
}
-//------------------------------------------------------------------------
void IODevice::setOutputLevelLimit(LogLevel level)
{
outputLevelLimit = level;
}
-//------------------------------------------------------------------------
IODevice::LogLevel IODevice::getOutputLevelLimit(void) const
{
return outputLevelLimit;
}
-//------------------------------------------------------------------------
-bool IODevice::readStr(string *dest, unsigned int max)
+bool IODevice::readStr(std::string *dest, unsigned int max)
{
// If max is 0, fill the input buffer once only if it's empty.
if (!max && inputBuffer.getSize() == 0 && !fillInputBuffer()) return false;
// If max is != 0, wait until we have max.
- while (max && inputBuffer.getSize() < max) {
+ while (max && inputBuffer.getSize() < max)
if (!fillInputBuffer()) return false;
- }
unsigned int bytesToRead = max ? max : inputBuffer.getSize();
*dest += inputBuffer.str().substr(0, bytesToRead);
- if (dumpfd) {
- ::write(dumpfd, inputBuffer.str().substr(0, bytesToRead).c_str(), bytesToRead);
- }
+ if (dumpfd) ::write(dumpfd, inputBuffer.str().substr(0, bytesToRead).c_str(), bytesToRead);
inputBuffer.popString(bytesToRead);
readCount += bytesToRead;
@@ -178,7 +160,6 @@ bool IODevice::readStr(string *dest, unsigned int max)
return true;
}
-//------------------------------------------------------------------------
bool IODevice::readChar(char *dest)
{
if (inputBuffer.getSize() == 0 && !fillInputBuffer()) return false;
@@ -192,19 +173,16 @@ bool IODevice::readChar(char *dest)
return true;
}
-//------------------------------------------------------------------------
void IODevice::unreadChar(char c)
{
inputBuffer.unpopChar(c);
}
-//------------------------------------------------------------------------
-void IODevice::unreadStr(const string &s)
+void IODevice::unreadStr(const std::string &s)
{
inputBuffer.unpopStr(s);
}
-//------------------------------------------------------------------------
bool IODevice::skipTo(char c)
{
char dest = '\0';
@@ -216,67 +194,57 @@ bool IODevice::skipTo(char c)
return true;
}
-//------------------------------------------------------------------------
-string IODevice::service(void) const
+std::string IODevice::service(void) const
{
return "nul";
}
-//------------------------------------------------------------------------
bool IODevice::waitForWrite(void) const
{
return false;
}
-//------------------------------------------------------------------------
bool IODevice::waitForRead(void) const
{
return false;
}
-//------------------------------------------------------------------------
IODevice::WriteResult IODevice::write(void)
{
return WriteError;
}
-//------------------------------------------------------------------------
bool IODevice::fillInputBuffer(void)
{
return false;
}
-//------------------------------------------------------------------------
IODevice::Error IODevice::getLastError(void) const
{
return error;
}
-//------------------------------------------------------------------------
-string IODevice::getLastErrorString(void) const
+std::string IODevice::getLastErrorString(void) const
{
return errorString;
}
-//------------------------------------------------------------------------
unsigned int IODevice::getReadCount(void) const
{
return readCount;
}
-//------------------------------------------------------------------------
unsigned int IODevice::getWriteCount(void) const
{
return writeCount;
}
-//------------------------------------------------------------------------
void IODevice::enableProtocolDumping(void)
{
BincStream ss;
- ss << "/tmp/bincimap-dump-" << (int)time(0) << "-" << Session::getInstance().getIP() << "-XXXXXX";
- char *safename = strdup(ss.str().c_str());
- dumpfd = mkstemp(safename);
+ ss << "/tmp/bincimap-dump-" << static_cast<int>(time(nullptr)) << "-" << Session::getInstance().getIP()
+ << "-XXXXXX";
+ std::string safename = ss.str();
+ dumpfd = mkstemp(safename.data());
if (dumpfd == -1) dumpfd = 0;
- delete[] safename;
}