aboutsummaryrefslogtreecommitdiffstats
path: root/src/platforms/posix/posixHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/platforms/posix/posixHandler.cpp')
-rw-r--r--src/platforms/posix/posixHandler.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/platforms/posix/posixHandler.cpp b/src/platforms/posix/posixHandler.cpp
index 8629b1e2..50428b70 100644
--- a/src/platforms/posix/posixHandler.cpp
+++ b/src/platforms/posix/posixHandler.cpp
@@ -29,8 +29,10 @@
#include "vmime/platforms/posix/posixHandler.hpp"
-#include <time.h>
+#include "vmime/platforms/posix/posixCriticalSection.hpp"
+#include <time.h>
+#include <fcntl.h>
#include <unistd.h>
#include <locale.h>
#include <langinfo.h>
@@ -39,10 +41,15 @@
#include <sys/types.h>
#include <sys/stat.h>
+#if VMIME_HAVE_SYSCALL
+# include <sys/syscall.h>
+#endif
+
#include <netdb.h>
#include <string.h>
#include <cassert>
+#include <cstdlib>
#if VMIME_HAVE_PTHREAD
# include <pthread.h>
@@ -217,6 +224,18 @@ unsigned int posixHandler::getProcessId() const
}
+unsigned int posixHandler::getThreadId() const
+{
+#if VMIME_HAVE_GETTID
+ return static_cast <unsigned int>(::gettid());
+#elif VMIME_HAVE_SYSCALL && VMIME_HAVE_SYSCALL_GETTID
+ return static_cast <unsigned int>(::syscall(SYS_gettid));
+#else
+ #error We have no implementation of getThreadId() for this platform!
+#endif
+}
+
+
#if VMIME_HAVE_MESSAGING_FEATURES
ref <vmime::net::socketFactory> posixHandler::getSocketFactory()
@@ -261,6 +280,29 @@ void posixHandler::wait() const
}
+void posixHandler::generateRandomBytes(unsigned char* buffer, const unsigned int count)
+{
+ int fd = open("/dev/urandom", O_RDONLY);
+
+ if (fd != -1)
+ {
+ read(fd, buffer, count);
+ close(fd);
+ }
+ else // fallback
+ {
+ for (unsigned int i = 0 ; i < count ; ++i)
+ buffer[i] = static_cast <unsigned char>(rand() % 255);
+ }
+}
+
+
+ref <utility::sync::criticalSection> posixHandler::createCriticalSection()
+{
+ return vmime::create <posixCriticalSection>();
+}
+
+
} // posix
} // platforms
} // vmime