groupsock/include/GroupsockHelper.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "mTunnel" multicast access service
00017 // Copyright (c) 1996-2014 Live Networks, Inc.  All rights reserved.
00018 // Helper routines to implement 'group sockets'
00019 // C++ header
00020 
00021 #ifndef _GROUPSOCK_HELPER_HH
00022 #define _GROUPSOCK_HELPER_HH
00023 
00024 #ifndef _NET_ADDRESS_HH
00025 #include "NetAddress.hh"
00026 #endif
00027 
00028 int setupDatagramSocket(UsageEnvironment& env, Port port);
00029 int setupStreamSocket(UsageEnvironment& env,
00030                       Port port, Boolean makeNonBlocking = True);
00031 
00032 int readSocket(UsageEnvironment& env,
00033                int socket, unsigned char* buffer, unsigned bufferSize,
00034                struct sockaddr_in& fromAddress);
00035 
00036 Boolean writeSocket(UsageEnvironment& env,
00037                     int socket, struct in_addr address, Port port,
00038                     u_int8_t ttlArg,
00039                     unsigned char* buffer, unsigned bufferSize);
00040 
00041 Boolean writeSocket(UsageEnvironment& env,
00042                     int socket, struct in_addr address, Port port,
00043                     unsigned char* buffer, unsigned bufferSize);
00044     // An optimized version of "writeSocket" that omits the "setsockopt()" call to set the TTL.
00045 
00046 unsigned getSendBufferSize(UsageEnvironment& env, int socket);
00047 unsigned getReceiveBufferSize(UsageEnvironment& env, int socket);
00048 unsigned setSendBufferTo(UsageEnvironment& env,
00049                          int socket, unsigned requestedSize);
00050 unsigned setReceiveBufferTo(UsageEnvironment& env,
00051                             int socket, unsigned requestedSize);
00052 unsigned increaseSendBufferTo(UsageEnvironment& env,
00053                               int socket, unsigned requestedSize);
00054 unsigned increaseReceiveBufferTo(UsageEnvironment& env,
00055                                  int socket, unsigned requestedSize);
00056 
00057 Boolean makeSocketNonBlocking(int sock);
00058 Boolean makeSocketBlocking(int sock, unsigned writeTimeoutInMilliseconds = 0);
00059   // A "writeTimeoutInMilliseconds" value of 0 means: Don't timeout
00060 
00061 Boolean socketJoinGroup(UsageEnvironment& env, int socket,
00062                         netAddressBits groupAddress);
00063 Boolean socketLeaveGroup(UsageEnvironment&, int socket,
00064                          netAddressBits groupAddress);
00065 
00066 // source-specific multicast join/leave
00067 Boolean socketJoinGroupSSM(UsageEnvironment& env, int socket,
00068                            netAddressBits groupAddress,
00069                            netAddressBits sourceFilterAddr);
00070 Boolean socketLeaveGroupSSM(UsageEnvironment&, int socket,
00071                             netAddressBits groupAddress,
00072                             netAddressBits sourceFilterAddr);
00073 
00074 Boolean getSourcePort(UsageEnvironment& env, int socket, Port& port);
00075 
00076 netAddressBits ourIPAddress(UsageEnvironment& env); // in network order
00077 
00078 // IP addresses of our sending and receiving interfaces.  (By default, these
00079 // are INADDR_ANY (i.e., 0), specifying the default interface.)
00080 extern netAddressBits SendingInterfaceAddr;
00081 extern netAddressBits ReceivingInterfaceAddr;
00082 
00083 // Allocates a randomly-chosen IPv4 SSM (multicast) address:
00084 netAddressBits chooseRandomIPv4SSMAddress(UsageEnvironment& env);
00085 
00086 // Returns a simple "hh:mm:ss" string, for use in debugging output (e.g.)
00087 char const* timestampString();
00088 
00089 
00090 #ifdef HAVE_SOCKADDR_LEN
00091 #define SET_SOCKADDR_SIN_LEN(var) var.sin_len = sizeof var
00092 #else
00093 #define SET_SOCKADDR_SIN_LEN(var)
00094 #endif
00095 
00096 #define MAKE_SOCKADDR_IN(var,adr,prt) /*adr,prt must be in network order*/\
00097     struct sockaddr_in var;\
00098     var.sin_family = AF_INET;\
00099     var.sin_addr.s_addr = (adr);\
00100     var.sin_port = (prt);\
00101     SET_SOCKADDR_SIN_LEN(var);
00102 
00103 
00104 // By default, we create sockets with the SO_REUSE_* flag set.
00105 // If, instead, you want to create sockets without the SO_REUSE_* flags,
00106 // Then enclose the creation code with:
00107 //          {
00108 //            NoReuse dummy;
00109 //            ...
00110 //          }
00111 class NoReuse {
00112 public:
00113   NoReuse(UsageEnvironment& env);
00114   ~NoReuse();
00115 
00116 private:
00117   UsageEnvironment& fEnv;
00118 };
00119 
00120 
00121 // Define the "UsageEnvironment"-specific "groupsockPriv" structure:
00122 
00123 struct _groupsockPriv { // There should be only one of these allocated
00124   HashTable* socketTable;
00125   int reuseFlag;
00126 };
00127 _groupsockPriv* groupsockPriv(UsageEnvironment& env); // allocates it if necessary
00128 void reclaimGroupsockPriv(UsageEnvironment& env);
00129 
00130 
00131 #if defined(__WIN32__) || defined(_WIN32)
00132 // For Windoze, we need to implement our own gettimeofday()
00133 extern int gettimeofday(struct timeval*, int*);
00134 #endif
00135 
00136 // The following are implemented in inet.c:
00137 extern "C" netAddressBits our_inet_addr(char const*);
00138 extern "C" void our_srandom(int x);
00139 extern "C" long our_random();
00140 extern "C" u_int32_t our_random32(); // because "our_random()" returns a 31-bit number
00141 
00142 #endif

Generated on Tue Oct 21 01:14:17 2014 for live by  doxygen 1.5.2