Merge branch 'master' into events

This commit is contained in:
Lourens Naudé 2012-05-11 22:08:17 +01:00
commit d0461752ff
10 changed files with 183 additions and 35 deletions

1
.gitignore vendored
View File

@ -39,6 +39,7 @@ tests/test_invalid_rep
tests/test_msg_flags
tests/test_ts_context
tests/test_connect_resolve
tests/test_term_endpoint
src/platform.hpp*
src/stamp-h1
perf/local_lat

View File

@ -42,6 +42,7 @@
Name="VCCLCompilerTool"
AdditionalOptions="-DDLL_EXPORT -DFD_SETSIZE=1024 -D_CRT_SECURE_NO_WARNINGS"
Optimization="0"
PreprocessorDefinitions="NOMINMAX"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@ -258,10 +259,18 @@
RelativePath="..\..\..\src\ctx.cpp"
>
</File>
<File
RelativePath="..\..\..\src\dealer.cpp"
>
</File>
<File
RelativePath="..\..\..\src\decoder.cpp"
>
</File>
<File
RelativePath="..\..\..\src\device.cpp"
>
</File>
<File
RelativePath="..\..\..\src\devpoll.cpp"
>
@ -402,6 +411,10 @@
RelativePath="..\..\..\src\req.cpp"
>
</File>
<File
RelativePath="..\..\..\src\router.cpp"
>
</File>
<File
RelativePath="..\..\..\src\select.cpp"
>
@ -450,14 +463,6 @@
RelativePath="..\..\..\src\xpub.cpp"
>
</File>
<File
RelativePath="..\..\..\src\xrep.cpp"
>
</File>
<File
RelativePath="..\..\..\src\xreq.cpp"
>
</File>
<File
RelativePath="..\..\..\src\xsub.cpp"
>

View File

@ -106,7 +106,9 @@
<ClCompile Include="..\..\..\src\address.cpp" />
<ClCompile Include="..\..\..\src\clock.cpp" />
<ClCompile Include="..\..\..\src\ctx.cpp" />
<ClCompile Include="..\..\..\src\dealer.cpp" />
<ClCompile Include="..\..\..\src\decoder.cpp" />
<ClCompile Include="..\..\..\src\device.cpp" />
<ClCompile Include="..\..\..\src\devpoll.cpp" />
<ClCompile Include="..\..\..\src\dist.cpp" />
<ClCompile Include="..\..\..\src\encoder.cpp" />
@ -144,6 +146,7 @@
<ClCompile Include="..\..\..\src\reaper.cpp" />
<ClCompile Include="..\..\..\src\rep.cpp" />
<ClCompile Include="..\..\..\src\req.cpp" />
<ClCompile Include="..\..\..\src\router.cpp" />
<ClCompile Include="..\..\..\src\select.cpp" />
<ClCompile Include="..\..\..\src\session_base.cpp" />
<ClCompile Include="..\..\..\src\signaler.cpp" />
@ -156,8 +159,6 @@
<ClCompile Include="..\..\..\src\thread.cpp" />
<ClCompile Include="..\..\..\src\trie.cpp" />
<ClCompile Include="..\..\..\src\xpub.cpp" />
<ClCompile Include="..\..\..\src\xrep.cpp" />
<ClCompile Include="..\..\..\src\xreq.cpp" />
<ClCompile Include="..\..\..\src\xsub.cpp" />
<ClCompile Include="..\..\..\src\zmq.cpp" />
<ClCompile Include="..\..\..\src\zmq_utils.cpp" />

65
doc/zmq_disconnect.txt Normal file
View File

@ -0,0 +1,65 @@
zmq_disconnect(3)
==============
NAME
----
zmq_disconnect - Disconnect a socket
SYNOPSIS
--------
int zmq_disconnect (void '*socket', const char '*endpoint');
DESCRIPTION
-----------
The _zmq_disconnect()_ function shall disconnect a socket specified
by the 'socket' argument from the endpoint specified by the 'endpoint'
argument.
The 'endpoint' argument is as described in linkzmq:zmq_connect[3]
RETURN VALUE
------------
The _zmq_disconnect()_ function shall return zero if successful. Otherwise it
shall return `-1` and set 'errno' to one of the values defined below.
ERRORS
------
*EINVAL*::
The endpoint supplied is invalid.
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*ENOTSOCK*::
The provided 'socket' was invalid.
EXAMPLE
-------
.Connecting a subscriber socket to an in-process and a TCP transport
----
/* Create a ZMQ_SUB socket */
void *socket = zmq_socket (context, ZMQ_SUB);
assert (socket);
/* Connect it to the host server001, port 5555 using a TCP transport */
rc = zmq_connect (socket, "tcp://server001:5555");
assert (rc == 0);
/* Disconnect from the previously connected endpoint */
rc = zmq_disconnect (socket, "tcp://server001:5555");
assert (rc == 0);
----
SEE ALSO
--------
linkzmq:zmq_connect[3]
linkzmq:zmq_socket[3]
linkzmq:zmq[7]
AUTHORS
-------
This 0MQ manual page was written by Martin Sustrik <sustrik@250bpm.com>,
Martin Lucina <mato@kotelna.sk> and Ian Barber <ian.barber@gmail.com>

65
doc/zmq_unbind.txt Normal file
View File

