Commit b1035b56 authored by Dominik Charousset's avatar Dominik Charousset

fixed includes + minor issues in MinGW build

parent a1a11c74
...@@ -140,7 +140,7 @@ std::unique_ptr<T> create_unique(Args&&... args) { ...@@ -140,7 +140,7 @@ std::unique_ptr<T> create_unique(Args&&... args) {
constexpr SOCKET invalid_socket = INVALID_SOCKET; constexpr SOCKET invalid_socket = INVALID_SOCKET;
inline int last_socket_error() { return WSAGetLastError(); } inline int last_socket_error() { return WSAGetLastError(); }
inline bool would_block_or_temporarily_unavailable(int errcode) { inline bool would_block_or_temporarily_unavailable(int errcode) {
return errcode == WSAEWOULDBLOCK || errcode = WSATRY_AGAIN; return errcode == WSAEWOULDBLOCK || errcode == WSATRY_AGAIN;
} }
#else #else
typedef int native_socket_type; typedef int native_socket_type;
......
...@@ -32,9 +32,8 @@ ...@@ -32,9 +32,8 @@
#include <sstream> #include <sstream>
#include <cstring> #include <cstring>
// socket related functions #include "cppa/config.hpp"
#include <sys/types.h> #include "cppa/exception.hpp"
#include <sys/socket.h>
#ifdef CPPA_WINDOWS #ifdef CPPA_WINDOWS
# include <winsock2.h> # include <winsock2.h>
...@@ -42,6 +41,8 @@ ...@@ -42,6 +41,8 @@
# include <windows.h> # include <windows.h>
# include <io.h> # include <io.h>
#else #else
# include <sys/types.h>
# include <sys/socket.h>
# include <errno.h> # include <errno.h>
# include <netdb.h> # include <netdb.h>
# include <fcntl.h> # include <fcntl.h>
...@@ -49,7 +50,8 @@ ...@@ -49,7 +50,8 @@
# include <netinet/tcp.h> # include <netinet/tcp.h>
#endif #endif
#include "cppa/exception.hpp" #include "cppa/util/scope_guard.hpp"
#include "cppa/detail/fd_util.hpp" #include "cppa/detail/fd_util.hpp"
/************** implementation of platform-independent functions **************/ /************** implementation of platform-independent functions **************/
...@@ -68,7 +70,8 @@ void throw_io_failure(const char* what, bool add_errno_failure) { ...@@ -68,7 +70,8 @@ void throw_io_failure(const char* what, bool add_errno_failure) {
void tcp_nodelay(native_socket_type fd, bool new_value) { void tcp_nodelay(native_socket_type fd, bool new_value) {
int flag = new_value ? 1 : 0; int flag = new_value ? 1 : 0;
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)) < 0) { if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<setsockopt_ptr>(&flag), sizeof(flag)) < 0) {
throw_io_failure("unable to set TCP_NODELAY"); throw_io_failure("unable to set TCP_NODELAY");
} }
} }
...@@ -128,6 +131,7 @@ namespace cppa { namespace detail { namespace fd_util { ...@@ -128,6 +131,7 @@ namespace cppa { namespace detail { namespace fd_util {
std::string last_socket_error_as_string() { std::string last_socket_error_as_string() {
LPTSTR errorText = NULL; LPTSTR errorText = NULL;
auto hresult = last_socket_error();
FormatMessage(// use system message tables to retrieve error text FormatMessage(// use system message tables to retrieve error text
FORMAT_MESSAGE_FROM_SYSTEM FORMAT_MESSAGE_FROM_SYSTEM
// allocate buffer on local heap for error text // allocate buffer on local heap for error text
...@@ -160,7 +164,7 @@ void nonblocking(native_socket_type fd, bool new_value) { ...@@ -160,7 +164,7 @@ void nonblocking(native_socket_type fd, bool new_value) {
// wraps a C call and throws an IO failure if f returns an integer != 0 // wraps a C call and throws an IO failure if f returns an integer != 0
template<typename F, typename... Ts> template<typename F, typename... Ts>
inline void ccall(const char* errmsg, F f, Ts&&... args) { inline void ccall(const char* errmsg, F f, Ts&&... args) {
if (f(std::forward<Ts>(args...)) != 0) { if (f(std::forward<Ts>(args)...) != 0) {
throw_io_failure(errmsg); throw_io_failure(errmsg);
} }
} }
......
...@@ -181,9 +181,6 @@ std::vector<std::string> get_mac_addresses() { ...@@ -181,9 +181,6 @@ std::vector<std::string> get_mac_addresses() {
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "cppa/singletons.hpp" #include "cppa/singletons.hpp"
#include "cppa/windows/windows_tcp.hpp"
// Link with Iphlpapi.lib
// #pragma comment(lib, "IPHLPAPI.lib") -liphlpapi
namespace { namespace {
......
...@@ -189,34 +189,51 @@ std::string get_root_uuid() { ...@@ -189,34 +189,51 @@ std::string get_root_uuid() {
#elif defined(CPPA_WINDOWS) #elif defined(CPPA_WINDOWS)
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <windows.h>
#include <tchar.h>
using namespace std; using namespace std;
namespace cppa { namespace util { namespace cppa { namespace util {
namespace { constexpr size_t max_drive_name = MAX_PATH; } namespace { constexpr size_t max_drive_name = MAX_PATH; }
// if TCHAR is indeed a char, we can simply move rhs
void mv(std::string& lhs, std::string&& rhs) {
lhs = std::move(rhs);
}
// if TCHAR is defined as WCHAR, we have to do unicode conversion
void mv(std::string& lhs, const std::basic_string<WCHAR>& rhs) {
auto size_needed = WideCharToMultiByte(CP_UTF8, 0, rhs.c_str(),
static_cast<int>(rhs.size()),
nullptr, 0, nullptr, nullptr);
lhs.resize(size_needed);
WideCharToMultiByte(CP_UTF8, 0, rhs.c_str(), static_cast<int>(rhs.size()),
&lhs[0], size_needed, nullptr, nullptr);
}
std::string get_root_uuid() { std::string get_root_uuid() {
typedef std::basic_string<TCHAR> tchar_str;
string uuid; string uuid;
char drive_name[max_drive_name]; // temporary buffer for volume name TCHAR buf[max_drive_name]; // temporary buffer for volume name
auto drive = TEXT("c:\\"); // string "template" for drive specifier tchar_str drive = TEXT("c:\\"); // string "template" for drive specifier
// walk through legal drive letters, skipping floppies // walk through legal drive letters, skipping floppies
for (auto i = TEXT('c'); i < TEXT('z'); i++ ) { for (TCHAR i = TEXT('c'); i < TEXT('z'); i++ ) {
// Stamp the drive for the appropriate letter. // Stamp the drive for the appropriate letter.
drive[0] = i; drive[0] = i;
if (GetVolumeNameForVolumeMountPoint(drive, drive_name, max_drive_name)) { if (GetVolumeNameForVolumeMountPoint(drive.c_str(), buf, max_drive_name)) {
auto first = drive_name.find("Volume{"); tchar_str drive_name = buf;
auto first = drive_name.find(TEXT("Volume{"));
if (first != std::string::npos) { if (first != std::string::npos) {
first += 7; first += 7;
auto last = drive_name.find("}", first); auto last = drive_name.find(TEXT("}"), first);
if (last != std::string::npos && last > first) { if (last != std::string::npos && last > first) {
uuid = drive_name.substr(first, last - first); mv(uuid, drive_name.substr(first, last - first));
// UUIDs are formatted as 8-4-4-4-12 hex digits groups // UUIDs are formatted as 8-4-4-4-12 hex digits groups
auto cpy = uuid; auto cpy = uuid;
replace_if(cpy.begin(), cpy.end(), ::isxdigit, 'F'); replace_if(cpy.begin(), cpy.end(), ::isxdigit, 'F');
......
...@@ -45,8 +45,6 @@ ...@@ -45,8 +45,6 @@
#ifdef CPPA_WINDOWS #ifdef CPPA_WINDOWS
# include <winsock2.h> # include <winsock2.h>
# include <ws2tcpip.h> # include <ws2tcpip.h>
# include "cppa/singletons.hpp"
# include "cppa/windows/windows_tcp.hpp"
#else #else
# include <netdb.h> # include <netdb.h>
# include <unistd.h> # include <unistd.h>
...@@ -82,40 +80,13 @@ struct socket_guard { ...@@ -82,40 +80,13 @@ struct socket_guard {
}; };
#ifdef CPPA_WINDOWS
inline native_socket_type do_accept(native_socket_type fd,
sockaddr* addr,
socklen_t* addrlen) {
return ::WSAAccept(fd, addr, addrlen, 0, 0)
}
#else
inline native_socket_type do_accept(native_socket_type fd,
sockaddr* addr,
socklen_t* addrlen) {
return ::accept(fd, addr, addrlen);
}
#endif
bool accept_impl(stream_ptr_pair& result, bool accept_impl(stream_ptr_pair& result,
native_socket_type fd, native_socket_type fd,
bool nonblocking) { bool nonblocking) {
/*
sockaddr addr;
memset(&addr, 0, sizeof(addr));
*/
//socklen_t addrlen = sizeof(addr);
/*
socklen_t addrlen;
memset(&addrlen, 0, sizeof(addrlen));
# ifdef CPPA_WINDOWS
addrlen = sizeof(addr);
# endif
*/
sockaddr addr; sockaddr addr;
socklen_t addrlen;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
memset(&addrlen, 0, sizeof(addrlen)); socklen_t addrlen = sizeof(addr);
auto sfd = do_accept(fd, &addr, &addrlen); auto sfd = ::accept(fd, &addr, &addrlen);
if (sfd == invalid_socket) { if (sfd == invalid_socket) {
auto err = last_socket_error(); auto err = last_socket_error();
if (nonblocking && would_block_or_temporarily_unavailable(err)) { if (nonblocking && would_block_or_temporarily_unavailable(err)) {
......
...@@ -79,7 +79,7 @@ using namespace std; ...@@ -79,7 +79,7 @@ using namespace std;
namespace cppa { namespace io { namespace cppa { namespace io {
void notify_queue_event(native_socket_type fd) { void notify_queue_event(native_socket_type fd) {
uint8_t dummy = 0; char dummy = 0;
// on unix, we have file handles, on windows, we actually have sockets // on unix, we have file handles, on windows, we actually have sockets
# ifdef CPPA_WINDOWS # ifdef CPPA_WINDOWS
auto res = ::send(fd, &dummy, sizeof(dummy), 0); auto res = ::send(fd, &dummy, sizeof(dummy), 0);
...@@ -92,7 +92,7 @@ void notify_queue_event(native_socket_type fd) { ...@@ -92,7 +92,7 @@ void notify_queue_event(native_socket_type fd) {
size_t num_queue_events(native_socket_type fd) { size_t num_queue_events(native_socket_type fd) {
static constexpr size_t num_dummies = 64; static constexpr size_t num_dummies = 64;
uint8_t dummies[num_dummies]; char dummies[num_dummies];
// on unix, we have file handles, on windows, we actually have sockets // on unix, we have file handles, on windows, we actually have sockets
# ifdef CPPA_WINDOWS # ifdef CPPA_WINDOWS
auto read_result = ::recv(fd, dummies, num_dummies, 0); auto read_result = ::recv(fd, dummies, num_dummies, 0);
......
...@@ -111,9 +111,9 @@ void middleman_event_handler::update() { ...@@ -111,9 +111,9 @@ void middleman_event_handler::update() {
CPPA_LOG_DEBUG("new bitmask for " CPPA_LOG_DEBUG("new bitmask for "
<< elem.ptr << ": " << eb2str(mask)); << elem.ptr << ": " << eb2str(mask));
if (iter == last || iter->fd != elem.fd) { if (iter == last || iter->fd != elem.fd) {
CPPA_LOG_ERROR_IF(mask == event::none,
"cannot erase " << ptr << " (no such element)");
if (mask != event::none) { if (mask != event::none) {
// element has been removed from m_meta by an
// previous alteration but is not put back in
m_meta.insert(iter, elem); m_meta.insert(iter, elem);
handle_event(fd_meta_event::add, elem.fd, handle_event(fd_meta_event::add, elem.fd,
event::none, mask, ptr); event::none, mask, ptr);
...@@ -138,11 +138,13 @@ void middleman_event_handler::update() { ...@@ -138,11 +138,13 @@ void middleman_event_handler::update() {
// m_meta won't be touched inside loop // m_meta won't be touched inside loop
auto first = m_meta.begin(); auto first = m_meta.begin();
auto last = m_meta.end(); auto last = m_meta.end();
// checks whether an element can be safely deleted,
// i.e., was not put back into m_meta by some alteration
auto is_alive = [&](native_socket_type fd) -> bool { auto is_alive = [&](native_socket_type fd) -> bool {
auto iter = std::lower_bound(first, last, fd, mless); auto iter = std::lower_bound(first, last, fd, mless);
return iter != last && iter->fd == fd; return iter != last && iter->fd == fd;
}; };
// check whether elements in dispose list can be safely deleted // dispose everything that wasn't put back into m_meta again
for (auto elem : m_dispose_list) { for (auto elem : m_dispose_list) {
auto rd = elem->read_handle(); auto rd = elem->read_handle();
auto wr = elem->write_handle(); auto wr = elem->write_handle();
......
...@@ -833,8 +833,8 @@ void test_spawn() { ...@@ -833,8 +833,8 @@ void test_spawn() {
// create some actors linked to one single actor // create some actors linked to one single actor
// and kill them all through killing the link // and kill them all through killing the link
auto legion = spawn([](event_based_actor* self) { auto legion = spawn([](event_based_actor* self) {
CPPA_PRINT("spawn 1, 000 actors"); CPPA_PRINT("spawn 100 actors");
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 100; ++i) {
self->spawn<event_testee, linked>(); self->spawn<event_testee, linked>();
} }
self->become(others() >> CPPA_UNEXPECTED_MSG_CB()); self->become(others() >> CPPA_UNEXPECTED_MSG_CB());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment