# HG changeset patch # User sl # Date 1418732652 -3600 # Node ID f0dda362f77e2ed7c6215ed5caed7ccad40d2eaf # Parent 042c1fa136b9b3898aab81fd62c1b4b5823677fb Prevent stackoverflow when client reconnects. Client now specifies layout rather than relying on default one. diff -r 042c1fa136b9 -r f0dda362f77e Client/Client.cs --- a/Client/Client.cs Tue Dec 16 11:08:18 2014 +0100 +++ b/Client/Client.cs Tue Dec 16 13:24:12 2014 +0100 @@ -96,14 +96,16 @@ /// - /// + /// Handle connection with our Sharp Display Server. + /// If the connection is faulted it will attempt to restart it. /// public class DisplayClient { - Client iClient; - Callback iCallback; + private Client iClient; + private Callback iCallback; + private bool resetingConnection = false; + private MainForm MainForm { get; set; } - public string SessionId { get { return iClient.SessionId; } } public string Name { get; private set; } private TableLayout Layout { get; set; } @@ -117,12 +119,18 @@ Fields = new DataField[]{}; } + /// + /// Initialize our server connection. + /// public void Open() { iCallback = new Callback(MainForm); iClient = new Client(iCallback); } + /// + /// Terminate our server connection. + /// public void Close() { iClient.Close(); @@ -131,26 +139,45 @@ iCallback = null; } + /// + /// Tells whether a server connection is available. + /// + /// True if a server connection is available. False otherwise. public bool IsReady() { return (iClient != null && iCallback != null && iClient.IsReady()); } + /// + /// Check if our server connection is available and attempt reset it if it isn't. + /// This is notably dealing with timed out connections. + /// public void CheckConnection() { - if (!IsReady()) + if (!IsReady() && !resetingConnection) { //Try to reconnect Open(); - //On reconnect there is a bunch of properties we need to set - if (Name != "") + //Avoid stack overflow in case of persisting failure + resetingConnection = true; + + try { - iClient.SetName(Name); + //On reconnect there is a bunch of properties we need to reset + if (Name != "") + { + iClient.SetName(Name); + } + + SetLayout(Layout); + SetFields(Fields); } - - SetLayout(Layout); - SetFields(Fields); + finally + { + //Make sure our this state does not get out of sync + resetingConnection = true; + } } } diff -r 042c1fa136b9 -r f0dda362f77e Client/MainForm.cs --- a/Client/MainForm.cs Tue Dec 16 11:08:18 2014 +0100 +++ b/Client/MainForm.cs Tue Dec 16 13:24:12 2014 +0100 @@ -143,6 +143,11 @@ //iClient.SetText(1, "Bottom"); //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft); + //Set one column two lines layout + TableLayout layout = new TableLayout(1, 2); + iClient.SetLayout(layout); + + //Set our fields iClient.SetFields(new DataField[] { new DataField(0, textBoxTop.Text, Alignment),