private void ThreadConnectionProc(object state) { while (true) { try { Socket s = _srvSocket.Accept(); if (s != null) { IChannel ch = new SocketChannel(s, true); /// TODO: Implement a generic mechanism to decouple Port from the type of channel to be created if (_channelMgr != null) { IPEndPoint p = (IPEndPoint)s.RemoteEndPoint; String uri = TcpIpUri.AddressPortAsUri(p.Address.ToString(), p.Port); ch.Uri = uri; //>> LDRTEST // Check if there is an old version of the channel // This means that the closing of the socket was not detected if (_channelMgr.GetChannel(uri) != null) { _channelMgr.CloseChannel(uri); CommMain.Logger.AddLog("Port.ThreadConnectionProc: Forced to close channel: " + uri, LoggerSeverities.Error); } //<< LDRTEST _channelMgr.AddChannel(uri, ch); } if (_connHandler != null) { _connHandler(ch); } else { CommMain.Logger.AddLog("WARNING: Port.NotifySendError: ThreadConnectionProc is null.", LoggerSeverities.Error); } //>> LDR 2004.07.16 SocketChannel sch = (SocketChannel)ch; sch.Run(); //<< LDR 2004.07.16 } } catch (SocketException sockEx) { CommMain.Logger.AddLog(sockEx); if (Closing) { break; } } catch (Exception ex) { CommMain.Logger.AddLog(ex); } } }
/// <summary> /// Returns the URI for the destination specified in a message row /// </summary> /// <param name="row">The row containing data for a message</param> /// <returns>The URI of the message destination</returns> private string GetDestinationUri(DataRow row) { string destURI = null; string addr = "0.0.0.0"; int port = Convert.ToInt32(row[(int)MsgsColumns.PortAdapter]); if (!DBNull.Value.Equals(row[(int)MsgsColumns.IpAdapter])) { addr = (string)row[(int)MsgsColumns.IpAdapter]; } else { addr = Configuration.AddressCache.GetAddressCache().GetUnitAddress( (decimal)row[(int)MsgsColumns.UniId]); } destURI = TcpIpUri.AddressPortAsUri(addr, port); return(destURI); }