Skip to content

Commit

Permalink
Merge pull request zeromq#7 from tberkey/master
Browse files Browse the repository at this point in the history
Updates from zeromq/libczmq project.
  • Loading branch information
Telford Berkey committed Apr 30, 2015
2 parents 2f32c08 + 3eac568 commit aea74b8
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 63 deletions.
10 changes: 0 additions & 10 deletions builds/cmake/platform.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,4 @@

#cmakedefine ZMQ_HAVE_WINDOWS

#ifdef ZMQ_HAVE_WINDOWS
#if defined _WIN32_WINNT && _WIN32_WINNT < 0x0600
#undef _WIN32_WINNT
#endif

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#endif

#endif
9 changes: 0 additions & 9 deletions builds/mingw32/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,4 @@

#define ZMQ_HAVE_WINDOWS

#if defined _WIN32_WINNT && _WIN32_WINNT < 0x0600
#undef _WIN32_WINNT
#endif

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif


#endif
8 changes: 0 additions & 8 deletions builds/msvc/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,4 @@

#define ZMQ_HAVE_WINDOWS

#if defined _WIN32_WINNT && _WIN32_WINNT < 0x0600
#undef _WIN32_WINNT
#endif

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif

#endif
8 changes: 2 additions & 6 deletions builds/qt-android/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ if [[ $ANDROID_BUILD_CLEAN ]]; then
fi

##
# Build libsodium from latest release tarball
# Build libsodium from latest master branch

