NetMQ.Core.Transports.Pgm.PgmSocket.InitOptions C# (CSharp) Method

InitOptions() private method

private InitOptions ( ) : void
return void
        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);
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// This method is called when a message receive operation has been completed.
        /// </summary>
        /// <param name="socketError">a SocketError value that indicates whether Success or an error occurred</param>
        /// <param name="bytesTransferred">the number of bytes that were transferred</param>
        public void InCompleted(SocketError socketError, int bytesTransferred)
        {
            if (socketError != SocketError.Success)
            {
                m_socket.EventAcceptFailed(m_address.ToString(), socketError.ToErrorCode());

                // dispose old object
                m_acceptedSocket.Handle.Dispose();

                Accept();
            }
            else
            {
                m_acceptedSocket.InitOptions();

                var pgmSession = new PgmSession(m_acceptedSocket, m_options);

                IOThread ioThread = ChooseIOThread(m_options.Affinity);

                SessionBase session = SessionBase.Create(ioThread, false, m_socket, m_options, new Address(m_handle.LocalEndPoint));

                session.IncSeqnum();
                LaunchChild(session);
                SendAttach(session, pgmSession, false);
                m_socket.EventAccepted(m_address.ToString(), m_acceptedSocket.Handle);

                Accept();
            }
        }
All Usage Examples Of NetMQ.Core.Transports.Pgm.PgmSocket::InitOptions