Ejemplo n.º 1
0
        private async Task SetupClient(Socket client)
        {
            lock (_pending)
            {
                _pending.Add(client);
            }

            _logger.LogVerbose(Properties.Resources.TcpNetworkListener_ConnectionLogString, _localEndpoint);

            StreamSocketDataAdapter  da = new StreamSocketDataAdapter(client, _localEndpoint.ToString());
            ClientConnectedEventArgs e  = new ClientConnectedEventArgs(da);

            NetUtils.PopulateBagFromSocket(client, e.Properties);

            try
            {
                await Task.Run(() => ClientConnected.Invoke(this, e));
            }
            catch
            {
                client.Dispose();
            }
            finally
            {
                lock (_pending)
                {
                    _pending.Remove(client);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Connect socket.
        /// </summary>
        /// <param name="token">The proxy token (ignored).</param>
        /// <param name="logger">The logger object.</param>
        /// <param name="meta">Connection meta-data.</param>
        /// <param name="globalMeta">Global meta-data.</param>
        /// <param name="properties">Properties for the connection.</param>
        /// <returns>The connected data adapater.</returns>
        public override IDataAdapter Connect(ProxyToken token, Logger logger,
                                             MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties)
        {
            IDataAdapter adapter = null;

            try
            {
                Socket socket = new Socket(_endPoint.AddressFamily, SocketType.Stream, _protocolType);
                socket.Connect(_endPoint);
                NetUtils.PopulateBagFromSocket(socket, properties);

                adapter = new StreamSocketDataAdapter(socket);
            }
            catch (SocketException ex)
            {
                logger.LogException(ex);
                token.Status = NetStatusCodes.ConnectFailure;
            }
            catch (IOException ex)
            {
                logger.LogException(ex);
                token.Status = NetStatusCodes.ConnectFailure;
            }

            return(adapter);
        }