|
16 | 16 | *
|
17 | 17 | * The unit is in milliseconds in sync with ZMQ_RCVTIMEO of
|
18 | 18 | * zmq_setsockopt.
|
| 19 | + * |
| 20 | + * Publisher uses more to shadow async connectivity from PUB to |
| 21 | + * XSUB end point of eventd's proxy. Hene have a less value. |
| 22 | + * |
| 23 | + * Subscriber uses it for cache management and here we need a |
| 24 | + * longer timeout, to handle slow proxy. This timeout value's only |
| 25 | + * impact could be subscriber process trying to terminate. |
19 | 26 | */
|
20 | 27 |
|
21 |
| -#define EVENTS_SERVICE_TIMEOUT_MILLISECS 200 |
| 28 | +#define EVENTS_SERVICE_TIMEOUT_MS_PUB 200 |
| 29 | +#define EVENTS_SERVICE_TIMEOUT_MS_SUB 2000 |
22 | 30 |
|
23 | 31 | /*
|
24 | 32 | * Track created publishers to avoid duplicates
|
@@ -50,7 +58,7 @@ int EventPublisher::init(const string event_source)
|
50 | 58 | * Event service could be down. So have a timeout.
|
51 | 59 | *
|
52 | 60 | */
|
53 |
| - rc = m_event_service.init_client(m_zmq_ctx, EVENTS_SERVICE_TIMEOUT_MILLISECS); |
| 61 | + rc = m_event_service.init_client(m_zmq_ctx, EVENTS_SERVICE_TIMEOUT_MS_PUB); |
54 | 62 | RET_ON_ERR (rc == 0, "Failed to init event service");
|
55 | 63 |
|
56 | 64 | rc = m_event_service.echo_send("hello");
|
@@ -87,7 +95,7 @@ EventPublisher::publish(const string tag, const event_params_t *params)
|
87 | 95 | string s;
|
88 | 96 |
|
89 | 97 | /* Failure is no-op; The eventd service my be down
|
90 |
| - * NOTE: This call atmost blocks for EVENTS_SERVICE_TIMEOUT_MILLISECS |
| 98 | + * NOTE: This call atmost blocks for EVENTS_SERVICE_TIMEOUT_MS_PUB |
91 | 99 | * as provided in publisher init.
|
92 | 100 | */
|
93 | 101 | m_event_service.echo_receive(s);
|
@@ -240,7 +248,8 @@ EventSubscriber::~EventSubscriber()
|
240 | 248 |
|
241 | 249 |
|
242 | 250 | int
|
243 |
| -EventSubscriber::init(bool use_cache, const event_subscribe_sources_t *subs_sources) |
| 251 | +EventSubscriber::init(bool use_cache, int recv_timeout, |
| 252 | + const event_subscribe_sources_t *subs_sources) |
244 | 253 | {
|
245 | 254 | /*
|
246 | 255 | * Initiate SUBS connection to XPUB end point.
|
@@ -268,8 +277,13 @@ EventSubscriber::init(bool use_cache, const event_subscribe_sources_t *subs_sour
|
268 | 277 | }
|
269 | 278 | }
|
270 | 279 |
|
| 280 | + if (recv_timeout != -1) { |
| 281 | + rc = zmq_setsockopt (m_socket, ZMQ_RCVTIMEO, &recv_timeout, sizeof (recv_timeout)); |
| 282 | + RET_ON_ERR(rc == 0, "Failed to ZMQ_RCVTIMEO to %d", recv_timeout); |
| 283 | + } |
| 284 | + |
271 | 285 | if (use_cache) {
|
272 |
| - rc = m_event_service.init_client(m_zmq_ctx, EVENTS_SERVICE_TIMEOUT_MILLISECS); |
| 286 | + rc = m_event_service.init_client(m_zmq_ctx, EVENTS_SERVICE_TIMEOUT_MS_SUB); |
273 | 287 | RET_ON_ERR(rc == 0, "Fails to init the service");
|
274 | 288 |
|
275 | 289 | if (m_event_service.cache_stop() == 0) {
|
@@ -379,12 +393,13 @@ EventSubscriber::event_receive(string &key, event_params_t ¶ms, int &missed_
|
379 | 393 | static EventSubscriber *s_subscriber = NULL;
|
380 | 394 |
|
381 | 395 | event_handle_t
|
382 |
| -events_init_subscriber(bool use_cache, const event_subscribe_sources_t *sources) |
| 396 | +events_init_subscriber(bool use_cache, int recv_timeout, |
| 397 | + const event_subscribe_sources_t *sources) |
383 | 398 | {
|
384 | 399 | if (s_subscriber == NULL) {
|
385 | 400 | EventSubscriber *p = new EventSubscriber();
|
386 | 401 |
|
387 |
| - RET_ON_ERR(p->init(use_cache, sources) == 0, |
| 402 | + RET_ON_ERR(p->init(use_cache, recv_timeout, sources) == 0, |
388 | 403 | "Failed to init subscriber");
|
389 | 404 |
|
390 | 405 | s_subscriber = p;
|
@@ -416,4 +431,8 @@ event_receive(event_handle_t handle, string &key,
|
416 | 431 | return -1;
|
417 | 432 | }
|
418 | 433 |
|
| 434 | +int event_last_error() |
| 435 | +{ |
| 436 | + return recv_last_err; |
| 437 | +} |
419 | 438 |
|
0 commit comments