internal void InitOptions()
{
// Enable gigabit on the socket
Handle.SetSocketOption(PgmLevel, EnableGigabitOption, BitConverter.GetBytes((uint)1));
// set the receive buffer size for receiver and listener
if (m_options.ReceiveBuffer > 0 && (m_pgmSocketType == PgmSocketType.Receiver || m_pgmSocketType == PgmSocketType.Listener))
{
Handle.ReceiveBufferSize = m_options.ReceiveBuffer;
}
// set the send buffer for the publisher
if (m_options.SendBuffer > 0 && m_pgmSocketType == PgmSocketType.Publisher)
{
Handle.SendBufferSize = m_options.SendBuffer;
}
// set the receive interface on the listener and receiver
if (m_pgmSocketType == PgmSocketType.Listener || m_pgmSocketType == PgmSocketType.Receiver)
{
if (m_pgmAddress.InterfaceAddress != null)
{
Handle.SetSocketOption(PgmLevel, RM_ADD_RECEIVE_IF, m_pgmAddress.InterfaceAddress.GetAddressBytes());
}
}
else if (m_pgmSocketType == PgmSocketType.Publisher)
{
// set multicast hops for the publisher
Handle.SetSocketOption(PgmLevel, RM_SET_MCAST_TTL, m_options.MulticastHops);
// set the publisher send interface
if (m_pgmAddress.InterfaceAddress != null)
{
Handle.SetSocketOption(PgmLevel, RM_SET_SEND_IF, m_pgmAddress.InterfaceAddress.GetAddressBytes());
}
// instead of using the struct _RM_SEND_WINDOW we are using byte array of size 12 (the size of the original struct and the size of three ints)
// typedef struct _RM_SEND_WINDOW {
// ULONG RateKbitsPerSec;
// ULONG WindowSizeInMSecs;
// ULONG WindowSizeInBytes;
//} RM_SEND_WINDOW;
var sendWindow = new byte[12];
// setting the rate of the transmission in Kilobits per second
var rate = (uint)(m_options.Rate);
Array.Copy(BitConverter.GetBytes(rate), 0, sendWindow, 0, 4);
// setting the recovery interval
var sizeInMS = (uint)(m_options.RecoveryIvl);
Array.Copy(BitConverter.GetBytes(sizeInMS), 0, sendWindow, 4, 4);
// we are not setting the size in bytes because it get filled automatically, if we want to set it we would just uncomment the following lines
//uint sizeInBytes = (uint)((rate / 8.0) * sizeInMS);
//Array.Copy(BitConverter.GetBytes(sizeInBytes), 0, sendWindow, 8, 4);
Handle.SetSocketOption(PgmLevel, RM_RATE_WINDOW_SIZE, sendWindow);
}
}