libzmq master
The Intelligent Transport Layer

pgm_socket.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2009-2011 250bpm s.r.o.
00003     Copyright (c) 2007-2009 iMatix Corporation
00004     Copyright (c) 2010-2011 Miru Limited
00005     Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
00006 
00007     This file is part of 0MQ.
00008 
00009     0MQ is free software; you can redistribute it and/or modify it under
00010     the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation; either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     0MQ is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 
00023 #ifndef __PGM_SOCKET_HPP_INCLUDED__
00024 #define __PGM_SOCKET_HPP_INCLUDED__
00025 
00026 #include "platform.hpp"
00027 
00028 #if defined ZMQ_HAVE_OPENPGM
00029 
00030 #ifdef ZMQ_HAVE_WINDOWS
00031 #include "windows.hpp"
00032 #define __PGM_WININT_H__
00033 #endif
00034 
00035 #include <pgm/pgm.h>
00036 
00037 #ifdef ZMQ_HAVE_OSX
00038 #include <pgm/in.h>
00039 #endif
00040 
00041 #include "fd.hpp"
00042 #include "options.hpp"
00043 
00044 namespace zmq
00045 {
00046     //  Encapsulates PGM socket.
00047     class pgm_socket_t
00048     {
00049 
00050     public:
00051 
00052         //  If receiver_ is true PGM transport is not generating SPM packets.
00053         pgm_socket_t (bool receiver_, const options_t &options_);
00054 
00055         //  Closes the transport.
00056         ~pgm_socket_t ();
00057 
00058         //  Initialize PGM network structures (GSI, GSRs).
00059         int init (bool udp_encapsulation_, const char *network_);
00060         
00061         //   Get receiver fds and store them into user allocated memory.
00062         void get_receiver_fds (fd_t *receive_fd_, fd_t *waiting_pipe_fd_);
00063 
00064         //   Get sender and receiver fds and store it to user allocated 
00065         //   memory. Receive fd is used to process NAKs from peers.
00066         void get_sender_fds (fd_t *send_fd_, fd_t *receive_fd_,
00067             fd_t *rdata_notify_fd_, fd_t *pending_notify_fd_);
00068 
00069         //  Send data as one APDU, transmit window owned memory.
00070         size_t send (unsigned char *data_, size_t data_len_);
00071 
00072         //  Returns max tsdu size without fragmentation.
00073         size_t get_max_tsdu_size ();
00074 
00075         //  Receive data from pgm socket.
00076         ssize_t receive (void **data_, const pgm_tsi_t **tsi_);
00077 
00078         long get_rx_timeout ();
00079         long get_tx_timeout ();
00080 
00081         //  POLLIN on sender side should mean NAK or SPMR receiving. 
00082         //  process_upstream function is used to handle such a situation.
00083         void process_upstream ();
00084 
00085     private:
00086 
00087         //  Compute size of the buffer based on rate and recovery interval.
00088         int compute_sqns (int tpdu_);
00089     
00090         //  OpenPGM transport.
00091         pgm_sock_t* sock;
00092 
00093         int last_rx_status, last_tx_status;
00094 
00095         //  Associated socket options.
00096         options_t options;
00097        
00098         //  true when pgm_socket should create receiving side.
00099         bool receiver;
00100 
00101         //  Array of pgm_msgv_t structures to store received data
00102         //  from the socket (pgm_transport_recvmsgv).
00103         pgm_msgv_t *pgm_msgv;
00104 
00105         //  Size of pgm_msgv array.
00106         size_t pgm_msgv_len;
00107 
00108         // How many bytes were read from pgm socket.
00109         size_t nbytes_rec;
00110 
00111         //  How many bytes were processed from last pgm socket read.
00112         size_t nbytes_processed;
00113         
00114         //  How many messages from pgm_msgv were already sent up.
00115         size_t pgm_msgv_processed;
00116     };
00117 }
00118 #endif
00119 
00120 #endif
00121 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines