pgm_socket.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "precompiled.hpp"
4 
5 #ifdef ZMQ_HAVE_OPENPGM
6 
7 #ifdef ZMQ_HAVE_LINUX
8 #include <poll.h>
9 #endif
10 
11 #include <stdlib.h>
12 #include <string.h>
13 #include <string>
14 
15 #include "options.hpp"
16 #include "pgm_socket.hpp"
17 #include "config.hpp"
18 #include "err.hpp"
19 #include "random.hpp"
20 #include "stdint.hpp"
21 
22 #ifndef MSG_ERRQUEUE
23 #define MSG_ERRQUEUE 0x2000
24 #endif
25 
26 zmq::pgm_socket_t::pgm_socket_t (bool receiver_, const options_t &options_) :
27  sock (NULL),
28  options (options_),
29  receiver (receiver_),
30  pgm_msgv (NULL),
31  pgm_msgv_len (0),
32  nbytes_rec (0),
33  nbytes_processed (0),
34  pgm_msgv_processed (0)
35 {
36 }
37 
38 // Resolve PGM socket address.
39 // network_ of the form <interface & multicast group decls>:<IP port>
40 // e.g. eth0;239.192.0.1:7500
41 // link-local;224.250.0.1,224.250.0.2;224.250.0.3:8000
42 // ;[fe80::1%en0]:7500
43 int zmq::pgm_socket_t::init_address (const char *network_,
44  struct pgm_addrinfo_t **res,
45  uint16_t *port_number)
46 {
47  // Parse port number, start from end for IPv6
48  const char *port_delim = strrchr (network_, ':');
49  if (!port_delim) {
50  errno = EINVAL;
51  return -1;
52  }
53 
54  *port_number = atoi (port_delim + 1);
55 
56  char network[256];
57  if (port_delim - network_ >= (int) sizeof (network) - 1) {
58  errno = EINVAL;
59  return -1;
60  }
61  memset (network, '\0', sizeof (network));
62  memcpy (network, network_, port_delim - network_);
63 
64  pgm_error_t *pgm_error = NULL;
65  struct pgm_addrinfo_t hints;
66 
67  memset (&hints, 0, sizeof (hints));
68  hints.ai_family = AF_UNSPEC;
69  if (!pgm_getaddrinfo (network, NULL, res, &pgm_error)) {
70  // Invalid parameters don't set pgm_error_t.
71  zmq_assert (pgm_error != NULL);
72  if (pgm_error->domain == PGM_ERROR_DOMAIN_IF &&
73 
74  // NB: cannot catch EAI_BADFLAGS.
75  (pgm_error->code != PGM_ERROR_SERVICE
76  && pgm_error->code != PGM_ERROR_SOCKTNOSUPPORT)) {
77  // User, host, or network configuration or transient error.
78  pgm_error_free (pgm_error);
79  errno = EINVAL;
80  return -1;
81  }
82 
83  // Fatal OpenPGM internal error.
84  zmq_assert (false);
85  }
86  return 0;
87 }
88 
89 // Create, bind and connect PGM socket.
90 int zmq::pgm_socket_t::init (bool udp_encapsulation_, const char *network_)
91 {
92  // Can not open transport before destroying old one.
93  zmq_assert (sock == NULL);
94  zmq_assert (options.rate > 0);
95 
96  // Zero counter used in msgrecv.
97  nbytes_rec = 0;
98  nbytes_processed = 0;
99  pgm_msgv_processed = 0;
100 
101  uint16_t port_number;
102  struct pgm_addrinfo_t *res = NULL;
103  sa_family_t sa_family;
104 
105  pgm_error_t *pgm_error = NULL;
106 
107  if (init_address (network_, &res, &port_number) < 0) {
108  goto err_abort;
109  }
110 
111  zmq_assert (res != NULL);
112 
113  // Pick up detected IP family.
114  sa_family = res->ai_send_addrs[0].gsr_group.ss_family;
115 
116  // Create IP/PGM or UDP/PGM socket.
117  if (udp_encapsulation_) {
118  if (!pgm_socket (&sock, sa_family, SOCK_SEQPACKET, IPPROTO_UDP,
119  &pgm_error)) {
120  // Invalid parameters don't set pgm_error_t.
121  zmq_assert (pgm_error != NULL);
122  if (pgm_error->domain == PGM_ERROR_DOMAIN_SOCKET
123  && (pgm_error->code != PGM_ERROR_BADF
124  && pgm_error->code != PGM_ERROR_FAULT
125  && pgm_error->code != PGM_ERROR_NOPROTOOPT
126  && pgm_error->code != PGM_ERROR_FAILED))
127 
128  // User, host, or network configuration or transient error.
129  goto err_abort;
130 
131  // Fatal OpenPGM internal error.
132  zmq_assert (false);
133  }
134 
135  // All options are of data type int
136  const int encapsulation_port = port_number;
137  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_UDP_ENCAP_UCAST_PORT,
138  &encapsulation_port, sizeof (encapsulation_port)))
139  goto err_abort;
140  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_UDP_ENCAP_MCAST_PORT,
141  &encapsulation_port, sizeof (encapsulation_port)))
142  goto err_abort;
143  } else {
144  if (!pgm_socket (&sock, sa_family, SOCK_SEQPACKET, IPPROTO_PGM,
145  &pgm_error)) {
146  // Invalid parameters don't set pgm_error_t.
147  zmq_assert (pgm_error != NULL);
148  if (pgm_error->domain == PGM_ERROR_DOMAIN_SOCKET
149  && (pgm_error->code != PGM_ERROR_BADF
150  && pgm_error->code != PGM_ERROR_FAULT
151  && pgm_error->code != PGM_ERROR_NOPROTOOPT
152  && pgm_error->code != PGM_ERROR_FAILED))
153 
154  // User, host, or network configuration or transient error.
155  goto err_abort;
156 
157  // Fatal OpenPGM internal error.
158  zmq_assert (false);
159  }
160  }
161 
162  {
163  const int rcvbuf = (int) options.rcvbuf;
164  if (rcvbuf >= 0) {
165  if (!pgm_setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf,
166  sizeof (rcvbuf)))
167  goto err_abort;
168  }
169 
170  const int sndbuf = (int) options.sndbuf;
171  if (sndbuf >= 0) {
172  if (!pgm_setsockopt (sock, SOL_SOCKET, SO_SNDBUF, &sndbuf,
173  sizeof (sndbuf)))
174  goto err_abort;
175  }
176 
177  const int max_tpdu = (int) options.multicast_maxtpdu;
178  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MTU, &max_tpdu,
179  sizeof (max_tpdu)))
180  goto err_abort;
181  }
182 
183  if (receiver) {
184  const int recv_only = 1, rxw_max_tpdu = (int) options.multicast_maxtpdu,
185  rxw_sqns = compute_sqns (rxw_max_tpdu),
186  peer_expiry = pgm_secs (300), spmr_expiry = pgm_msecs (25),
187  nak_bo_ivl = pgm_msecs (50), nak_rpt_ivl = pgm_msecs (200),
188  nak_rdata_ivl = pgm_msecs (200), nak_data_retries = 50,
189  nak_ncf_retries = 50;
190 
191  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_RECV_ONLY, &recv_only,
192  sizeof (recv_only))
193  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_RXW_SQNS, &rxw_sqns,
194  sizeof (rxw_sqns))
195  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_PEER_EXPIRY,
196  &peer_expiry, sizeof (peer_expiry))
197  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_SPMR_EXPIRY,
198  &spmr_expiry, sizeof (spmr_expiry))
199  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_NAK_BO_IVL, &nak_bo_ivl,
200  sizeof (nak_bo_ivl))
201  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_NAK_RPT_IVL,
202  &nak_rpt_ivl, sizeof (nak_rpt_ivl))
203  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_NAK_RDATA_IVL,
204  &nak_rdata_ivl, sizeof (nak_rdata_ivl))
205  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_NAK_DATA_RETRIES,
206  &nak_data_retries, sizeof (nak_data_retries))
207  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_NAK_NCF_RETRIES,
208  &nak_ncf_retries, sizeof (nak_ncf_retries)))
209  goto err_abort;
210  } else {
211  const int send_only = 1, max_rte = (int) ((options.rate * 1000) / 8),
212  txw_max_tpdu = (int) options.multicast_maxtpdu,
213  txw_sqns = compute_sqns (txw_max_tpdu),
214  ambient_spm = pgm_secs (30),
215  heartbeat_spm[] = {
216  pgm_msecs (100), pgm_msecs (100), pgm_msecs (100),
217  pgm_msecs (100), pgm_msecs (1300), pgm_secs (7),
218  pgm_secs (16), pgm_secs (25), pgm_secs (30)};
219 
220  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_SEND_ONLY, &send_only,
221  sizeof (send_only))
222  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_ODATA_MAX_RTE, &max_rte,
223  sizeof (max_rte))
224  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_TXW_SQNS, &txw_sqns,
225  sizeof (txw_sqns))
226  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_AMBIENT_SPM,
227  &ambient_spm, sizeof (ambient_spm))
228  || !pgm_setsockopt (sock, IPPROTO_PGM, PGM_HEARTBEAT_SPM,
229  &heartbeat_spm, sizeof (heartbeat_spm)))
230  goto err_abort;
231  }
232 
233  // PGM transport GSI.
234  struct pgm_sockaddr_t addr;
235 
236  memset (&addr, 0, sizeof (addr));
237  addr.sa_port = port_number;
238  addr.sa_addr.sport = DEFAULT_DATA_SOURCE_PORT;
239 
240  // Create random GSI.
241  uint32_t buf[2];
242  buf[0] = generate_random ();
243  buf[1] = generate_random ();
244  if (!pgm_gsi_create_from_data (&addr.sa_addr.gsi, (uint8_t *) buf, 8))
245  goto err_abort;
246 
247 
248  // Bind a transport to the specified network devices.
249  struct pgm_interface_req_t if_req;
250  memset (&if_req, 0, sizeof (if_req));
251  if_req.ir_interface = res->ai_recv_addrs[0].gsr_interface;
252  if_req.ir_scope_id = 0;
253  if (AF_INET6 == sa_family) {
254  struct sockaddr_in6 sa6;
255  memcpy (&sa6, &res->ai_recv_addrs[0].gsr_group, sizeof (sa6));
256  if_req.ir_scope_id = sa6.sin6_scope_id;
257  }
258  if (!pgm_bind3 (sock, &addr, sizeof (addr), &if_req, sizeof (if_req),
259  &if_req, sizeof (if_req), &pgm_error)) {
260  // Invalid parameters don't set pgm_error_t.
261  zmq_assert (pgm_error != NULL);
262  if ((pgm_error->domain == PGM_ERROR_DOMAIN_SOCKET
263  || pgm_error->domain == PGM_ERROR_DOMAIN_IF)
264  && (pgm_error->code != PGM_ERROR_INVAL
265  && pgm_error->code != PGM_ERROR_BADF
266  && pgm_error->code != PGM_ERROR_FAULT))
267 
268  // User, host, or network configuration or transient error.
269  goto err_abort;
270 
271  // Fatal OpenPGM internal error.
272  zmq_assert (false);
273  }
274 
275  // Join IP multicast groups.
276  for (unsigned i = 0; i < res->ai_recv_addrs_len; i++) {
277  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_JOIN_GROUP,
278  &res->ai_recv_addrs[i], sizeof (struct group_req)))
279  goto err_abort;
280  }
281  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_SEND_GROUP,
282  &res->ai_send_addrs[0], sizeof (struct group_req)))
283  goto err_abort;
284 
285  pgm_freeaddrinfo (res);
286  res = NULL;
287 
288  // Set IP level parameters.
289  {
290  // Multicast loopback disabled by default
291  const int multicast_loop = 0;
292  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_LOOP,
293  &multicast_loop, sizeof (multicast_loop)))
294  goto err_abort;
295 
296  const int multicast_hops = options.multicast_hops;
297  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_HOPS,
298  &multicast_hops, sizeof (multicast_hops)))
299  goto err_abort;
300 
301  // Expedited Forwarding PHB for network elements, no ECN.
302  // Ignore return value due to varied runtime support.
303  const int dscp = 0x2e << 2;
304  if (AF_INET6 != sa_family)
305  pgm_setsockopt (sock, IPPROTO_PGM, PGM_TOS, &dscp, sizeof (dscp));
306 
307  const int nonblocking = 1;
308  if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_NOBLOCK, &nonblocking,
309  sizeof (nonblocking)))
310  goto err_abort;
311  }
312 
313  // Connect PGM transport to start state machine.
314  if (!pgm_connect (sock, &pgm_error)) {
315  // Invalid parameters don't set pgm_error_t.
316  zmq_assert (pgm_error != NULL);
317  goto err_abort;
318  }
319 
320  // For receiver transport preallocate pgm_msgv array.
321  if (receiver) {
322  zmq_assert (options.in_batch_size > 0);
323  size_t max_tsdu_size = get_max_tsdu_size ();
324  pgm_msgv_len = (int) options.in_batch_size / max_tsdu_size;
325  if ((int) options.in_batch_size % max_tsdu_size)
326  pgm_msgv_len++;
327  zmq_assert (pgm_msgv_len);
328 
329  pgm_msgv = (pgm_msgv_t *) malloc (sizeof (pgm_msgv_t) * pgm_msgv_len);
330  alloc_assert (pgm_msgv);
331  }
332 
333  return 0;
334 
335 err_abort:
336  if (sock != NULL) {
337  pgm_close (sock, FALSE);
338  sock = NULL;
339  }
340  if (res != NULL) {
341  pgm_freeaddrinfo (res);
342  res = NULL;
343  }
344  if (pgm_error != NULL) {
345  pgm_error_free (pgm_error);
346  pgm_error = NULL;
347  }
348  errno = EINVAL;
349  return -1;
350 }
351 
352 zmq::pgm_socket_t::~pgm_socket_t ()
353 {
354  if (pgm_msgv)
355  free (pgm_msgv);
356  if (sock)
357  pgm_close (sock, TRUE);
358 }
359 
360 // Get receiver fds. receive_fd_ is signaled for incoming packets,
361 // waiting_pipe_fd_ is signaled for state driven events and data.
362 void zmq::pgm_socket_t::get_receiver_fds (fd_t *receive_fd_,
363  fd_t *waiting_pipe_fd_)
364 {
365  socklen_t socklen;
366  bool rc;
367 
368  zmq_assert (receive_fd_);
369  zmq_assert (waiting_pipe_fd_);
370 
371  socklen = sizeof (*receive_fd_);
372  rc =
373  pgm_getsockopt (sock, IPPROTO_PGM, PGM_RECV_SOCK, receive_fd_, &socklen);
374  zmq_assert (rc);
375  zmq_assert (socklen == sizeof (*receive_fd_));
376 
377  socklen = sizeof (*waiting_pipe_fd_);
378  rc = pgm_getsockopt (sock, IPPROTO_PGM, PGM_PENDING_SOCK, waiting_pipe_fd_,
379  &socklen);
380  zmq_assert (rc);
381  zmq_assert (socklen == sizeof (*waiting_pipe_fd_));
382 }
383 
384 // Get fds and store them into user allocated memory.
385 // send_fd is for non-blocking send wire notifications.
386 // receive_fd_ is for incoming back-channel protocol packets.
387 // rdata_notify_fd_ is raised for waiting repair transmissions.
388 // pending_notify_fd_ is for state driven events.
389 void zmq::pgm_socket_t::get_sender_fds (fd_t *send_fd_,
390  fd_t *receive_fd_,
391  fd_t *rdata_notify_fd_,
392  fd_t *pending_notify_fd_)
393 {
394  socklen_t socklen;
395  bool rc;
396 
397  zmq_assert (send_fd_);
398  zmq_assert (receive_fd_);
399  zmq_assert (rdata_notify_fd_);
400  zmq_assert (pending_notify_fd_);
401 
402  socklen = sizeof (*send_fd_);
403  rc = pgm_getsockopt (sock, IPPROTO_PGM, PGM_SEND_SOCK, send_fd_, &socklen);
404  zmq_assert (rc);
405  zmq_assert (socklen == sizeof (*receive_fd_));
406 
407  socklen = sizeof (*receive_fd_);
408  rc =
409  pgm_getsockopt (sock, IPPROTO_PGM, PGM_RECV_SOCK, receive_fd_, &socklen);
410  zmq_assert (rc);
411  zmq_assert (socklen == sizeof (*receive_fd_));
412 
413  socklen = sizeof (*rdata_notify_fd_);
414  rc = pgm_getsockopt (sock, IPPROTO_PGM, PGM_REPAIR_SOCK, rdata_notify_fd_,
415  &socklen);
416  zmq_assert (rc);
417  zmq_assert (socklen == sizeof (*rdata_notify_fd_));
418 
419  socklen = sizeof (*pending_notify_fd_);
420  rc = pgm_getsockopt (sock, IPPROTO_PGM, PGM_PENDING_SOCK,
421  pending_notify_fd_, &socklen);
422  zmq_assert (rc);
423  zmq_assert (socklen == sizeof (*pending_notify_fd_));
424 }
425 
426 // Send one APDU, transmit window owned memory.
427 // data_len_ must be less than one TPDU.
428 size_t zmq::pgm_socket_t::send (unsigned char *data_, size_t data_len_)
429 {
430  size_t nbytes = 0;
431 
432  const int status = pgm_send (sock, data_, data_len_, &nbytes);
433 
434  // We have to write all data as one packet.
435  if (nbytes > 0) {
436  zmq_assert (status == PGM_IO_STATUS_NORMAL);
437  zmq_assert (nbytes == data_len_);
438  } else {
439  zmq_assert (status == PGM_IO_STATUS_RATE_LIMITED
440  || status == PGM_IO_STATUS_WOULD_BLOCK);
441 
442  if (status == PGM_IO_STATUS_RATE_LIMITED)
443  errno = ENOMEM;
444  else
445  errno = EBUSY;
446  }
447 
448  // Save return value.
449  last_tx_status = status;
450 
451  return nbytes;
452 }
453 
454 long zmq::pgm_socket_t::get_rx_timeout ()
455 {
456  if (last_rx_status != PGM_IO_STATUS_RATE_LIMITED
457  && last_rx_status != PGM_IO_STATUS_TIMER_PENDING)
458  return -1;
459 
460  struct timeval tv;
461  socklen_t optlen = sizeof (tv);
462  const bool rc = pgm_getsockopt (sock, IPPROTO_PGM,
463  last_rx_status == PGM_IO_STATUS_RATE_LIMITED
464  ? PGM_RATE_REMAIN
465  : PGM_TIME_REMAIN,
466  &tv, &optlen);
467  zmq_assert (rc);
468 
469  const long timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
470 
471  return timeout;
472 }
473 
474 long zmq::pgm_socket_t::get_tx_timeout ()
475 {
476  if (last_tx_status != PGM_IO_STATUS_RATE_LIMITED)
477  return -1;
478 
479  struct timeval tv;
480  socklen_t optlen = sizeof (tv);
481  const bool rc =
482  pgm_getsockopt (sock, IPPROTO_PGM, PGM_RATE_REMAIN, &tv, &optlen);
483  zmq_assert (rc);
484 
485  const long timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
486 
487  return timeout;
488 }
489 
490 // Return max TSDU size without fragmentation from current PGM transport.
491 size_t zmq::pgm_socket_t::get_max_tsdu_size ()
492 {
493  int max_tsdu = 0;
494  socklen_t optlen = sizeof (max_tsdu);
495 
496  bool rc = pgm_getsockopt (sock, IPPROTO_PGM, PGM_MSS, &max_tsdu, &optlen);
497  zmq_assert (rc);
498  zmq_assert (optlen == sizeof (max_tsdu));
499  return (size_t) max_tsdu;
500 }
501 
502 // pgm_recvmsgv is called to fill the pgm_msgv array up to pgm_msgv_len.
503 // In subsequent calls data from pgm_msgv structure are returned.
504 ssize_t zmq::pgm_socket_t::receive (void **raw_data_, const pgm_tsi_t **tsi_)
505 {
506  size_t raw_data_len = 0;
507 
508  // We just sent all data from pgm_transport_recvmsgv up
509  // and have to return 0 that another engine in this thread is scheduled.
510  if (nbytes_rec == nbytes_processed && nbytes_rec > 0) {
511  // Reset all the counters.
512  nbytes_rec = 0;
513  nbytes_processed = 0;
514  pgm_msgv_processed = 0;
515  errno = EAGAIN;
516  return 0;
517  }
518 
519  // If we have are going first time or if we have processed all pgm_msgv_t
520  // structure previously read from the pgm socket.
521  if (nbytes_rec == nbytes_processed) {
522  // Check program flow.
523  zmq_assert (pgm_msgv_processed == 0);
524  zmq_assert (nbytes_processed == 0);
525  zmq_assert (nbytes_rec == 0);
526 
527  // Receive a vector of Application Protocol Domain Unit's (APDUs)
528  // from the transport.
529  pgm_error_t *pgm_error = NULL;
530 
531  const int status = pgm_recvmsgv (sock, pgm_msgv, pgm_msgv_len,
532  MSG_ERRQUEUE, &nbytes_rec, &pgm_error);
533 
534  // Invalid parameters.
535  zmq_assert (status != PGM_IO_STATUS_ERROR);
536 
537  last_rx_status = status;
538 
539  // In a case when no ODATA/RDATA fired POLLIN event (SPM...)
540  // pgm_recvmsg returns PGM_IO_STATUS_TIMER_PENDING.
541  if (status == PGM_IO_STATUS_TIMER_PENDING) {
542  zmq_assert (nbytes_rec == 0);
543 
544  // In case if no RDATA/ODATA caused POLLIN 0 is
545  // returned.
546  nbytes_rec = 0;
547  errno = EBUSY;
548  return 0;
549  }
550 
551  // Send SPMR, NAK, ACK is rate limited.
552  if (status == PGM_IO_STATUS_RATE_LIMITED) {
553  zmq_assert (nbytes_rec == 0);
554 
555  // In case if no RDATA/ODATA caused POLLIN 0 is returned.
556  nbytes_rec = 0;
557  errno = ENOMEM;
558  return 0;
559  }
560 
561  // No peers and hence no incoming packets.
562  if (status == PGM_IO_STATUS_WOULD_BLOCK) {
563  zmq_assert (nbytes_rec == 0);
564 
565  // In case if no RDATA/ODATA caused POLLIN 0 is returned.
566  nbytes_rec = 0;
567  errno = EAGAIN;
568  return 0;
569  }
570 
571  // Data loss.
572  if (status == PGM_IO_STATUS_RESET) {
573  struct pgm_sk_buff_t *skb = pgm_msgv[0].msgv_skb[0];
574 
575  // Save lost data TSI.
576  *tsi_ = &skb->tsi;
577  nbytes_rec = 0;
578 
579  // In case of dala loss -1 is returned.
580  errno = EINVAL;
581  pgm_free_skb (skb);
582  return -1;
583  }
584 
585  zmq_assert (status == PGM_IO_STATUS_NORMAL);
586  } else {
587  zmq_assert (pgm_msgv_processed <= pgm_msgv_len);
588  }
589 
590  // Zero byte payloads are valid in PGM, but not 0MQ protocol.
591  zmq_assert (nbytes_rec > 0);
592 
593  // Only one APDU per pgm_msgv_t structure is allowed.
594  zmq_assert (pgm_msgv[pgm_msgv_processed].msgv_len == 1);
595 
596  struct pgm_sk_buff_t *skb = pgm_msgv[pgm_msgv_processed].msgv_skb[0];
597 
598  // Take pointers from pgm_msgv_t structure.
599  *raw_data_ = skb->data;
600  raw_data_len = skb->len;
601 
602  // Save current TSI.
603  *tsi_ = &skb->tsi;
604 
605  // Move the the next pgm_msgv_t structure.
606  pgm_msgv_processed++;
607  zmq_assert (pgm_msgv_processed <= pgm_msgv_len);
608  nbytes_processed += raw_data_len;
609 
610  return raw_data_len;
611 }
612 
613 void zmq::pgm_socket_t::process_upstream ()
614 {
615  pgm_msgv_t dummy_msg;
616 
617  size_t dummy_bytes = 0;
618  pgm_error_t *pgm_error = NULL;
619 
620  const int status = pgm_recvmsgv (sock, &dummy_msg, 1, MSG_ERRQUEUE,
621  &dummy_bytes, &pgm_error);
622 
623  // Invalid parameters.
624  zmq_assert (status != PGM_IO_STATUS_ERROR);
625 
626  // No data should be returned.
627  zmq_assert (dummy_bytes == 0
628  && (status == PGM_IO_STATUS_TIMER_PENDING
629  || status == PGM_IO_STATUS_RATE_LIMITED
630  || status == PGM_IO_STATUS_WOULD_BLOCK));
631 
632  last_rx_status = status;
633 
634  if (status == PGM_IO_STATUS_TIMER_PENDING)
635  errno = EBUSY;
636  else if (status == PGM_IO_STATUS_RATE_LIMITED)
637  errno = ENOMEM;
638  else
639  errno = EAGAIN;
640 }
641 
642 int zmq::pgm_socket_t::compute_sqns (int tpdu_)
643 {
644  // Convert rate into B/ms.
645  uint64_t rate = uint64_t (options.rate) / 8;
646 
647  // Compute the size of the buffer in bytes.
648  uint64_t size = uint64_t (options.recovery_ivl) * rate;
649 
650  // Translate the size into number of packets.
651  uint64_t sqns = size / tpdu_;
652 
653  // Buffer should be able to hold at least one packet.
654  if (sqns == 0)
655  sqns = 1;
656 
657  return (int) sqns;
658 }
659 
660 #endif
init
WEPOLL_INTERNAL int init(void)
Definition: wepoll.c:858
data_
StringPiece data_
Definition: bytestream_unittest.cc:60
receive
int receive(void *socket_, int *is_termination_)
Definition: test_hwm_pubsub.cpp:62
NULL
NULL
Definition: test_security_zap.cpp:405
config.hpp
options
Message * options
Definition: src/google/protobuf/descriptor.cc:3119
EINVAL
#define EINVAL
Definition: errno.hpp:25
sock
void * sock
Definition: test_connect_resolve.cpp:9
EAGAIN
#define EAGAIN
Definition: errno.hpp:14
precompiled.hpp
zmq_assert
#define zmq_assert(x)
Definition: err.hpp:102
random.hpp
if
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END if(!upb_strtable_init(&intern->table, UPB_CTYPE_UINT64))
Definition: php/ext/google/protobuf/map.c:232
errno
int errno
send
void send(fd_t fd_, const char(&data_)[N])
Definition: test_security_curve.cpp:209
alloc_assert
#define alloc_assert(x)
Definition: err.hpp:146
stdint.hpp
pgm_socket.hpp
timeout
GLbitfield GLuint64 timeout
Definition: glcorearb.h:3588
buf
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:4175
i
int i
Definition: gmock-matchers_test.cc:764
options.hpp
size
GLsizeiptr size
Definition: glcorearb.h:2943
zmq::generate_random
uint32_t generate_random()
Definition: random.cpp:30
err.hpp
receiver
static void receiver(void *socket_)
Definition: test_ctx_destroy.cpp:16
fd_t
zmq_fd_t fd_t
Definition: libzmq/tests/testutil.hpp:98
options_
DebugStringOptions options_
Definition: src/google/protobuf/descriptor.cc:2410


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:57