@ -0,0 +1,65 @@
zmq_unbind(3)
==============
NAME
----
zmq_unbind - Stop accepting connections on a socket
SYNOPSIS
--------
int zmq_unbind (void '*socket', const char '*endpoint');
DESCRIPTION
-----------
The _zmq_unbind()_ function shall unbind a socket specified
by the 'socket' argument from the endpoint specified by the 'endpoint'
argument.
The 'endpoint' argument is as described in linkzmq:zmq_bind[3]
RETURN VALUE
------------
The _zmq_unbind()_ function shall return zero if successful. Otherwise it
shall return `-1` and set 'errno' to one of the values defined below.
ERRORS
------
*EINVAL*::
The endpoint supplied is invalid.
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*ENOTSOCK*::
The provided 'socket' was invalid.
EXAMPLE
-------
.Unbind a subscriber socket from a TCP transport
----
/* Create a ZMQ_SUB socket */
void *socket = zmq_socket (context, ZMQ_SUB);
assert (socket);
/* Connect it to the host server001, port 5555 using a TCP transport */
rc = zmq_bind (socket, "tcp://127.0.0.1:5555");
assert (rc == 0);
/* Disconnect from the previously connected endpoint */
rc = zmq_unbind (socket, "tcp://127.0.0.1:5555");
assert (rc == 0);
----
SEE ALSO
--------
linkzmq:zmq_bind[3]
linkzmq:zmq_socket[3]
linkzmq:zmq[7]
AUTHORS
-------
This 0MQ manual page was written by Martin Sustrik <sustrik@250bpm.com>,
Martin Lucina <mato@kotelna.sk> and Ian Barber <ian.barber@gmail.com>

View File

@ -51,7 +51,7 @@ bool zmq::encoder_t::size_ready ()
{
// Write message body into the buffer.
next_step (in_progress.data (), in_progress.size (),
&encoder_t::message_ready, false);
&encoder_t::message_ready, !(in_progress.flags () & msg_t::more));
return true;
}
@ -90,15 +90,13 @@ bool zmq::encoder_t::message_ready ()
if (size < 255) {
tmpbuf [0] = (unsigned char) size;
tmpbuf [1] = (in_progress.flags () & msg_t::more);
next_step (tmpbuf, 2, &encoder_t::size_ready,
!(in_progress.flags () & msg_t::more));
next_step (tmpbuf, 2, &encoder_t::size_ready, false);
}
else {
tmpbuf [0] = 0xff;
put_uint64 (tmpbuf + 1, size);
tmpbuf [9] = (in_progress.flags () & msg_t::more);
next_step (tmpbuf, 10, &encoder_t::size_ready,
!(in_progress.flags () & msg_t::more));
next_step (tmpbuf, 10, &encoder_t::size_ready, false);
}
return true;
}

View File

@ -69,29 +69,24 @@ namespace zmq
unsigned char *buffer = !*data_ ? buf : *data_;
size_t buffersize = !*data_ ? bufsize : *size_;
size_t pos = 0;
if (offset_)
*offset_ = -1;
while (true) {
size_t pos = 0;
while (pos < buffersize) {
// If there are no more data to return, run the state machine.
// If there are still no data, return what we already have
// in the buffer.
if (!to_write) {
if (!(static_cast <T*> (this)->*next) ()) {
*data_ = buffer;
*size_ = pos;
return;
}
// If beginning of the message was processed, adjust the
// first-message-offset.
if (beginning) {
// If we are to encode the beginning of a new message,
// adjust the message offset.
if (beginning)
if (offset_ && *offset_ == -1)
*offset_ = (int) pos;
beginning = false;
}
*offset_ = static_cast <int> (pos);
if (!(static_cast <T*> (this)->*next) ())
break;
}
// If there are no data in the buffer yet and we are able to
@ -118,12 +113,10 @@ namespace zmq
pos += to_copy;
write_pos += to_copy;
to_write -= to_copy;
if (pos == buffersize) {
*data_ = buffer;
*size_ = pos;
return;
}
}
*data_ = buffer;
*size_ = pos;
}
protected:

View File

@ -57,6 +57,12 @@ zmq::fd_t zmq::open_socket (int domain_, int type_, int protocol_)
errno_assert (rc != -1);
#endif
// On Windows, preventing sockets to be inherited by child processes.
#if defined ZMQ_HAVE_WINDOWS && defined HANDLE_FLAG_INHERIT
BOOL brc = SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
#endif
return s;
}

View File

@ -288,6 +288,10 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
*w_ = WSASocket (AF_INET, SOCK_STREAM, 0, NULL, 0, 0);
wsa_assert (*w_ != INVALID_SOCKET);
// On Windows, preventing sockets to be inherited by child processes.
BOOL brc = SetHandleInformation ((HANDLE) *w_, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
// Set TCP_NODELAY on writer socket.
rc = setsockopt (*w_, IPPROTO_TCP, TCP_NODELAY,
(char *)&tcp_nodelay, sizeof (tcp_nodelay));
@ -301,12 +305,16 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
*r_ = accept (listener, NULL, NULL);
wsa_assert (*r_ != INVALID_SOCKET);
// On Windows, preventing sockets to be inherited by child processes.
brc = SetHandleInformation ((HANDLE) *r_, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
// We don't need the listening socket anymore. Close it.
rc = closesocket (listener);
wsa_assert (rc != SOCKET_ERROR);
// Exit the critical section.
BOOL brc = SetEvent (sync);
brc = SetEvent (sync);
win_assert (brc != 0);
return 0;

View File

@ -173,6 +173,9 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
wsa_error_to_errno ();
return -1;
}
// On Windows, preventing sockets to be inherited by child processes.
BOOL brc = SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
#else
if (s == -1)
return -1;
@ -239,6 +242,9 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
WSAGetLastError () == WSAECONNRESET);
return retired_fd;
}
// On Windows, preventing sockets to be inherited by child processes.
BOOL brc = SetHandleInformation ((HANDLE) sock, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
#else
if (sock == -1) {
errno_assert (errno == EAGAIN || errno == EWOULDBLOCK ||