pgm_socket.hpp 4.03 KB
Newer Older
malosek's avatar
malosek committed
1
/*
2
    Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
malosek's avatar
malosek committed
3

4
    This file is part of libzmq, the ZeroMQ core engine in C++.
malosek's avatar
malosek committed
5

6 7 8
    libzmq is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License (LGPL) as published
    by the Free Software Foundation; either version 3 of the License, or
malosek's avatar
malosek committed
9 10
    (at your option) any later version.

11 12 13 14 15 16 17 18 19 20 21 22 23 24
    As a special exception, the Contributors give you permission to link
    this library with independent modules to produce an executable,
    regardless of the license terms of these independent modules, and to
    copy and distribute the resulting executable under terms of your choice,
    provided that you also meet, for each linked independent module, the
    terms and conditions of the license of that module. An independent
    module is a module which is not derived from or based on this library.
    If you modify this library, you must extend this exception to your
    version of the library.

    libzmq is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    License for more details.
malosek's avatar
malosek committed
25

26
    You should have received a copy of the GNU Lesser General Public License
malosek's avatar
malosek committed
27 28 29 30 31 32
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __PGM_SOCKET_HPP_INCLUDED__
#define __PGM_SOCKET_HPP_INCLUDED__

malosek's avatar
malosek committed
33
#if defined ZMQ_HAVE_OPENPGM
malosek's avatar
malosek committed
34

35
#ifdef ZMQ_HAVE_WINDOWS
36
#define __PGM_WININT_H__
malosek's avatar
malosek committed
37 38
#endif

39 40
#include <pgm/pgm.h>

41
#if defined(ZMQ_HAVE_OSX) || defined(ZMQ_HAVE_NETBSD)
42 43 44
#include <pgm/in.h>
#endif

45
#include "fd.hpp"
malosek's avatar
malosek committed
46 47 48 49
#include "options.hpp"

namespace zmq
{
50 51 52 53 54 55
//  Encapsulates PGM socket.
class pgm_socket_t
{
  public:
    //  If receiver_ is true PGM transport is not generating SPM packets.
    pgm_socket_t (bool receiver_, const options_t &options_);
malosek's avatar
malosek committed
56

57 58
    //  Closes the transport.
    ~pgm_socket_t ();
59

60 61
    //  Initialize PGM network structures (GSI, GSRs).
    int init (bool udp_encapsulation_, const char *network_);
62

63 64 65 66
    //  Resolve PGM socket address.
    static int init_address (const char *network_,
                             struct pgm_addrinfo_t **addr,
                             uint16_t *port_number);
malosek's avatar
malosek committed
67

68 69
    //   Get receiver fds and store them into user allocated memory.
    void get_receiver_fds (fd_t *receive_fd_, fd_t *waiting_pipe_fd_);
malosek's avatar
malosek committed
70

71 72 73 74 75 76
    //   Get sender and receiver fds and store it to user allocated
    //   memory. Receive fd is used to process NAKs from peers.
    void get_sender_fds (fd_t *send_fd_,
                         fd_t *receive_fd_,
                         fd_t *rdata_notify_fd_,
                         fd_t *pending_notify_fd_);
malosek's avatar
malosek committed
77

78 79
    //  Send data as one APDU, transmit window owned memory.
    size_t send (unsigned char *data_, size_t data_len_);
malosek's avatar
malosek committed
80

81 82
    //  Returns max tsdu size without fragmentation.
    size_t get_max_tsdu_size ();
malosek's avatar
malosek committed
83

84 85
    //  Receive data from pgm socket.
    ssize_t receive (void **data_, const pgm_tsi_t **tsi_);
86

87 88
    long get_rx_timeout ();
    long get_tx_timeout ();
malosek's avatar
malosek committed
89

90 91 92
    //  POLLIN on sender side should mean NAK or SPMR receiving.
    //  process_upstream function is used to handle such a situation.
    void process_upstream ();
93

94 95 96
  private:
    //  Compute size of the buffer based on rate and recovery interval.
    int compute_sqns (int tpdu_);
97

98 99
    //  OpenPGM transport.
    pgm_sock_t *sock;
malosek's avatar
malosek committed
100

101
    int last_rx_status, last_tx_status;
102

103 104
    //  Associated socket options.
    options_t options;
105

106 107
    //  true when pgm_socket should create receiving side.
    bool receiver;
malosek's avatar
malosek committed
108

109 110 111
    //  Array of pgm_msgv_t structures to store received data
    //  from the socket (pgm_transport_recvmsgv).
    pgm_msgv_t *pgm_msgv;
malosek's avatar
malosek committed
112

113 114
    //  Size of pgm_msgv array.
    size_t pgm_msgv_len;
Martin Sustrik's avatar
Martin Sustrik committed
115

116 117
    // How many bytes were read from pgm socket.
    size_t nbytes_rec;
malosek's avatar
malosek committed
118

119 120
    //  How many bytes were processed from last pgm socket read.
    size_t nbytes_processed;
121

122 123 124
    //  How many messages from pgm_msgv were already sent up.
    size_t pgm_msgv_processed;
};
malosek's avatar
malosek committed
125 126 127 128
}
#endif

#endif