libzmq/src/pgm_socket.hpp

116 lines
3.3 KiB
C++
Raw Normal View History

2009-09-11 17:58:37 +02:00
/*
Copyright (c) 2007-2010 iMatix Corporation
2009-09-11 17:58:37 +02:00
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
2009-09-11 17:58:37 +02:00
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
GNU Lesser General Public License for more details.
2009-09-11 17:58:37 +02:00
You should have received a copy of the GNU Lesser General Public License
2009-09-11 17:58:37 +02:00
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"
2009-09-24 16:23:49 +02:00
#if defined ZMQ_HAVE_OPENPGM
2009-09-11 17:58:37 +02:00
#ifdef ZMQ_HAVE_WINDOWS
#include "windows.hpp"
2009-09-11 17:58:37 +02:00
#endif
#define __PGM_WININT_H__
#include <pgm/pgm.h>
// TODO: OpenPGM redefines bool -- remove this once OpenPGM is fixed.
#if defined bool
#undef bool
#endif
2009-09-11 17:58:37 +02:00
#include "options.hpp"
namespace zmq
{
// Encapsulates PGM socket.
class pgm_socket_t
{
public:
2009-09-11 17:58:37 +02:00
// If receiver_ is true PGM transport is not generating SPM packets.
pgm_socket_t (bool receiver_, const options_t &options_);
// Closes the transport.
~pgm_socket_t ();
// Initialize PGM network structures (GSI, GSRs).
int init (bool udp_encapsulation_, const char *network_);
2009-09-11 17:58:37 +02:00
// Get receiver fds and store them into user allocated memory.
2009-12-13 11:27:43 +01:00
void get_receiver_fds (int *receive_fd_, int *waiting_pipe_fd_);
2009-09-11 17:58:37 +02:00
// Get sender and receiver fds and store it to user allocated
// memory. Receive fd is used to process NAKs from peers.
2009-12-13 11:27:43 +01:00
void get_sender_fds (int *send_fd_, int *receive_fd_,
int *rdata_notify_fd_, int *pending_notify_fd_);
2009-09-11 17:58:37 +02:00
// Send data as one APDU, transmit window owned memory.
size_t send (unsigned char *data_, size_t data_len_);
2009-12-28 11:51:06 +01:00
// Returns max tsdu size without fragmentation.
size_t get_max_tsdu_size ();
2009-09-11 17:58:37 +02:00
// Receive data from pgm socket.
2009-09-22 15:12:51 +02:00
ssize_t receive (void **data_, const pgm_tsi_t **tsi_);
2009-09-11 17:58:37 +02:00
2010-09-28 22:46:56 +02:00
long get_rx_timeout ();
long get_tx_timeout ();
2009-09-11 17:58:37 +02:00
// POLLIN on sender side should mean NAK or SPMR receiving.
// process_upstream function is used to handle such a situation.
2009-12-13 11:27:43 +01:00
void process_upstream ();
2009-09-11 17:58:37 +02:00
2009-12-13 11:27:43 +01:00
private:
2009-09-11 17:58:37 +02:00
// OpenPGM transport.
2010-09-28 16:35:29 +02:00
pgm_sock_t* sock;
2009-09-11 17:58:37 +02:00
2010-09-28 22:46:56 +02:00
int last_rx_status, last_tx_status;
2009-09-22 15:12:51 +02:00
// Associated socket options.
options_t options;
2009-09-11 17:58:37 +02:00
// true when pgm_socket should create receiving side.
bool receiver;
2009-12-28 11:51:06 +01:00
// Array of pgm_msgv_t structures to store received data
2009-09-11 17:58:37 +02:00
// from the socket (pgm_transport_recvmsgv).
pgm_msgv_t *pgm_msgv;
2009-12-28 11:51:06 +01:00
// Size of pgm_msgv array.
size_t pgm_msgv_len;
2009-09-11 17:58:37 +02:00
// How many bytes were read from pgm socket.
2009-09-25 17:50:12 +02:00
size_t nbytes_rec;
2009-09-11 17:58:37 +02:00
// How many bytes were processed from last pgm socket read.
2009-09-25 17:50:12 +02:00
size_t nbytes_processed;
2009-09-11 17:58:37 +02:00
// How many messages from pgm_msgv were already sent up.
2009-09-25 17:50:12 +02:00
size_t pgm_msgv_processed;
2009-09-11 17:58:37 +02:00
};
}
#endif
#endif