(android_build_verify_so "libsodium.so" &> /dev/null) || {
rm -rf "${cache}/libsodium"
(cd "${cache}" && mkdir libsodium \
&& wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz\
-O "${cache}/libsodium.tar.gz" \
&& tar -C libsodium -xf libsodium.tar.gz --strip=1) || exit 1

(cd "${cache}" && git clone git://github.com/jedisct1/libsodium.git) || exit 1
(cd "${cache}/libsodium" && ./autogen.sh \
&& ./configure "${ANDROID_BUILD_OPTS[@]}" --disable-soname-versions \
&& make \
Expand Down
43 changes: 43 additions & 0 deletions src/condition_variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,47 @@

#include "windows.hpp"

// Condition variable is supported from Windows Vista only, to use condition variable define _WIN32_WINNT to 0x0600
#if _WIN32_WINNT < 0x0600

namespace zmq
{

class condition_variable_t
{
public:
inline condition_variable_t ()
{
zmq_assert(false);
}

inline ~condition_variable_t ()
{

}

inline int wait (mutex_t* mutex_, int timeout_ )
{
zmq_assert(false);
return -1;
}

inline void broadcast ()
{
zmq_assert(false);
}

private:

// Disable copy construction and assignment.
condition_variable_t (const condition_variable_t&);
void operator = (const condition_variable_t&);
};

}

#else

namespace zmq
{

Expand Down Expand Up @@ -79,6 +120,8 @@ namespace zmq

}

#endif

#else

#include <pthread.h>
Expand Down
2 changes: 1 addition & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
case ZMQ_IDENTITY:
// Identity is any binary string from 1 to 255 octets
if (optvallen_ > 0 && optvallen_ < 256) {
identity_size = optvallen_;
identity_size = (unsigned char) optvallen_;
memcpy (identity, optval_, identity_size);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plain_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ int zmq::plain_server_t::produce_error (msg_t *msg_) const
zmq_assert (rc == 0);
char *msg_data = static_cast <char *> (msg_->data ());
memcpy (msg_data, "\5ERROR", 6);
msg_data [6] = status_code.length ();
msg_data [6] = (char) status_code.length ();
memcpy (msg_data + 7, status_code.c_str (), status_code.length ());
return 0;
}
Expand Down
13 changes: 13 additions & 0 deletions src/pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

#include "pub.hpp"
#include "pipe.hpp"
#include "err.hpp"
#include "msg.hpp"

zmq::pub_t::pub_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
Expand All @@ -30,6 +32,17 @@ zmq::pub_t::~pub_t ()
{
}

void zmq::pub_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
{
zmq_assert (pipe_);

// Don't delay pipe termination as there is no one
// to receive the delimiter.
pipe_->set_nodelay ();

xpub_t::xattach_pipe (pipe_, subscribe_to_all_);
}

int zmq::pub_t::xrecv (class msg_t *)
{
// Messages cannot be received from PUB socket.
Expand Down
1 change: 1 addition & 0 deletions src/pub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace zmq
~pub_t ();

// Implementations of virtual functions from socket_base_t.
void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_ = false);
int xrecv (zmq::msg_t *msg_);
bool xhas_in ();

Expand Down
3 changes: 3 additions & 0 deletions src/push.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ void zmq::push_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
{
// subscribe_to_all_ is unused
(void)subscribe_to_all_;
// Don't delay pipe termination as there is no one
// to receive the delimiter.
pipe_->set_nodelay ();

zmq_assert (pipe_);
lb.attach (pipe_);
Expand Down
19 changes: 11 additions & 8 deletions src/socks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ zmq::socks_greeting_t::socks_greeting_t (uint8_t method_) :
}

zmq::socks_greeting_t::socks_greeting_t (
uint8_t *methods_, size_t num_methods_)
uint8_t *methods_, uint8_t num_methods_)
: num_methods (num_methods_)
{
zmq_assert (num_methods_ <= 255);

for (size_t i = 0; i < num_methods_; i++)
for (uint8_t i = 0; i < num_methods_; i++)
methods [i] = methods_ [i];
}

Expand All @@ -55,8 +53,8 @@ void zmq::socks_greeting_encoder_t::encode (const socks_greeting_t &greeting_)
uint8_t *ptr = buf;

*ptr++ = 0x05;
*ptr++ = greeting_.num_methods;
for (size_t i = 0; i < greeting_.num_methods; i++)
*ptr++ = (uint8_t) greeting_.num_methods;
for (uint8_t i = 0; i < greeting_.num_methods; i++)
*ptr++ = greeting_.methods [i];

bytes_encoded = 2 + greeting_.num_methods;
Expand Down Expand Up @@ -118,17 +116,22 @@ void zmq::socks_choice_decoder_t::reset ()
bytes_read = 0;
}


zmq::socks_request_t::socks_request_t (
uint8_t command_, std::string hostname_, uint16_t port_)
: command (command_), hostname (hostname_), port (port_)
{}
{
zmq_assert (hostname_.size () <= UINT8_MAX);
}

zmq::socks_request_encoder_t::socks_request_encoder_t ()
: bytes_encoded (0), bytes_written (0)
{}

void zmq::socks_request_encoder_t::encode (const socks_request_t &req)
{
zmq_assert (req.hostname.size() <= UINT8_MAX);

unsigned char *ptr = buf;
*ptr++ = 0x05;
*ptr++ = req.command;
Expand Down Expand Up @@ -163,7 +166,7 @@ void zmq::socks_request_encoder_t::encode (const socks_request_t &req)
}
else {
*ptr++ = 0x03;
*ptr++ = req.hostname.size ();
*ptr++ = (unsigned char) req.hostname.size ();
memcpy (ptr, req.hostname.c_str (), req.hostname.size ());
ptr += req.hostname.size ();
}
Expand Down
10 changes: 5 additions & 5 deletions src/socks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ namespace zmq
struct socks_greeting_t
{
socks_greeting_t (uint8_t method);
socks_greeting_t (uint8_t *methods_, size_t num_methods_);
socks_greeting_t (uint8_t *methods_, uint8_t num_methods_);

uint8_t methods [255];
uint8_t methods [UINT8_MAX];
const size_t num_methods;
};

Expand All @@ -48,7 +48,7 @@ namespace zmq
private:
size_t bytes_encoded;
size_t bytes_written;
uint8_t buf [2 + 255];
uint8_t buf [2 + UINT8_MAX];
};

struct socks_choice_t
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace zmq
private:
size_t bytes_encoded;
size_t bytes_written;
uint8_t buf [4 + 256 + 2];
uint8_t buf [4 + UINT8_MAX + 1 + 2];
};

struct socks_response_t
Expand All @@ -116,7 +116,7 @@ namespace zmq
void reset ();

private:
uint8_t buf [4 + 256 + 2];
int8_t buf [4 + UINT8_MAX + 1 + 2];
size_t bytes_read;
};

