Exemplo n.º 1
0
 public void CloseConnect(long handle)
 {
     if (Connects.ContainsKey(handle) == false)
     {
         return;
     }
     try
     {
         Connects[handle].Socket.Shutdown(SocketShutdown.Both);
     }
     // throws if client process has already closed
     catch (Exception)
     {
     }
     if (Connects.ContainsKey(handle) == false)
     {
         return;
     }
     Connects[handle].Socket.Close();
     Connects[handle].ClientArgs.Dispose();
     Connects.TryRemove(handle, out Link link);
     OnSocketClose?.Invoke(handle);
     //SocketAsyncEventArgs eventArgs = GetFreeEventArgs();
     //eventArgs.UserToken = Connects[handle];
     //Connects[handle].Socket.DisconnectAsync(eventArgs);
 }
Exemplo n.º 2
0
        //Добавить соединение в поток
        public ProviderConnect AddConnect(string code)
        {
            var con = Connects[code];

            if (!Connects.ContainsKey(code))
            {
                var scon = Project.SchemeConnects[code];
                con = ProvidersFactory.CreateConnect(Logger, scon.Type, scon.Code, scon.Complect, Project.Code);
                con = Connects.Add(code, con);
                if (con.Type == ProviderType.Source)
                {
                    _sources.Add(con.Code, (SourceConnect)con);
                }
                if (con.Type == ProviderType.Receiver)
                {
                    _receivers.Add(con.Code, (ReceiverConnect)con);
                }
                if (!scon.ProviderCode.IsEmpty() && !scon.ProviderInf.IsEmpty())
                {
                    con.JoinProvider(ProvidersFactory.CreateProvider(Logger, scon.ProviderCode, scon.ProviderInf, Project.Code));
                }
            }
            return(con);
        }