libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
pgm_socket.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #ifndef __PGM_SOCKET_HPP_INCLUDED__
31 #define __PGM_SOCKET_HPP_INCLUDED__
32 
33 #include "platform.hpp"
34 
35 #if defined ZMQ_HAVE_OPENPGM
36 
37 #ifdef ZMQ_HAVE_WINDOWS
38 #include "windows.hpp"
39 #define __PGM_WININT_H__
40 #endif
41 
42 #include <pgm/pgm.h>
43 
44 #if defined(ZMQ_HAVE_OSX) || defined(ZMQ_HAVE_NETBSD)
45 #include <pgm/in.h>
46 #endif
47 
48 #include "fd.hpp"
49 #include "options.hpp"
50 
51 namespace zmq
52 {
53  // Encapsulates PGM socket.
54  class pgm_socket_t
55  {
56 
57  public:
58 
59  // If receiver_ is true PGM transport is not generating SPM packets.
60  pgm_socket_t (bool receiver_, const options_t &options_);
61 
62  // Closes the transport.
63  ~pgm_socket_t ();
64 
65  // Initialize PGM network structures (GSI, GSRs).
66  int init (bool udp_encapsulation_, const char *network_);
67 
68  // Resolve PGM socket address.
69  static int init_address(const char *network_, struct pgm_addrinfo_t **addr, uint16_t *port_number);
70 
71  // Get receiver fds and store them into user allocated memory.
72  void get_receiver_fds (fd_t *receive_fd_, fd_t *waiting_pipe_fd_);
73 
74  // Get sender and receiver fds and store it to user allocated
75  // memory. Receive fd is used to process NAKs from peers.
76  void get_sender_fds (fd_t *send_fd_, fd_t *receive_fd_,
77  fd_t *rdata_notify_fd_, fd_t *pending_notify_fd_);
78 
79  // Send data as one APDU, transmit window owned memory.
80  size_t send (unsigned char *data_, size_t data_len_);
81 
82  // Returns max tsdu size without fragmentation.
83  size_t get_max_tsdu_size ();
84 
85  // Receive data from pgm socket.
86  ssize_t receive (void **data_, const pgm_tsi_t **tsi_);
87 
88  long get_rx_timeout ();
89  long get_tx_timeout ();
90 
91  // POLLIN on sender side should mean NAK or SPMR receiving.
92  // process_upstream function is used to handle such a situation.
93  void process_upstream ();
94 
95  private:
96 
97  // Compute size of the buffer based on rate and recovery interval.
98  int compute_sqns (int tpdu_);
99 
100  // OpenPGM transport.
101  pgm_sock_t* sock;
102 
103  int last_rx_status, last_tx_status;
104 
105  // Associated socket options.
106  options_t options;
107 
108  // true when pgm_socket should create receiving side.
109  bool receiver;
110 
111  // Array of pgm_msgv_t structures to store received data
112  // from the socket (pgm_transport_recvmsgv).
113  pgm_msgv_t *pgm_msgv;
114 
115  // Size of pgm_msgv array.
116  size_t pgm_msgv_len;
117 
118  // How many bytes were read from pgm socket.
119  size_t nbytes_rec;
120 
121  // How many bytes were processed from last pgm socket read.
122  size_t nbytes_processed;
123 
124  // How many messages from pgm_msgv were already sent up.
125  size_t pgm_msgv_processed;
126  };
127 }
128 #endif
129 
130 #endif
131 
int fd_t
Definition: fd.hpp:50
int receive(void *socket)
static void receiver(void *socket)
Definition: address.hpp:35