Commit e7b12b3c authored by Dmitriy-GH's avatar Dmitriy-GH

Add WinXP compatibility

#define ZMQ_HAVE_WINDOWS_TARGET_XP  disable uncompatible WinAPI

1. Disable call if_indextoname()
2. Emulate windows Condition Variable API in class condition_variable_t with std::condition_variable
 	
This code can be compiled in MSVC 2015 with option "Platform toolset: Visual Studio 2015 - Windows XP (v140_xp)"
parent 819bf785
......@@ -81,9 +81,15 @@ namespace zmq
#else
#ifdef ZMQ_HAVE_WINDOWS_TARGET_XP
#include <condition_variable>
#include <mutex>
#endif
namespace zmq
{
#ifndef ZMQ_HAVE_WINDOWS_TARGET_XP
class condition_variable_t
{
public:
......@@ -126,7 +132,54 @@ namespace zmq
condition_variable_t (const condition_variable_t&);
void operator = (const condition_variable_t&);
};
#else
class condition_variable_t
{
public:
inline condition_variable_t()
{
}
inline ~condition_variable_t()
{
}
inline int wait(mutex_t* mutex_, int timeout_)
{
std::unique_lock<std::mutex> lck(mtx); // lock mtx
mutex_->unlock(); // unlock mutex_
int res = 0;
if(timeout_ == -1) {
cv.wait(lck); // unlock mtx and wait cv.notify_all(), lock mtx after cv.notify_all()
} else if (cv.wait_for(lck, std::chrono::milliseconds(timeout_)) == std::cv_status::timeout) {
// time expired
errno = EAGAIN;
res = -1;
}
lck.unlock(); // unlock mtx
mutex_->lock(); // lock mutex_
return res;
}
inline void broadcast()
{
std::unique_lock<std::mutex> lck(mtx); // lock mtx
cv.notify_all();
}
private:
std::condition_variable cv;
std::mutex mtx;
// Disable copy construction and assignment.
condition_variable_t(const condition_variable_t&);
void operator = (const condition_variable_t&);
};
#endif
}
#endif
......
......@@ -245,7 +245,9 @@ int zmq::tcp_address_t::get_interface_name(unsigned long index, char ** dest) co
char * if_name_result = NULL;
#ifndef ZMQ_HAVE_WINDOWS_TARGET_XP
if_name_result = if_indextoname(index, buffer);
#endif
if (if_name_result == NULL) {
free(buffer);
......
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