diff options
Diffstat (limited to 'src/platforms')
-rw-r--r-- | src/platforms/posix/posixChildProcess.cpp | 30 | ||||
-rw-r--r-- | src/platforms/posix/posixFile.cpp | 27 | ||||
-rw-r--r-- | src/platforms/posix/posixHandler.cpp | 2 | ||||
-rw-r--r-- | src/platforms/posix/posixSocket.cpp | 24 | ||||
-rw-r--r-- | src/platforms/windows/windowsFile.cpp | 18 | ||||
-rw-r--r-- | src/platforms/windows/windowsHandler.cpp | 2 | ||||
-rw-r--r-- | src/platforms/windows/windowsSocket.cpp | 20 |
7 files changed, 70 insertions, 53 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; diff --git a/src/platforms/windows/windowsFile.cpp b/src/platforms/windows/windowsFile.cpp index 8d2a19da..6aa0fea8 100644 --- a/src/platforms/windows/windowsFile.cpp +++ b/src/platforms/windows/windowsFile.cpp @@ -61,8 +61,8 @@ const vmime::string windowsFileSystemFactory::pathToString(const vmime::utility: const vmime::utility::file::path windowsFileSystemFactory::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; @@ -117,7 +117,7 @@ bool windowsFileSystemFactory::isValidPathComponent( } // Check for invalid characters - for (string::size_type i = 0 ; i < buffer.length() ; ++i) + for (size_t i = 0 ; i < buffer.length() ; ++i) { const unsigned char c = buffer[i]; @@ -467,7 +467,7 @@ void windowsFileReaderInputStream::reset() SetFilePointer(m_hFile, 0, NULL, FILE_BEGIN); } -vmime::utility::stream::size_type windowsFileReaderInputStream::read(value_type* const data, const size_type count) +size_t windowsFileReaderInputStream::read(byte_t* const data, const size_t count) { DWORD dwBytesRead; if (!ReadFile(m_hFile, (LPVOID)data, (DWORD)count, &dwBytesRead, NULL)) @@ -475,24 +475,24 @@ vmime::utility::stream::size_type windowsFileReaderInputStream::read(value_type* return dwBytesRead; } -vmime::utility::stream::size_type windowsFileReaderInputStream::skip(const size_type count) +size_t windowsFileReaderInputStream::skip(const size_t count) { DWORD dwCurPos = SetFilePointer(m_hFile, 0, NULL, FILE_CURRENT); DWORD dwNewPos = SetFilePointer(m_hFile, (LONG)count, NULL, FILE_CURRENT); return (dwNewPos - dwCurPos); } -vmime::utility::stream::size_type windowsFileReaderInputStream::getPosition() const +size_t windowsFileReaderInputStream::getPosition() const { DWORD dwCurPos = SetFilePointer(m_hFile, 0, NULL, FILE_CURRENT); if (dwCurPos == INVALID_SET_FILE_POINTER) windowsFileSystemFactory::reportError(m_path, GetLastError()); - return static_cast <size_type>(dwCurPos); + return static_cast <size_t>(dwCurPos); } -void windowsFileReaderInputStream::seek(const size_type pos) +void windowsFileReaderInputStream::seek(const size_t pos) { DWORD dwNewPos = SetFilePointer(m_hFile, (LONG)pos, NULL, FILE_BEGIN); @@ -530,7 +530,7 @@ windowsFileWriterOutputStream::~windowsFileWriterOutputStream() CloseHandle(m_hFile); } -void windowsFileWriterOutputStream::write(const value_type* const data, const size_type count) +void windowsFileWriterOutputStream::writeImpl(const byte_t* const data, const size_t count) { DWORD dwBytesWritten; if (!WriteFile(m_hFile, data, (DWORD)count, &dwBytesWritten, NULL)) diff --git a/src/platforms/windows/windowsHandler.cpp b/src/platforms/windows/windowsHandler.cpp index 5b9c37ce..9c96b271 100644 --- a/src/platforms/windows/windowsHandler.cpp +++ b/src/platforms/windows/windowsHandler.cpp @@ -206,7 +206,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/windows/windowsSocket.cpp b/src/platforms/windows/windowsSocket.cpp index 502d1067..2cad21c0 100644 --- a/src/platforms/windows/windowsSocket.cpp +++ b/src/platforms/windows/windowsSocket.cpp @@ -230,7 +230,7 @@ const string windowsSocket::getPeerName() const } -windowsSocket::size_type windowsSocket::getBlockSize() const +size_t windowsSocket::getBlockSize() const { return 16384; // 16 KB } @@ -238,12 +238,12 @@ windowsSocket::size_type windowsSocket::getBlockSize() const void windowsSocket::receive(vmime::string& buffer) { - const size_type size = receiveRaw(m_buffer, sizeof(m_buffer)); + const size_t size = receiveRaw(m_buffer, sizeof(m_buffer)); buffer = vmime::string(m_buffer, size); } -windowsSocket::size_type windowsSocket::receiveRaw(char* buffer, const size_type count) +size_t windowsSocket::receiveRaw(char* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; @@ -307,15 +307,21 @@ windowsSocket::size_type windowsSocket::receiveRaw(char* buffer, const size_type void windowsSocket::send(const vmime::string& buffer) { - sendRaw(buffer.data(), buffer.length()); + sendRaw(reinterpret_cast <const byte_t*>(buffer.data()), buffer.length()); } -void windowsSocket::sendRaw(const char* buffer, const size_type count) +void windowsSocket::send(const char* str) +{ + sendRaw(reinterpret_cast <const byte_t*>(str), strlen(str)); +} + + +void windowsSocket::sendRaw(const char* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; - size_type size = count; + size_t size = count; while (size > 0) { @@ -344,7 +350,7 @@ void windowsSocket::sendRaw(const char* buffer, const size_type count) } -windowsSocket::size_type windowsSocket::sendRawNonBlocking(const char* buffer, const size_type count) +size_t windowsSocket::sendRawNonBlocking(const char* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; |