/// <summary> /// Exchange messages with Outlook. /// </summary> private void ChatWithOutlook() { Debug.Assert(m_msgQueue.Count == 0); Debug.Assert(m_chattingFlag); try { AnpTransport transport = new AnpTransport(m_outlookSock); while (true) { if (!transport.isReceiving) transport.beginRecv(); if (!transport.isSending && m_msgQueue.Count != 0) transport.sendMsg(m_msgQueue.Dequeue()); SelectSockets select = new SelectSockets(); select.AddRead(m_outlookSock); if (transport.isSending) select.AddWrite(m_outlookSock); Block(select); transport.doXfer(); if (transport.doneReceiving) { OutlookUiThreadMsg msg = new OutlookUiThreadMsg(m_broker, OutlookBrokerMsgType.ReceivedMsg); msg.Msg = transport.getRecv(); PostToUI(msg); } } } catch (Exception ex) { m_chattingFlag = false; CloseOutlookSock(); m_msgQueue.Clear(); if (ex is WorkerCancellationException) throw; OutlookUiThreadMsg msg = new OutlookUiThreadMsg(m_broker, OutlookBrokerMsgType.Disconnected); msg.Ex = ex; PostToUI(msg); } }
/// <summary> /// Close the connection to ktlstunnel. /// </summary> public void Disconnect() { tunnel.Disconnect(); transport = null; }
/// <summary> /// Kill ktlstunnel. /// </summary> public void Terminate() { tunnel.Terminate(); transport = null; }
/// <summary> /// Create an AnpTransport when the tunnel is connected. /// </summary> public void CreateTransport() { transport = new AnpTransport(tunnel.EndTls()); transport.beginRecv(); }