mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-09 15:26:04 +00:00
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)"
This commit is contained in:
parent
819bf785b7
commit
e7b12b3c2a
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user