/// <summary> /// Add the socket of the KCD in the select sets as needed and manage /// ktlstunnel.exe processes. /// </summary> private void PrepareStateForSelect(KcdThreadHost k, SelectSockets selectSockets, bool quenchFlag, ref bool connWatchFlag) { // Note: the KCD should never have received a message when this function // is called. The function UpdateStateAfterSelect() is responsible for // doing all the transfers and handling any message received after these // transfers. try { k.CheckNoMessageReceivedInvariant(); if (k.ConnStatus == KcdThreadConnStatus.Scheduled) { // Start ktlstunnel.exe. k.ConnStatus = KcdThreadConnStatus.Connecting; k.Tunnel.BeginConnect(); } if (k.ConnStatus == KcdThreadConnStatus.Connecting) { // The TCP connection is now open. if (k.Tunnel.CheckConnect()) { // Send the select role command. k.SendSelectRoleMsg(); // Wait for the reply to arrive. k.ConnStatus = KcdThreadConnStatus.RoleReply; } // Wait for the TCP connection to be established. We busy wait // to monitor the status of ktlstunnel.exe regularly, to detect // the case where the connection fails. else { connWatchFlag = true; } } if (k.ConnStatus == KcdThreadConnStatus.RoleReply) { // Wait for the reply to arrive. if (!quenchFlag) { k.Tunnel.UpdateSelect(selectSockets); } } if (k.ConnStatus == KcdThreadConnStatus.Connected) { // Send the next message, if possible. k.SendNextQueuedMsgIfNeeded(); if (!quenchFlag) { k.Tunnel.UpdateSelect(selectSockets); } } k.CheckNoMessageReceivedInvariant(); } catch (Exception ex) { HandleDisconnectedKcd(k, ex); } }
/// <summary> /// Add the socket of the KCD in the select sets as needed and manage /// ktlstunnel.exe processes. /// </summary> private void PrepareStateForSelect(KcdThreadHost k, SelectSockets selectSockets, bool quenchFlag, ref bool connWatchFlag) { // Note: the KCD should never have received a message when this function // is called. The function UpdateStateAfterSelect() is responsible for // doing all the transfers and handling any message received after these // transfers. try { k.CheckNoMessageReceivedInvariant(); if (k.ConnStatus == KcdThreadConnStatus.Scheduled) { // Start ktlstunnel.exe. k.ConnStatus = KcdThreadConnStatus.Connecting; k.Tunnel.BeginConnect(); } if (k.ConnStatus == KcdThreadConnStatus.Connecting) { // The TCP connection is now open. if (k.Tunnel.CheckConnect()) { // Send the select role command. k.SendSelectRoleMsg(); // Wait for the reply to arrive. k.ConnStatus = KcdThreadConnStatus.RoleReply; } // Wait for the TCP connection to be established. We busy wait // to monitor the status of ktlstunnel.exe regularly, to detect // the case where the connection fails. else connWatchFlag = true; } if (k.ConnStatus == KcdThreadConnStatus.RoleReply) { // Wait for the reply to arrive. if (!quenchFlag) k.Tunnel.UpdateSelect(selectSockets); } if (k.ConnStatus == KcdThreadConnStatus.Connected) { // Send the next message, if possible. k.SendNextQueuedMsgIfNeeded(); if (!quenchFlag) k.Tunnel.UpdateSelect(selectSockets); } k.CheckNoMessageReceivedInvariant(); } catch (Exception ex) { HandleDisconnectedKcd(k, ex); } }