pgm_socket.hpp 3.18 KB
Newer Older
malosek's avatar
malosek committed
1
/*
2
    Copyright (c) 2007-2010 iMatix Corporation
malosek's avatar
malosek committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
    the terms of the Lesser GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    0MQ 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
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __PGM_SOCKET_HPP_INCLUDED__
#define __PGM_SOCKET_HPP_INCLUDED__

#include "platform.hpp"

malosek's avatar
malosek committed
25
#if defined ZMQ_HAVE_OPENPGM
malosek's avatar
malosek committed
26

27 28
#ifdef ZMQ_HAVE_WINDOWS
#include "windows.hpp"
malosek's avatar
malosek committed
29 30
#endif

31 32
#include <pgm/pgm.h>

malosek's avatar
malosek committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#include "options.hpp"

namespace zmq
{
    //  Encapsulates PGM socket.
    class pgm_socket_t
    {

    public:
        //  If receiver_ is true PGM transport is not generating SPM packets.
        //  interface format: iface;mcast_group:port for raw PGM socket
        //                    udp:iface;mcast_goup:port for UDP encapsulacion
        pgm_socket_t (bool receiver_, const options_t &options_);

        //  Closes the transport.
        ~pgm_socket_t ();

        //  Initialize PGM network structures (GSI, GSRs).
51
        int init (bool udp_encapsulation_, const char *network_);
malosek's avatar
malosek committed
52 53
        
        //   Get receiver fds and store them into user allocated memory.
54
        void get_receiver_fds (int *receive_fd_, int *waiting_pipe_fd_);
malosek's avatar
malosek committed
55 56 57

        //   Get sender and receiver fds and store it to user allocated 
        //   memory. Receive fd is used to process NAKs from peers.
58
        void get_sender_fds (int *send_fd_, int *receive_fd_,
59
            int *rdata_notify_fd_, int *pending_notify_fd_);
malosek's avatar
malosek committed
60 61 62 63

        //  Send data as one APDU, transmit window owned memory.
        size_t send (unsigned char *data_, size_t data_len_);

Martin Sustrik's avatar
Martin Sustrik committed
64 65
        //  Returns max tsdu size without fragmentation.
        size_t get_max_tsdu_size ();
malosek's avatar
malosek committed
66 67

        //  Receive data from pgm socket.
malosek's avatar
malosek committed
68
        ssize_t receive (void **data_, const pgm_tsi_t **tsi_);
malosek's avatar
malosek committed
69 70 71

        //  POLLIN on sender side should mean NAK or SPMR receiving. 
        //  process_upstream function is used to handle such a situation.
72
        void process_upstream ();
malosek's avatar
malosek committed
73

74
    private:
malosek's avatar
malosek committed
75 76
    
        //  OpenPGM transport
Martin Sustrik's avatar
Martin Sustrik committed
77
        pgm_transport_t* transport;
malosek's avatar
malosek committed
78

malosek's avatar
malosek committed
79 80 81
        //  Associated socket options.
        options_t options;
       
malosek's avatar
malosek committed
82 83 84
        //  true when pgm_socket should create receiving side.
        bool receiver;

Martin Sustrik's avatar
Martin Sustrik committed
85
        //  Array of pgm_msgv_t structures to store received data
malosek's avatar
malosek committed
86 87 88
        //  from the socket (pgm_transport_recvmsgv).
        pgm_msgv_t *pgm_msgv;

Martin Sustrik's avatar
Martin Sustrik committed
89 90 91
        //  Size of pgm_msgv array.
        size_t pgm_msgv_len;

malosek's avatar
malosek committed
92
        // How many bytes were read from pgm socket.
malosek's avatar
malosek committed
93
        size_t nbytes_rec;
malosek's avatar
malosek committed
94 95

        //  How many bytes were processed from last pgm socket read.
malosek's avatar
malosek committed
96
        size_t nbytes_processed;
malosek's avatar
malosek committed
97 98
        
        //  How many messages from pgm_msgv were already sent up.
malosek's avatar
malosek committed
99
        size_t pgm_msgv_processed;
malosek's avatar
malosek committed
100 101 102 103 104
    };
}
#endif

#endif
105