aboutsummaryrefslogtreecommitdiffstats
path: root/src/platforms/posix
diff options
context:
space:
mode:
Diffstat (limited to 'src/platforms/posix')
-rw-r--r--src/platforms/posix/posixChildProcess.cpp30
-rw-r--r--src/platforms/posix/posixFile.cpp27
-rw-r--r--src/platforms/posix/posixHandler.cpp2
-rw-r--r--src/platforms/posix/posixSocket.cpp24
4 files changed, 47 insertions, 36 deletions
diff --git a/src/platforms/posix/posixChildProcess.cpp b/src/platforms/posix/posixChildProcess.cpp
index c4761624..54d4cd75 100644
--- a/src/platforms/posix/posixChildProcess.cpp
+++ b/src/platforms/posix/posixChildProcess.cpp
@@ -118,7 +118,14 @@ public:
{
}
- void write(const value_type* const data, const size_type count)
+ void flush()
+ {
+ ::fsync(m_desc);
+ }
+
+protected:
+
+ void writeImpl(const byte_t* const data, const size_t count)
{
if (::write(m_desc, data, count) == -1)
{
@@ -127,11 +134,6 @@ public:
}
}
- void flush()
- {
- ::fsync(m_desc);
- }
-
private:
const int m_desc;
@@ -159,13 +161,13 @@ public:
// Do nothing: unsupported
}
- size_type skip(const size_type count)
+ size_t skip(const size_t count)
{
// TODO: not tested
- value_type buffer[4096];
+ byte_t buffer[4096];
- int bytesSkipped = 0;
- int bytesRead = 0;
+ ssize_t bytesSkipped = 0;
+ ssize_t bytesRead = 0;
while ((bytesRead = ::read(m_desc, buffer,
std::min(sizeof(buffer), count - bytesSkipped))) != 0)
@@ -179,12 +181,12 @@ public:
bytesSkipped += bytesRead;
}
- return static_cast <size_type>(bytesSkipped);
+ return static_cast <size_t>(bytesSkipped);
}
- size_type read(value_type* const data, const size_type count)
+ size_t read(byte_t* const data, const size_t count)
{
- int bytesRead = 0;
+ ssize_t bytesRead = 0;
if ((bytesRead = ::read(m_desc, data, count)) == -1)
{
@@ -194,7 +196,7 @@ public:
m_eof = (bytesRead == 0);
- return static_cast <size_type>(bytesRead);
+ return static_cast <size_t>(bytesRead);
}
private:
diff --git a/src/platforms/posix/posixFile.cpp b/src/platforms/posix/posixFile.cpp
index 1e4dd070..9387414d 100644
--- a/src/platforms/posix/posixFile.cpp
+++ b/src/platforms/posix/posixFile.cpp
@@ -97,7 +97,7 @@ void posixFileIterator::getNextElement()
while ((m_dirEntry = ::readdir(m_dir)) != NULL)
{
const char* name = m_dirEntry->d_name;
- const int len = ::strlen(name);
+ const size_t len = ::strlen(name);
if (!(len == 1 && name[0] == '.') &&
!(len == 2 && name[0] == '.' && name[1] == '.'))
@@ -128,9 +128,10 @@ posixFileWriterOutputStream::~posixFileWriterOutputStream()
}
-void posixFileWriterOutputStream::write(const value_type* const data, const size_type count)
+void posixFileWriterOutputStream::writeImpl
+ (const byte_t* const data, const size_t count)
{
- const value_type* array = data;
+ const byte_t* array = data;
size_t size = count;
while (1)
@@ -196,8 +197,8 @@ void posixFileReaderInputStream::reset()
}
-vmime::utility::stream::size_type posixFileReaderInputStream::read
- (value_type* const data, const size_type count)
+size_t posixFileReaderInputStream::read
+ (byte_t* const data, const size_t count)
{
ssize_t c = 0;
@@ -207,11 +208,11 @@ vmime::utility::stream::size_type posixFileReaderInputStream::read
if (c == 0 && count != 0)
m_eof = true;
- return static_cast <size_type>(c);
+ return static_cast <size_t>(c);
}
-vmime::utility::stream::size_type posixFileReaderInputStream::skip(const size_type count)
+size_t posixFileReaderInputStream::skip(const size_t count)
{
const off_t curPos = ::lseek(m_fd, 0, SEEK_CUR);
@@ -223,22 +224,22 @@ vmime::utility::stream::size_type posixFileReaderInputStream::skip(const size_ty
if (newPos == off_t(-1))
posixFileSystemFactory::reportError(m_path, errno);
- return static_cast <size_type>(newPos - curPos);
+ return static_cast <size_t>(newPos - curPos);
}
-vmime::utility::stream::size_type posixFileReaderInputStream::getPosition() const
+size_t posixFileReaderInputStream::getPosition() const
{
const off_t curPos = ::lseek(m_fd, 0, SEEK_CUR);
if (curPos == off_t(-1))
posixFileSystemFactory::reportError(m_path, errno);
- return static_cast <size_type>(curPos);
+ return static_cast <size_t>(curPos);
}
-void posixFileReaderInputStream::seek(const size_type pos)
+void posixFileReaderInputStream::seek(const size_t pos)
{
const off_t newPos = ::lseek(m_fd, pos, SEEK_SET);
@@ -528,8 +529,8 @@ const vmime::string posixFileSystemFactory::pathToString(const vmime::utility::f
const vmime::utility::file::path posixFileSystemFactory::stringToPathImpl(const vmime::string& str)
{
- vmime::string::size_type offset = 0;
- vmime::string::size_type prev = 0;
+ vmime::size_t offset = 0;
+ vmime::size_t prev = 0;
vmime::utility::file::path path;
diff --git a/src/platforms/posix/posixHandler.cpp b/src/platforms/posix/posixHandler.cpp
index b5d08ce6..7ab0341a 100644
--- a/src/platforms/posix/posixHandler.cpp
+++ b/src/platforms/posix/posixHandler.cpp
@@ -181,7 +181,7 @@ static inline bool isFQDN(const vmime::string& str)
if (utility::stringUtils::isStringEqualNoCase(str, "localhost", 9))
return false;
- const vmime::string::size_type p = str.find_first_of(".");
+ const vmime::size_t p = str.find_first_of(".");
return p != vmime::string::npos && p > 0 && p != str.length() - 1;
}
diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp
index e0bcf03a..eb00beb6 100644
--- a/src/platforms/posix/posixSocket.cpp
+++ b/src/platforms/posix/posixSocket.cpp
@@ -40,6 +40,8 @@
#include <errno.h>
#include <string.h>
+#include "vmime/utility/stringUtils.hpp"
+
#include "vmime/exception.hpp"
@@ -426,7 +428,7 @@ const string posixSocket::getPeerName() const
}
-posixSocket::size_type posixSocket::getBlockSize() const
+size_t posixSocket::getBlockSize() const
{
return 16384; // 16 KB
}
@@ -434,12 +436,12 @@ posixSocket::size_type posixSocket::getBlockSize() const
void posixSocket::receive(vmime::string& buffer)
{
- const size_type size = receiveRaw(m_buffer, sizeof(m_buffer));
- buffer = vmime::string(m_buffer, size);
+ const size_t size = receiveRaw(m_buffer, sizeof(m_buffer));
+ buffer = utility::stringUtils::makeStringFromBytes(m_buffer, size);
}
-posixSocket::size_type posixSocket::receiveRaw(char* buffer, const size_type count)
+size_t posixSocket::receiveRaw(byte_t* buffer, const size_t count)
{
m_status &= ~STATUS_WOULDBLOCK;
@@ -529,15 +531,21 @@ posixSocket::size_type posixSocket::receiveRaw(char* buffer, const size_type cou
void posixSocket::send(const vmime::string& buffer)
{
- sendRaw(buffer.data(), buffer.length());
+ sendRaw(reinterpret_cast <const byte_t*>(buffer.data()), buffer.length());
+}
+
+
+void posixSocket::send(const char* str)
+{
+ sendRaw(reinterpret_cast <const byte_t*>(str), ::strlen(str));
}
-void posixSocket::sendRaw(const char* buffer, const size_type count)
+void posixSocket::sendRaw(const byte_t* buffer, const size_t count)
{
m_status &= ~STATUS_WOULDBLOCK;
- size_type size = count;
+ size_t size = count;
while (size > 0)
{
@@ -563,7 +571,7 @@ void posixSocket::sendRaw(const char* buffer, const size_type count)
}
-posixSocket::size_type posixSocket::sendRawNonBlocking(const char* buffer, const size_type count)
+size_t posixSocket::sendRawNonBlocking(const byte_t* buffer, const size_t count)
{
m_status &= ~STATUS_WOULDBLOCK;