コード例 #1
0
        /// <summary>
        /// Adds a connection handler to track.
        /// </summary>
        /// <param name="commandHandle">The command handle to use when tracking the handler.</param>
        /// <param name="handler">The handler to track.</param>
        /// <returns>The handle of the command the handler is associated with.</returns>
        private static int AddConnectionOpenedHandler(int commandHandle, ConnectionOpenedHandler handler)
        {
            Debug.Assert(!_connectionOpenedHandlers.ContainsKey(commandHandle));
            _connectionOpenedHandlers.Add(commandHandle, handler);

            return(commandHandle);
        }
コード例 #2
0
        /// <summary>
        /// Creates a listener than can be connected to by other agents.
        /// </summary>
        /// <param name="endpoint">The endpoint the agent is to be exposed on.</param>
        /// <param name="connectionOpenedHandler">The observer that will receive connection events from the listener.</param>
        /// <returns>An asynchronous task that returns a Listener result.</returns>
        public static Task <Listener> AgentListenAsync(string endpoint, ConnectionOpenedHandler connectionOpenedHandler)
        {
            var taskCompletionSource = new TaskCompletionSource <Listener>();
            var commandHandle        = AddTaskCompletionSource(taskCompletionSource);

            AddConnectionOpenedHandler(commandHandle, connectionOpenedHandler);

            var result = IndyNativeMethods.indy_agent_listen(
                commandHandle,
                endpoint,
                _listenerCreatedCallback,
                _listenerConnectionEstablishedCallback,
                _agentListenerMessageReceivedCallback);

            CheckResult(result);

            return(taskCompletionSource.Task);
        }