示例#1
0
        /// <summary>
        /// Begin an async SNMP request
        /// </summary>
        /// <param name="peer">Pdu to send to the agent</param>
        /// <param name="port">Callback to receive response from the agent</param>
        /// <param name="buffer">Buffer containing data to send to the peer</param>
        /// <param name="bufferLength">Length of data in the buffer</param>
        /// <param name="timeout">Request timeout in milliseconds</param>
        /// <param name="retries">Maximum retry count. 0 = single request no further retries.</param>
        /// <param name="asyncCallback">Callback that will receive the status and result of the operation</param>
        /// <returns>Returns false if another request is already in progress or if socket used by the class
        /// has been closed using Dispose() member, otherwise true</returns>
        /// <exception cref="SnmpException">Thrown when IPv4 address is passed to the v6 socket or vice versa</exception>
        internal bool RequestAsync(IPAddress peer, int port, byte[] buffer, int bufferLength, int timeout, int retries, SnmpAsyncCallback asyncCallback)
        {
            if (_busy == true)
            {
                return(false);
            }
            if (_socket == null)
            {
                return(false); // socket has been closed. no new operations are possible.
            }

            if (_socket.AddressFamily != peer.AddressFamily)
            {
                throw new SnmpException("Invalid address protocol version.");
            }
            _busy                      = true;
            _asyncCallback             = null;
            _asyncCallback            += asyncCallback;
            _requestState              = new AsyncRequestState(peer, port, retries, timeout);
            _requestState.Packet       = buffer;
            _requestState.PacketLength = bufferLength;

            // _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _requestState.Timeout);

            _inBuffer = new byte[64 * 1024]; // create incoming data buffer

            SendToBegin();                   // Send the request

            return(true);
        }
示例#2
0
        /// <summary>
        /// Begin an async SNMP request
        /// </summary>
        /// <param name="peer">Pdu to send to the agent</param>
        /// <param name="port">Callback to receive response from the agent</param>
        /// <param name="buffer">Buffer containing data to send to the peer</param>
        /// <param name="bufferLength">Length of data in the buffer</param>
        /// <param name="timeout">Request timeout in milliseconds</param>
        /// <param name="retries">Maximum retry count. 0 = single request no further retries.</param>
        /// <param name="asyncCallback">Callback that will receive the status and result of the operation</param>
        /// <returns>Returns false if another request is already in progress or if socket used by the class
        /// has been closed using Dispose() member, otherwise true</returns>
        /// <exception cref="SnmpException">Thrown when IPv4 address is passed to the v6 socket or vice versa</exception>
        internal bool RequestAsync(IPAddress peer, int port, byte[] buffer, int bufferLength, int timeout, int retries, SnmpAsyncCallback asyncCallback)
        {
            if (_busy == true)
            {
                return false;
            }
            if (_socket == null)
            {
                return false; // socket has been closed. no new operations are possible.
            }

            if (_socket.AddressFamily != peer.AddressFamily)
                throw new SnmpException("Invalid address protocol version.");
            _busy = true;
            _asyncCallback = null;
            _asyncCallback += asyncCallback;
            _requestState = new AsyncRequestState(peer, port, retries, timeout);
            _requestState.Packet = buffer;
            _requestState.PacketLength = bufferLength;

            // _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _requestState.Timeout);

            _inBuffer = new byte[64 * 1024]; // create incoming data buffer

            SendToBegin(); // Send the request

            return true;
        }