Commit Graph

464 Commits

Author SHA1 Message Date
Joe Eli McIlvain
33419425eb Problem: Private/internal macros defined in public header.
Solution: Move the macros to a private header.
2015-08-21 16:12:22 -07:00
Joe Eli McIlvain
61217a2686 Problem: Source files contain mixed tabs and spaces.
Solution: Convert to spaces and remove trailing whitespace in these files.
2015-08-20 07:46:34 -07:00
reza.ebrahimi
1621c25ef0 define a macro for heap object deletion in a unified manner (related to issue #1524) 2015-08-17 00:35:11 +04:30
somdoron
a63818904d add methods to handle poller 2015-08-16 13:57:28 +03:00
somdoron
34968771ca add an option to check if the socket is thread safe 2015-08-16 11:50:50 +03:00
Rik van der Heijden
c68e9a39bf Merge fix for zeromq/zeromq4-1#52, getsockopt ZMQ_RCVMORE now resets all bits 2015-08-11 21:37:50 +02:00
Brian Silverman
773a06fc23 Fix memory leak when creating a socket fails.
Previously, AddressSanitizer flagged leaks when running
tests/test_many_sockets.cpp.
2015-07-22 11:18:48 -07:00
Constantin Rack
15f9ee19cb Solution: allow brackets in tcp ipv6 address 2015-06-23 08:54:49 +02:00
Richard Newton
15eecf4cf4 Update high water marking to allow changing high water mark after connection established. 2015-06-05 17:14:55 +01:00
Richard Newton
9f8b8af926 Fail ZMQ_SNDHWM and ZMQ_RCVHWM setsockopt if already connected. 2015-06-05 10:43:40 +01:00
Pieter Hintjens
a07244cda2 Merge pull request #1414 from hintjens/master
Problem: source file headers are somewhat confusing about LGPLv3
2015-06-02 23:40:52 +02:00
Pieter Hintjens
8620c3e032 Problem: source file headers are somewhat confusing about LGPLv3
Of course people still "can" distributed the sources under the
LGPLv3. However we provide COPYING.LESSER with additional grants.

Solution: specify these grants in the header of each source file.
2015-06-02 22:33:55 +02:00
ALEKSANDR MELNIKOV
1eb8e2a69f HPUX build and gmake check issues solution (#1412) 2015-06-02 20:17:15 +06:00
Constantin Rack
8a3296c1aa Solution: add missing brackets 2015-05-23 23:18:10 +02:00
somdoron
5a897f7509 allocate reaper_signal only when needed 2015-02-12 20:42:31 +02:00
somdoron
6749c9b3eb thread safety 2015-02-12 18:54:22 +02:00
somdoron
862cd41c65 implement client socket type and drop messages when more flag is set on client and server 2015-02-02 11:59:13 +02:00
somdoron
5632b57b4a adds server socket type and routing id to msg 2015-02-02 01:17:37 +02:00
Pieter Hintjens
94d9a4ffdf Problem: copyright statements are out of date
Solution: update for 2015

Fixes #1320
2015-01-22 10:32:37 +01:00
Thomas Rodgers
7c0a644625 Remove of ZMQ_IDENTITY_FD socket option
Revert "linking fd to pipe identity via socket option"

This reverts commit fe3e8c5c70.

Conflicts:
	include/zmq.h
	src/pipe.hpp
	src/session_base.cpp
2015-01-09 17:28:50 -06:00
Martin Hurton
905b1683c7 Fix issue #1257 2014-11-24 15:07:59 +01:00
Pieter Hintjens
b6e61d72b2 Problem: linger values other than -1 or 0 are unsafe
Solution: set defaults back to infinity, and add new context
option, ZMQ_BLOCKY that the user can set to false to get a
less surprising behavior on context termination. Eg.

    zmq_ctx_set (ctx, ZMQ_BLOCKY, false);
2014-11-17 11:56:59 +01:00
lysyloren
09e7416ee9 Unbind socket with real endpoint when binding by wild-card * address 2014-10-27 14:16:36 +01:00
Martin Hurton
a54d8d7b0c Reset metadata for outbound messages 2014-08-13 08:53:54 +02:00
Martin Hurton
816299f11c Code cleanup 2014-07-09 14:07:32 +02:00
Martin Hurton
54e0fde1cc Resolve issue #949 2014-07-09 10:02:53 +02:00
Pieter Hintjens
ce8fbb26cb Problem: zmq_connect doesn't return EINVAL on invalid endpoint
Solution: set errno to EINVAL when tcp:// endpoint is invalid (was just
leaving errno to previous value).
2014-06-25 12:48:26 +02:00
Pieter Hintjens
2524e26893 Code cleanups 2014-06-25 12:47:39 +02:00
Pieter Hintjens
deaad00ad9 Problem: zmq_connect() does not validate TCP addresses
Since https://github.com/zeromq/libzmq/commit/350a1a, TCP addresses
get resolved asynchronously, so zmq_connect no longer returned an
error on incorrect addresses.

This is troublesome since we rely on some error checking to catch
blatant errors.

Solution add some upfront syntax checking that catches at least the
obvious kinds of errors (invalid characters, wrong or missing port
number).
2014-06-24 14:33:38 +02:00
Martin Hurton
dd2be381ad Add const qualifier to register_endpoint param 2014-05-23 12:27:01 +02:00
Martin Hurton
414fc86b22 Code cleanup
- limit visibility of pending_connection_t
- add const qualifiers
2014-05-21 13:08:15 +02:00
Martin Hurton
5f4145e7cb Small code cleanup
- add const modifier to address parameter of event generating functions
2014-05-20 21:48:59 +02:00
Stoian Ivanov
d5991d6728 merge to upstream 2014-05-12 10:24:31 +03:00
Stoian Ivanov
fe3e8c5c70 linking fd to pipe identity via socket option 2014-04-30 16:34:55 +03:00
Pieter Hintjens
9753de8566 Problem: zmq_socket_monitor code is dirty
Specifically:

* zmq_event_t should not be used internally in libzmq, it was
  meant to be an outward facing structure.

* In 4.x, zmq_event_t does not correspond to monitor events, so
  I removed the structure entirely.

* man page for zmq_socket_monitor is incomplete and the example
  code was particularly nasty.

* test_monitor.cpp needed rewriting, it was not clean.
2014-04-28 11:30:49 +02:00
bebopagogo
33f22d0d04 added norm_engine 2014-03-15 10:48:12 -04:00
Mark Barbisan
350a1ac12b Allow TCP addresses to be re-resolved whenever there is a reconnection attempt 2014-03-12 13:28:37 -04:00
Pavel Pimenov
acfbfe53bc Fix build with ZMQ_HAVE_WINDOWS (typedef UINT_PTR fd_t; -> unsigned type)
V547 Expression 'file_desc >= 0' is always true. Unsigned type value is always >= 0. socket_base.cpp 845
  V547 Expression 'file_desc >= 0' is always true. Unsigned type value is always >= 0. socket_base.cpp 863
  V547 Expression 'file_desc >= 0' is always true. Unsigned type value is always >= 0. socket_base.cpp 897
  http://www.viva64.com/en/d/0137/print/
2014-02-21 13:22:53 +04:00
Pieter Hintjens
ab9349d3fe Revert "Fix potential memory leak"
This reverts commit 50d34e5653.
2014-02-11 18:30:08 +01:00
Martin Hurton
a09407829e Fix identity handling for inproc transport
Fixes #872
2014-02-09 21:02:00 +01:00
Alex Pyrgiotis
50d34e5653 Fix potential memory leak
Delete the socket if the initialization part of the socket creation
fails.
2014-02-03 18:03:25 +02:00
Alex Pyrgiotis
e6ef16d005 Fix potential segmentation fault
Call the allocation assertion macro before dereferencing the socket
pointer.
2014-02-03 17:35:53 +02:00
Martin Hurton
e46ec31209 Implement socket_base_t::get_credential member function
The get_credential () member function returns
credential for the last peer we received message for.
The idea is that this function is used to implement user-level API.
2014-01-13 00:40:27 +01:00
Stefan Radomski
3aeaa6fab1 ZMQ_SRCFD docs and tests
Also moved the fd field from message content to message itself
2014-01-07 01:09:51 +01:00
Stefan Radomski
f30fb8501e Expose remote FD via zmq_msg_get(&msg, ZMQ_SRCFD)
This patch allows client applications to retrieve the remote endpoint from a message that originated from a tcp socket
2014-01-06 10:31:42 +01:00
Pieter Hintjens
b3b9e046ee Updated copyright statements for 2014 2014-01-02 12:00:57 +01:00
Trevor Bernard
10a6641ef2 Fix issue #788 - Only allow a single connect per endpoint for SUB, REQ, and DEALER sockets 2013-12-14 23:40:34 -04:00
KIU Shueng Chuan
fd8d6d471f use enum retired_fd instead of -1
using -1 causes a warning on Windows platform because SOCKET is unsigned.
2013-12-05 07:04:21 +08:00
Pieter Hintjens
c573f6b812 Fix for issue 574 2013-11-07 14:59:53 +01:00
Erik Hugne
58ac87def1 zmq: narrow condition to include TIPC in build/test
As TIPC transport for 0MQ will only work on post 3.8
Linux kernels where nonblocking connect was added,
we add AC_RUN test to check for this functionality.
Should the test fail, tipc is excluded from build/test.

Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
2013-11-01 14:59:31 +01:00
Erik Hugne
632677e805 ricnewton review comment
Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
2013-11-01 11:17:10 +01:00
Erik Hugne
eab85b5295 zmq: add support for TIPC transport
A ZeroMQ application can opt for TIPC based sockets
using the TIPC port name format:
zmq_bind(sb, "tipc://{type,lower,upper}");
zmq_connect(sc, "tipc://{type,inst}");

'type' is the service ID, and 'lower/upper' can be
used for service partitioning or basic load
balancing.

ZeroMQ TIPC transport requires a kernel >= 3.8
(nonblocking connect support for TIPC).

Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
2013-11-01 10:09:22 +01:00
Richard Newton
b9298823b4 Set hwm on connect socket before bind has happend to just that of connects hwm. 2013-09-15 13:35:44 +01:00
Richard Newton
b9c09064d5 Fix whitespace 2013-09-12 21:22:47 +01:00
Richard Newton
379bcb0881 Send identities when connecting pending sockets. 2013-09-12 21:07:29 +01:00
Richard Newton
7c3496a76a Fix race condition and support multiple socket connects before bind. 2013-09-12 18:09:37 +01:00
Richard Newton
5f20d63665 First attempt at inproc connect before bind 2013-09-12 14:44:44 +01:00
Pieter Hintjens
282765cab4 Merge pull request #628 from ianbarber/master
Remove delay options
2013-09-02 06:04:51 -07:00
Shawn J. Goff
6a18f59532 Change name of icanhasall to subscribe_to_all
icanhasall is cute (for now), but the effect of the variable is clear
only after tracking down its origin reading the commit. This change is
intended to make it easier for people to have some intuition about its
effect from its name.
2013-08-31 10:02:05 -04:00
Ian Barber
a9baa051dd Merge in master changes 2013-08-20 22:48:04 +01:00
Ian Barber
d485404aab Merge pull request #626 from dkrikun/master
Add ZMQ_CONFLATE socket option
2013-08-20 14:37:52 -07:00
Ian Barber
531d3ebc09 Remove delay options
These were exposed to users, but have subsequently been removed as
sockopts. They are currently only being used by ZAP, so I've moved it to
a simpl function call (actually it's only used in one case even in that,
so there may be a further simplification possible there).
2013-08-18 11:16:21 +01:00
Ian Barber
cb35fd7bfe Attempt to fix disconnect not respecting linger
Looks like linger is honoured properly, but shutting down the session
causes the pipe termination to come from that side - because the local
pipe then shuts down right away it seems to trigger a terminated on the
other end instead of waiting. This way we trigger the termination from
the local end and then terminate the session.
2013-08-18 07:50:53 +01:00
danielkr
daa7a8021f Plug in dbuffer to serve the ZMQ_CONFLATE option
ZMQ_CONFLATE option is passed to pipepair() which creates a usual
ypipe_t or ypipe_conflate_t and plugs it into pipe_t under a common
abstract base.
2013-08-17 23:27:25 +03:00
Richard Newton
d4d23caf32 Add new socket monitor event for when socket monitoring is stopped. 2013-07-01 11:00:46 +01:00
Martin Hurton
aef2171e83 Make last_endpoint attribute of socket object 2013-06-29 17:26:13 +02:00
Pieter Hintjens
ad77937956 Added ZMQ_STREAM socket type
- designed for TCP clients and servers
- added HTTP client / server example in tests/test_stream.cpp
- same as ZMQ_ROUTER + ZMQ_ROUTER_RAW + ZMQ_ROUTER_MANDATORY
- includes b893ce set ZMQ_IDENTITY on outgoing connect
- deprecates ZMQ_ROUTER_RAW
2013-06-27 20:53:15 +02:00
Martin Hurton
c3e40736de Rename terminated->pipe_terminated 2013-06-06 13:28:21 +02:00
Pieter Hintjens
8358d4e832 Renamed ZMQ_DELAY_ATTACH_ON_CONNECT_COULD_THIS_BE_ANY_LONGER to ZMQ_IMMEDIATE 2013-03-12 16:11:19 +01:00
Pieter Hintjens
f0f16505e5 Removed corporate advertisements from source file headers
Copyrights had become ads for Sustrik's corporate sponsors, going against the original
agreement to share copyrights with the community (that agreement was: one line stating
iMatix copyright + one reference to AUTHORS file). The proliferation of corporate ads
is also unfair to the many individual authors. I've removed ALL corporate title from
the source files so the copyright statements can now be centralized in AUTHORS and
source files can be properly updated on an annual basis.
2013-03-12 13:24:57 +01:00
Guido Goldstein
b0b8ab27c5 Changed message structure for event notifications. 2013-03-08 13:48:18 +01:00
Guido Goldstein
21eeb03b6c Simplified the zmq_event_t structure for easier access and better usability towards language bindings. 2013-03-08 10:34:25 +01:00
Sébastien Rombauts
41d79bc19e Windows CE support : using standard _WIN32_WCE flag instead of WINCE
- when compiling for Windows CE, a C++ project must define the preprocessor definitions: UNDER_CE=$(CEVersion),_WIN32_WCE=$(CEVersion)
- choosing the "_WIN32_CE" form for uniformization with "_WIN32" and "_WIN32_WINNT" already used in libzmq (boost is using both forms)
- see http://msdn.microsoft.com/en-us/library/ee479161(v=winembedded.60).aspx
2013-02-19 16:49:23 +01:00
Sébastien Rombauts
927000fe2f Fixed 7 MSVC2008 Compiler Warning (level 3) C4800: 'const int' : forcing value to bool 'true' or 'false' (performance warning)
- added explicit test "(xxx != 0)" to get a "bool" value out of the "int" expression
- see the MSDN recommandation http://msdn.microsoft.com/en-us/library/b6801kcy(v=vs.90).aspx
2013-02-19 14:27:14 +01:00
Pieter Hintjens
8ab3c4a1bf Fixed issue #500 2013-01-31 21:52:30 +01:00
Pieter Hintjens
309740e197 Fixed issue #499 2013-01-31 20:47:45 +01:00
Matt Arsenault
6ce464414b Fix typos 2013-01-02 03:24:11 -05:00
Matt Arsenault
1ffc5d11dc Fix some of the -Wshadows 2013-01-02 03:24:11 -05:00
Stefan Radomski
21345ffa50 Break early when pipe to be removed was found 2012-12-04 17:40:43 +01:00
Stefan Radomski
f9770e93ef Fixed iterator when erasing from inprocs multimap 2012-12-04 17:31:46 +01:00
Stefan Radomski
624dd1e5b5 Removal of terminated pipes from inproc and ignoring peer ends 2012-12-04 17:10:32 +01:00
Stefan Radomski
66c22456b9 Close pipes for inproc sockets on zmq_disconnect
- fixes LIBZMQ-476 and LIBZMQ-475
2012-12-04 15:14:21 +01:00
Lourens Naudé
359a505949 Prefer malloc to new for event address allocation as per Martin's recommendation 2012-11-22 00:12:17 +00:00
Lourens Naudé
b1f4850153 Let socket event messages initialize with zmq_msg_init_data and let the framework handle cleanup 2012-11-21 18:27:53 +00:00
Lourens Naudé
6d245eb6bc Copy monitor specific event endpoints to event messages as the engine etc. can be released at anytime 2012-11-17 11:29:47 +00:00
Lourens Naudé
5205415beb Fix addresses on triggered events 2012-11-14 09:51:24 +00:00
Martin Hurton
66dc4d8b54 Don't pass flags to xrecv method 2012-11-09 17:18:14 +01:00
Martin Hurton
7865f96e97 Don't pass flags to xsend method 2012-11-09 17:18:10 +01:00
Martin Hurton
ea19b7b658 Small cleanups 2012-11-09 14:12:11 +01:00
Martin Hurton
925a530663 Use const_cast operator to remove const modifier 2012-11-09 14:02:19 +01:00
Martin Hurton
03deb2c97a Resolve LIBZMQ-447 2012-10-29 10:15:51 +01:00
Pieter Hintjens
4ba34c9d70 Whitespace and style fixes 2012-10-24 09:18:52 +09:00
Pieter Hintjens
96811575c3 Fixed issue #448 2012-10-18 11:04:51 +09:00
Lourens Naudé
759d453368 Significantly reworked the monitoring infrastructure with a more granular per socket API and to play well with monitoring endpoints in application threads 2012-09-21 12:53:31 +01:00
Arthur O'Dwyer
3b984d40e9 Silence all "unused parameter" warnings from Clang.
Compiling without warnings is a good goal, because it makes
new warnings (which probably indicate bugs) stand out rather
than getting lost in the spam.

My fixes fall into two categories:

    - Adding (void) casts of unused parameters, where their
      unusedness seems like a TODO (or in some cases a bug?).

    - Removing parameter names altogether, where the function
      is clearly a stub that will never use its parameters.

Should be no change in behavior.
2012-08-27 16:05:51 -07:00
Ian Barber
206e5f6f44 Incorrect function name in socket_base
VA specific monitor event in socket base was named monitor_event rather
than va_monitor_event
2012-08-26 14:29:09 +01:00
Ian Barber
f028379c1c Incorrect var name in monitor_event
The call to the va version of the function was using 'event' instead of
'event_'
2012-08-26 14:27:12 +01:00
Arthur O'Dwyer
7fadd708a0 Fix monitor_event() to work at all.
There are three versions of monitor_event(), all taking
variadic arguments. The original code just has the first one
creating a va_list and passing that va_list variadically to
the second one... which creates a new va_list and passes it
variadically to the third one... and of course everything
blows up when we try to pull a non-va_list argument off the
stack.

The correct approach matches the C standard library's use
of printf/vprintf, scanf/vscanf, and so on. Once you make
a va_list, you must pass it only to functions which expect
a va_list parameter.
2012-08-24 16:42:31 -07:00
Martin Hurton
1ab85f471a Exchange greeting messages for all socket types
Fixes #415.
2012-08-11 19:04:49 +02:00
Martin Hurton
92827e45ee Small code cleanup 2012-07-18 01:53:43 +02:00
Martin Hurton
86eaa9c8e7 Rewrite process_command's loop 2012-07-06 12:17:36 +02:00
Ian Barber
e5904e63ce Allow blocking while connect() is completing
This patch, salvaged from a trainwreck accidental merge earlier, adds a
new sockopt, ZMQ_DELAY_ATTACH_ON_CONNECT which prevents a end point
being available to push messages to until it has fully connected, making
connect work more like bind. This also applies to reconnecting sockets,
which may cause message loss of in-queue messages, so it is sensible to
use this in conjunction with a low HWM and potentially an alternative
acknowledgement path.

Notes on most of the individual commits can be found the repository log.
2012-06-12 15:34:48 +01:00
Ian Barber
95cbad3841 Revert "After speaking with Ben Gray and the discussion on the mailing list, this is an attempt to create a sockopt to allow connecting pipes to not immediately be available for traffic. The problem is in a PUSH to many PULL situation, where there is a connect to a PULL which is not there. This connect will immediately create a pipe (unlike bind), and traffic will be load balanced to that pipe. This means if there is a persistently unavailable end point then the traffic will queue until HWM is hit, and older messages will be lost."
This reverts commit fe3fb419fe.
2012-06-12 14:53:57 +01:00
Ian Barber
5b167aa896 Revert "Remove the extra outpipe handling as the session is quite capable of delaying the creation of the pipe until the connection has happened. Simply don't build the pipe, and let it do that automatically."
This reverts commit 06485d9200.
2012-06-12 14:52:18 +01:00
Ian Barber
81b8362a59 Revert "Fix a number of whitespace issues in various parts of the code, add validation to most calls on the test and take a first stab at implementing the reconnection pipe blocking."
This reverts commit 6f6466f088.
2012-06-12 14:51:50 +01:00
Ian Barber
48d3977632 Revert "Fix condition so that PGM and EPGM sockets always create pipes immediately, even if delay_attach_on_connect is set. This allows passing through the icanhasall flag, and is realistic given the fact those protocols should be able to connect immediately"
This reverts commit b5ace39e2a.
2012-06-12 14:51:33 +01:00
Ian Barber
f0920caf02 Revert "On the advice of Martin Hurton, removed the new command type and just terminated the pipe in a reconnect situation, and notified the socket of the same. This handles the blocking properly, but at the cost of potentially losing in flight messages. However, this is a reasonable trade off given how much simpler it makes the patch."
This reverts commit c13f1d52ff.
2012-06-12 14:50:50 +01:00
Ian Barber
3ae68d67a4 Revert "Use the hiccup mechanism to notify the socket end of the pair of the change in state, and have it shutdown that end, and shutdown the local end normally. This seems to resolve the shutdown and race condition issues."
This reverts commit 67497a2643.
2012-06-12 14:46:23 +01:00
Ian Barber
f5a072fee1 Revert "Code formatting, and clean up so that xhiccuped is only handled in case the pipe isn't terminating"
This reverts commit 5da289cd5b.
2012-06-12 14:46:01 +01:00
Ian Barber
6eeaf15179 Revert "Remove unnecessary condition in assert"
This reverts commit 3053f7e368.
2012-06-12 14:45:36 +01:00
Ian Barber
eb14890d23 Revert "Revert "Merge branch 'master' of github.com:ianbarber/libzmq""
This reverts commit 029d3dfae2.
2012-06-12 14:43:18 +01:00
Ian Barber
029d3dfae2 Revert "Merge branch 'master' of github.com:ianbarber/libzmq"
This reverts commit 3345902979, reversing
changes made to 889b0e6f29.
2012-06-12 14:13:17 +01:00
Ian Barber
3053f7e368 Remove unnecessary condition in assert 2012-06-09 00:08:14 +01:00
Ian Barber
5da289cd5b Code formatting, and clean up so that xhiccuped is only handled in case the pipe isn't terminating 2012-06-09 00:07:30 +01:00
Ian Barber
67497a2643 Use the hiccup mechanism to notify the socket end of the pair of the change in state, and have it shutdown that end, and shutdown the local end normally. This seems to resolve the shutdown and race condition issues. 2012-06-08 23:55:42 +01:00
Ian Barber
c13f1d52ff On the advice of Martin Hurton, removed the new command type and just terminated the pipe in a reconnect situation, and notified the socket of the same. This handles the blocking properly, but at the cost of potentially losing in flight messages. However, this is a reasonable trade off given how much simpler it makes the patch. 2012-06-04 10:27:16 +01:00
Ian Barber
b5ace39e2a Fix condition so that PGM and EPGM sockets always create pipes immediately, even if delay_attach_on_connect is set. This allows passing through the icanhasall flag, and is realistic given the fact those protocols should be able to connect immediately 2012-06-03 23:01:24 +01:00
Ian Barber
6f6466f088 Fix a number of whitespace issues in various parts of the code, add validation to most calls on the test and take a first stab at implementing the reconnection pipe blocking.
It didn't seem straightforward to use any of the existing process calls, so I have added a new command to command_t and friends called detach. This instructs the socket_base to remove the pipe from it's pipe list. The session base stores a copy of the outpipe, and will resend the bind command on reconnection. This should allow balancing again.
2012-06-03 22:57:47 +01:00
Ian Barber
06485d9200 Remove the extra outpipe handling as the session is quite capable of delaying the creation of the pipe until the connection has happened. Simply don't build the pipe, and let it do that automatically. 2012-06-03 22:05:36 +01:00
Ian Barber
fe3fb419fe After speaking with Ben Gray and the discussion on the mailing list, this is an attempt to create a sockopt to allow connecting pipes to not immediately be available for traffic. The problem is in a PUSH to many PULL situation, where there is a connect to a PULL which is not there. This connect will immediately create a pipe (unlike bind), and traffic will be load balanced to that pipe. This means if there is a persistently unavailable end point then the traffic will queue until HWM is hit, and older messages will be lost.
This patch adds a sockopt ZMQ_DELAY_ATTACH_ON_CONNECT, which if set to 1 will attempt to preempt this behavior. It does this by extending the use of the session_base to include in the outbound as well as the inbound pipe, and only associates the pipe with the socket once it receives the connected callback via a process_attach message. This works, and a test has been added to show so, but may introduce unexpected complications. The shutdown logic in this class has become marginally more awkward because of this, requiring the session to serve as the sink for both pipes if shutdown occurs with a still-connecting pipe in place. It is also possible there could be issues around flushing the messages, but as I could not directly think how to create such an issue I have not written any code with regards to that.

The documentation has been updated to reflect the change, but please do check over the code and test and review.
2012-06-01 17:58:19 +01:00
Steven McCoy
13976a3d65 Return error on invalid PGM url instead of raising assertion.
Fix Win32 build.
2012-05-30 20:52:19 -04:00
Martin Hurton
24b79c7e0b Prefer errno_assert/alloc_assert to zmq_assert 2012-05-28 23:17:03 +02:00
Lourens Naudé
adf7a7ade1 Merge branch 'master' into monitor-regressions 2012-05-22 23:35:30 +01:00
Lourens Naudé
4767159f39 Initial stab at a context level monitor callback and registration API 2012-05-21 20:47:11 +01:00
Lourens Naudé
06cce15479 Change zmq_monitor_fn type to cast between pointer-to-object and pointer-to-function in a more standards compliant way 2012-05-20 18:22:13 +01:00
Ivan Pechorin
d25dce9df9 Solaris/SunCC build fix: could not find a match for std::multimap<...>::insert(std::pair<...,...>) 2012-05-20 13:34:08 +02:00
Lourens Naudé
c38aecdc50 Merge branch 'master' into events 2012-05-04 02:35:22 +01:00
Lourens Naudé
5c6f72c17c ZMQ_MONITOR socket option registers a callback / event sink for changes in socket state 2012-05-04 02:32:46 +01:00
Martin Hurton
394a248579 socket_base: process_unplug () is not used, remove it 2012-04-28 16:28:12 +02:00
Pieter Hintjens
c120f02dc9 Merge pull request #321 from shripchenko/master
add process_commands() to the beginning of zmq_connect() and zmq_bind()
2012-04-21 16:06:06 -07:00
Sergey KHripchenko
f858321c1c add process_commands() to the beginning of zmq_connect() and zmq_bind()
I believe there was a conception that zmq_connect() and zmq_bind() will be called
only at the socket creation time and therefore don't need it.
Now it is not true anymore.
2012-04-22 01:39:48 +04:00
Pieter Hintjens
b9fb919877 Merge pull request #320 from shripchenko/master
ZMQ BUG FOUND + fixes for zmq_unbind() / zmq_disconnect() usage corner cases
2012-04-21 09:52:46 -07:00
Sergey KHripchenko
057fab09a8 fixes for zmq_unbind() / zmq_disconnect() usage corner cases
1. when we call zmq_bind()/zmq_connect() to create endpoint
we send ourselfs(through launch_child()) command to process_own(endpoint)
(and add it to own_t::owned)
in the application thread we could call zmq_unbind() / zmq_disconnect() _BEFORE_
we run process_own() in ZMQ thread and in this situation we will be unable to find it in
own_t::owned. in other words own_t::owned.find(endpoint) will not be deleted but it will be deleted from
socket_base_t::endpoints.

2. when you zmq_unbind() the lisnening TCP/IPC socket was terminated only in destructor...
so the whole ZMQ_LINGER time listening TCP/IPC socket was able to accept() new connections
but unable to handle them.

this all geting even worse since unfortunately zmq has a bug and '*_listener_t' object not terminated
untill the socket's zmq_close().
AT LEAST FOR PUSH SOCKETS.
Everything is ok for SUB sockets.

Easy to reproduce without my fix:

zmq_socket(PUSH)
zmq_bind(tcp);
// connect to  it from PULL socket
zmq_unbind(tcp);

sleep(forever)

// netstat -anp | grep 'tcp listening socket'

With my fix you could see that after zmq_unbind(tcp) all previously connected tcp sessions
will not be finished untill the zmq_close(socket) regardless of ZMQ_LINGER value.

(*_listener_t terminates all owned session_base_t(connect=false) and they call pipe_t::terminate()
which in turn should call session_base_t::terminated() but this never happens)
2012-04-21 18:56:10 +04:00
Pieter Hintjens
952127dfd6 Merge pull request #319 from shripchenko/master
fix for: [zeromq-dev] head builds again but two failing tests
2012-04-21 06:03:00 -07:00
Sergey KHripchenko
06b2eae87d small wording change 2012-04-21 08:12:59 +04:00
Pieter Hintjens
653e5854ed Merge pull request #318 from shripchenko/master
2nd try wuth sock->unbind() and sock->disconnect(). now with const char*'s argument
2012-04-20 09:11:56 -07:00
Sergey KHripchenko
489481857a 2nd try wuth sock->unbind() and sock->disconnect(). now with blackjack and const char*'s 2012-04-20 18:59:08 +04:00
Pieter Hintjens
8837852546 Merge pull request #317 from shripchenko/master
implement zmq_unbind(),zmq_disconnect(), zmq->sock->getsockopt(ZMQ_LAST_ENDPOINT_ID)
2012-04-18 13:58:45 -07:00
Sergey KHripchenko
7b8e728e43 implement zmq_unbind(),zmq_disconnect(), zmq->sock->getsockopt(ZMQ_LAST_ENDPOINT_ID) 2012-04-18 23:42:11 +04:00
Ian Barber
5b3008957d port of patch by Martin Sustrik to libxs: This patch instantiate a clock_t instance for each XS
socket. Thus, it is shared between subsequent calls
to xs_recv (and xs_send). That in turn significantly
limits the number of invocations of  getimeofday (or similar)
when timeouts are used and recv/send is called in a
tight loop.
2012-04-17 10:10:22 +01:00
Martin Hurton
12c0c6aa74 Fix identity exchange for inproc transport
The socket connecting using the inproc transport never
received the identity of the remote peer.
2012-04-05 16:00:41 +02:00
Martin Hurton
b41036aa2a Flush identity message for inproc transport
The scoket implementation for inproc transfer failed to flush
identity message. The result was that the identity message
was not delivered until after the user sent the first message.

The identity message was never delivered if the user
used the socket only to receive messages.
2012-04-05 01:19:13 +02:00
Pieter Hintjens
27c28bdc2e Mark sockets as invalid when closed, not when destroyed
Previously, sockets were still "valid" after being closed and only marked
as invalid when destroyed. This meant programs could access closed sockets.
Now the socket is marked "invalid" when closed.
2012-03-22 15:56:30 -05:00
Pieter Hintjens
c12fedc70a Completed internal renaming of XREP/XREQ to ROUTER/DEALER 2012-03-22 11:36:19 -05:00
Pieter Hintjens
6e71a54b1e Fixed issues #337, #341, and #340
* Implemented new ctx API (_new, _destroy, _get, _set)
* Removed 'typesafe' macros from zmq.h
* Added support for MAX_SOCKETS (was tied into change for #337)
* Created new man pages
2012-03-19 19:41:20 -05:00
Pieter Hintjens
bdefa181ed Fixed issue 336 2012-03-19 16:15:09 -05:00
Pieter Hintjens
06dd31c56a Removed last vestiges of thread-safe sockets 2012-03-19 15:50:53 -05:00
boris@boressoft.ru
318ba8836f Add WinCE support.
* Added two new files: errno.hpp and errno.cpp. They are required to use errno functionality on WM.
* zmq.cpp, msg.h: removed inclusion of errno.h because it is included in zmq.h that is also included by .cpp.
* windows.hpp: process.h is included only for desktop builds.
* thread.cpp: on CE CreateThread is used instead of __beginthreadex
* socket_base.cpp, clock.cpp: on CE include cmnintrin.h instead on intrin.h
* signaler.cpp: on Windows should use special macro around event name (for unicode builds)
* err.hpp: make it include errno.hpp (my file) instead on errno.h when building for CE
* err.cpp: use FormatMessage when building for CE (because CE does not have ANSI API functions)
* zmq.h: do not include errno.h whe building for CE
* libzmq.vcproj: add tro new files
2012-03-14 19:12:28 +04:00
Mikko Koppanen
d00d4843be More fixes for ZMQ_LAST_ENDPOINT. Added a test 2012-02-18 20:44:41 +00:00
Mikko Koppanen
1bf4067cd8 More fixes for win build 2012-02-17 22:07:52 +00:00
Staffan Gimåker
b9fb48f47b Resolve addresses in the calling thread on connect.
This allows us to actually report an error to the caller on resolve
failure, rather than asserting later on in the io thread.

Signed-off-by: Staffan Gimåker <staffan@spotify.com>
2012-02-16 14:42:55 +01:00
Pieter Hintjens
afe8cd503f Revert "fix warn unused"
- anonymous contributor

This reverts commit 7b7d404269.
2012-02-14 18:43:33 -06:00
Ian Barber
b5d3373905 Moving to std::string in options 2012-02-14 23:10:06 +00:00
Ian Barber
91bf4944da Merge branch 'master' of https://github.com/zeromq/libzmq 2012-02-11 15:08:23 +00:00
niXman
7b7d404269 fix warn unused 2012-02-10 13:39:34 +04:00
Ian Barber
7fa14f3823 Merge branch 'master' of https://github.com/zeromq/libzmq 2012-02-08 22:06:50 +00:00
Ian Barber
7b32c9cb51 Adding ZMQ_LAST_ENDPOINT for wildcard support on TCP and IPC sockets 2012-02-08 22:06:46 +00:00
skaller
520ad3c2d7 Set and arrange propagation of thread safe sockets flag.
We use a distinct context initialisation function to specify
all sockets derived therefrom will be thread safe.

However the inheritance is done exclusively in the C interface.
This is not really correct, but it is chosen to minimise
interference with the existing C++ code, including any
construct or other calls within the C++ code base.
Semantically the C++ code should be unchanged,
physically some data structures and extra methods are
provided by they're only used from the C binding.
2012-02-04 02:17:35 +11:00
skaller
988efbc73a Thread Safe Sockets.
1. Reorganise C API socket functions to eliminate bad practice
of public functions calling other public functions. This should
be done for msg's too but hasn't been in this patch.

2. Reorganise code in C API socket functions so that the
socket is cast on one line, the C++ function called on
the next with the result retained, then the result is returned.

This makes the code much simpler to read and also allows
pre- and post- call hooks to be inserted easily.

3. Insert pre- and post- call hooks which set and release
a mutex iff the thread_safe flag is on.

4. Add the thread_safe_flag to base_socket_t initialised to
false to preserve existing semantics. Add an accessor for
the flag, add a mutex, and add lock and unlock functions.

Note: as yet no code to actually set the flag.
2012-02-04 01:41:09 +11:00
Martin Lucina
0319cb2cd1 Fix data loss for PUB/SUB and unidirectional transports (LIBZMQ-268)
With the introduction of subscription forwarding, the first message sent
on a PUB socket using a unidirectional transport (e.g. PGM) is always
lost due to the "subscribe to all" being done asynchronously.

This patch fixes the problem and also refactors the code to have a single
point where the "subscribe to all" is performed.

Signed-off-by: Martin Lucina <martin@lucina.net>
2012-02-02 13:07:48 +01:00
Martin Sustrik
f9eb763293 zmq_sendmsg and zmq_recvmsg checks for NULL message object
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-12-16 07:04:38 +01:00
Chuck Remes
93529d8c5d Add zmq_getmsgopt to the API
The new function allows to retrieve options (flags)
from zmq_msg_t.

Signed-off-by: Chuck Remes <cremes@mac.com>
Renamed from zmq_msg_flags to zmq_getmsgopt
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-11-06 14:03:51 +01:00
Martin Sustrik
a756956781 Use identities in inproc transport
Previous patches have missed the case when the identity should
be sent from an inproc endpoint. Fixed.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-11-05 09:57:17 +01:00
Martin Sustrik
a4843b65d2 Identities re-introduced
However, the "durable socket" behaviour wasn't re-added.
Identities are used solely for routing in REQ/REP pattern.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-11-04 08:00:47 +01:00
Martin Sustrik
8e21d64c97 Copyright dates adjusted to reflect reality
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-11-01 18:06:11 +01:00
Martin Sustrik
7842c71073 LABELS and COMMANDs removed
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-11-01 13:39:54 +01:00
Martin Sustrik
626099aa2a VTCP transport removed
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-10-31 16:37:20 +01:00
Martin Sustrik
ac7717b7b3 250bpm copyrights added
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-10-31 16:20:30 +01:00
Martin Sustrik
dee8b2360a New style ROUTER socket removed.
Signed-off-by: Martin Sustrik <sustrik@turist.(none)>
2011-10-31 15:44:42 +01:00
Martin Sustrik
f78d9b6bfc Session class separated into socket-type-specific sessions
This is a preliminary patch allowing for socket-type-specific
functionality in the I/O thread. For example, message format
can be checked asynchronously and misbehaved connections dropped
straight away.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-09-15 10:00:23 +02:00
Martin Sustrik
65bb75863d Fixed warnings on Win64
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-09-01 07:26:17 +02:00
Martin Sustrik
46b053b8d6 Dead code removed from TCP and IPC transports
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-28 13:46:16 +02:00
Martin Sustrik
5ac63140b0 Implementations of TCP and IPC transports separated
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-28 13:19:55 +02:00
Martin Sustrik
279302c5f5 Experimental VTCP listener added
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-26 18:35:40 +02:00
Martin Sustrik
9119b4fd7b TCP transport classes simplified
zmq_engine and tcp_socket merged into tcp_engine
zmq_connecter and tcp_connecter merged into tcp_connecter
zmq_listener and tcp_listener merged into tcp_listener

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-26 00:43:57 +02:00
Martin Sustrik
7c1dca546d Session classes merged into a single class
Removal of ZMQ_IDENTITY resulted in various session classes doing
almost the same thing. This patch merges the classes into a single
class.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-24 18:25:30 +02:00
Martin Sustrik
72a793f78a ZMQ_GENERIC renamed to ZMQ_ROUTER
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-21 18:43:50 +02:00
Martin Sustrik
bf78e230ad GENERIC socket type and COMMAND flag added
GENERIC allows to use 0MQ as a dumb networking framework.
It provides user with connect/disconnect notifications.
Also, each inbound message is labeled by ID of the connection
it originated from. Outbound messages should be labeled by
the ID of the connection to send them to.

To distinguish connect/disconnect notifications from common
messages, COMMAND flag was introduced.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-17 23:31:29 +02:00
Martin Sustrik
c8e8f2a24c ZMQ_IDENTITY socket option removed
This patch simplifies the whole codebase significantly,
including dropping depedency on libuuid.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-15 11:24:33 +02:00
Martin Sustrik
ba67eff167 non-immediate_connect functionality removed
It was used only by ROUTER socket. After its removal it became
obsolete.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-15 08:26:29 +02:00
Martin Sustrik
e4f98d1e10 ROUTER and DEALER sockets removed
To be replaced by new generic socket type

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-07-15 08:16:40 +02:00
Martin Sustrik
770d0bc77c Fix MSVC build
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-06-23 08:51:48 +02:00
Martin Sustrik
d1373792f7 Outstanding requests dropped when requester dies (issue 190)
So far the requests in req/rep pattern were delivered to and processed
by worker even though the original requester was dead. Thus,
the worker processing replies with noone to deliver results to.
This optimisation drops requests in two situations:

1. Queued inbound requests in XREP socket when peer disconnects.
2. Queued outbound requests in XREQ when socket is closed.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-06-23 07:57:47 +02:00
Martin Sustrik
ec81f8fb25 New wire format for REQ/REP pattern
This patch introduces two changes:
1. 32-bit ID is used to identify the peer instead of UUID
2. REQ socket seeds the label stack with unique 32-bit request ID
   It also drops any replies with non-matching request ID

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-06-22 11:02:16 +02:00
Martin Sustrik
a28928fe37 Introduce ZMQ_ROUTER and ZMQ_DEALER sockets
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-06-20 13:36:18 +02:00
Martin Sustrik
ab99975ad4 LABEL flag added to the wire format
So far there was no distinction between message parts used by 0MQ
and message parts used by user. Now, the message parts used by 0MQ
are marked as 'LABEL'.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-06-20 11:33:54 +02:00
Martin Sustrik
8440de2b14 Fix minor warning in MSVC build
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-06-20 08:11:48 +02:00
Fabien Ninoles
d7923f08ca Add sockopt ZMQ_RCVTIMEO/ZMQ_SNDTIMEO.
- Add doc and tests
- Add options and setup
- Wait using poll/select

Signed-off-by: Fabien Ninoles <fabien@tzone.org>
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-06-17 12:22:02 +02:00
Martin Sustrik
a24a7c15a8 Session termination induced by socket fixed
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-05-31 14:36:51 +02:00
Martin Sustrik
0b59866a84 Patches from sub-forward branch incorporated
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-05-30 10:07:34 +02:00
Martin Sustrik
87a6490b39 All pipe termination code moved to pipe_t
Till now the code was spread over mutliple locations.
Additionally, the code was made more formally correct,
with explicit pipe state machine etc.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-05-25 10:25:51 +02:00
Martin Sustrik
0f6f7276e3 Move the pipe termination code to socket_base_t
So far, the pipe termination code was spread among socket type
classes, fair queuer, load balancer, etc. This patch moves
all the associated logic to a single place.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-05-23 20:30:01 +02:00
Martin Sustrik
acf0b0e515 Introduces bi-directional pipes
So far, there was a pair of unidirectional pipes between a socket
and a session (or an inproc peer). This resulted in complex
problems with half-closed states and tracking which inpipe
corresponds to which outpipe.

This patch doesn't add any functionality in itself, but is
essential for further work on features like subscription
forwarding.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-05-22 17:26:53 +02:00
Martin Sustrik
b2eb84f8ca Substantial simplification of uuid_t
The string format of UUID is not used in 0MQ. Further on,
it turns out that UUIDs have fixed microarchitecture-agnostic
binary layout (see RFC4122). Thus, the conversion to string
and back to binary can be avoided.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-04-29 07:19:22 +02:00
Martin Sustrik
e0246e32d7 Message-related functionality factored out into msg_t class.
This patch addresses serveral issues:
1. It gathers message related functionality scattered over whole
   codebase into a single class.
2. It makes zmq_msg_t an opaque datatype. Internals of the class
   don't pollute zmq.h header file.
3. zmq_msg_t size decreases from 48 to 32 bytes. That saves ~33%
   of memory in scenarios with large amount of small messages.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-04-21 22:27:48 +02:00
Martin Sustrik
581697695a Message validity is checked in the runtime
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-04-19 08:08:15 +02:00
Martin Sustrik
b96fe15bb6 Run-time checking for context & socket validity added
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-04-09 09:35:34 +02:00
Martin Sustrik
abb184a051 ZMQ_NOBLOCK renamed ZMQ_DONTWAIT
Done because of POSIX compliance

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-03-26 10:38:40 +01:00
Martin Sustrik
bc4a1ce334 ZMQ_HWM split into ZMQ_SNDHWM and ZMQ_RCVHWM
These new options allow to control the maximum size of the
inbound and outbound message pipe separately.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-03-24 16:47:33 +01:00
Martin Sustrik
507718ee1a ZMQ_HWM type changed to int
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
2011-03-24 15:43:03 +01:00