00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#ifndef MN_RTP_REF_COUNTED_SOCKET_H
00025
#define MN_RTP_REF_COUNTED_SOCKET_H
00026
00027
00028
#include <assert.h>
00029
#include <stdio.h>
00030
#include <sys/types.h>
00031
00032
#include "MNArrayList.h"
00033
#include "DatagramSocket.h"
00034
#include "MNMutex.h"
00035
#include "MNValid.h"
00036
00037
class RefCountedSocket;
00038
class RefCountedSocketFactory;
00039
class RefCountingSocket;
00040
class MNRope;
00041
00042
00043
00044
00045
00073
class RefCountedSocket :
public DatagramSocket
00074 {
00075 DECLARE_VALID
00076
00077
private:
00078
struct MulticastInfo
00079 {
00082
MNUDPServerSocket::Interfaces* _iface;
00083
00088
int _port;
00089
00092
char* _addr;
00093
00096
bool _joined;
00097
00100 MulticastInfo();
00101
00102 ~MulticastInfo();
00103 };
00104
00106 size_t _refCtr;
00107
00111
MNArrayList<RefCountingSocket*> _notificationList;
00112
00115 MulticastInfo _mc;
00116
00120
RefCountedSocketFactory* _factory;
00121
00122
private:
00124 RefCountedSocket(
const RefCountedSocket& );
00125
00127 RefCountedSocket&
operator=(
const RefCountedSocket& );
00128
00129
public:
00130 RefCountedSocket(
RefCountedSocketFactory* factory,
00131
MNSelector& sel,
00132
MNSocket& sock );
00133
00134 RefCountedSocket(
RefCountedSocketFactory* factory,
00135
MNSelector& sel,
00136
int port );
00137
00149
virtual ~RefCountedSocket( );
00150
00156
void attach( );
00157
00160
void detach( );
00161
00166
void startReading(
RefCountingSocket* s,
bool sender );
00167
00171
void stopReading(
RefCountingSocket* s );
00172
00185
bool release(
RefCountingSocket* s );
00186
00190
virtual int reader (
struct iovec* iov,
00191
int len,
00192
struct sockaddr_in*& dest );
00193
00194
virtual int reader (
MNRope*& rope,
00195
struct sockaddr_in*& dest );
00196
00197
00198
virtual void writer ( );
00199
00203
virtual void connection_closed( );
00204
00216
struct ifi_info* get_ifi_info(
int family,
int doaliases);
00217
00226
bool join_multicast(
int port,
const char* address );
00227
00230
bool is_multicast_joined( ) const;
00231
00235
void leaveMulticast( );
00236
00240
void set_multicast_ttl(
int val );
00241
00245
int get_multicast_ttl( );
00246
00250
void set_multicast_if( const
char* ifname );
00251
00270
int send( struct iovec* iov,
00271 size_t iov_size,
00272
int target_port,
00273 const
char* target_host );
00274
00286
int send( struct iovec* iov,
00287 size_t iov_size,
00288 const struct sockaddr_in& sock_addr );
00289
00299
int send(
MNRope* rope,
00300 const struct sockaddr_in& sock_addr );
00301 };
00302
00303 #endif
00304