Expand Down
6 changes: 3 additions & 3 deletions src/socks_connecter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void zmq::socks_connecter_t::in_event ()
// Attach the engine to the corresponding session object.
send_attach (session, engine);

socket->event_connected (endpoint, s);
socket->event_connected (endpoint, (int) s);

rm_fd (handle);
s = -1;
Expand All @@ -170,7 +170,7 @@ void zmq::socks_connecter_t::out_event ()
|| status == sending_request);

if (status == waiting_for_proxy_connection) {
const int rc = check_proxy_connection ();
const int rc = (int) check_proxy_connection ();
if (rc == -1)
error ();
else {
Expand Down Expand Up @@ -436,7 +436,7 @@ void zmq::socks_connecter_t::close ()
const int rc = ::close (s);
errno_assert (rc == 0);
#endif
socket->event_closed (endpoint, s);
socket->event_closed (endpoint, (int) s);
s = retired_fd;
}

Expand Down
4 changes: 4 additions & 0 deletions src/stdint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ typedef unsigned __int64 uint64_t;

#endif

#ifndef UINT8_MAX
#define UINT8_MAX 0xFF
#endif

#endif
5 changes: 2 additions & 3 deletions src/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,13 @@ void zmq::stream_t::identify_peer (pipe_t *pipe_)
connect_rid.length ());
connect_rid.clear ();
outpipes_t::iterator it = outpipes.find (identity);
if (it != outpipes.end ())
zmq_assert(false);
zmq_assert (it == outpipes.end ());
}
else {
put_uint32 (buffer + 1, next_rid++);
identity = blob_t (buffer, sizeof buffer);
memcpy (options.identity, identity.data (), identity.size ());
options.identity_size = identity.size ();
options.identity_size = (unsigned char) identity.size ();
}
pipe_->set_identity (identity);
// Add the record into output pipes lookup table
Expand Down
2 changes: 1 addition & 1 deletion src/stream_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ void zmq::stream_engine_t::error (error_reason_t reason)
terminator.close();
}
zmq_assert (session);
socket->event_disconnected (endpoint, s);
socket->event_disconnected (endpoint, (int) s);
session->flush ();
session->engine_error (reason);
unplug ();
Expand Down
4 changes: 2 additions & 2 deletions src/tcp_connecter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void zmq::tcp_connecter_t::out_event ()
// Shut the connecter down.
terminate ();

socket->event_connected (endpoint, fd);
socket->event_connected (endpoint, (int) fd);
}

void zmq::tcp_connecter_t::timer_event (int id_)
Expand Down Expand Up @@ -352,6 +352,6 @@ void zmq::tcp_connecter_t::close ()
const int rc = ::close (s);
errno_assert (rc == 0);
#endif
socket->event_closed (endpoint, s);
socket->event_closed (endpoint, (int) s);
s = retired_fd;
}
6 changes: 3 additions & 3 deletions src/tcp_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void zmq::tcp_listener_t::in_event ()
session->inc_seqnum ();
launch_child (session);
send_attach (session, engine, false);
socket->event_accepted (endpoint, fd);
socket->event_accepted (endpoint, (int) fd);
}

void zmq::tcp_listener_t::close ()
Expand All @@ -124,7 +124,7 @@ void zmq::tcp_listener_t::close ()
int rc = ::close (s);
errno_assert (rc == 0);
#endif
socket->event_closed (endpoint, s);
socket->event_closed (endpoint, (int) s);
s = retired_fd;
}

Expand Down Expand Up @@ -239,7 +239,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
goto error;
#endif

socket->event_listening (endpoint, s);
socket->event_listening (endpoint, (int) s);
return 0;

error:
Expand Down
4 changes: 2 additions & 2 deletions src/windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#define NOMINMAX // Macros min(a,b) and max(a,b)
#endif

// Set target version to Windows Server 2003, Windows XP/SP1 or higher.
// Set target version to Windows Server 2008, Windows Vista or higher. Windows XP (0x0501) is also supported but without client & server socket types.
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#define _WIN32_WINNT 0x0600
#endif

#ifdef __MINGW32__
Expand Down
Loading

0 comments on commit aea74b8

Please sign in to comment.