/* * private ParcelFileDescriptor WaitTun() * { * while(!m_cancellationToken.IsCancellationRequested) * { * ParcelFileDescriptor tun = m_channel.FileDescriptor; * if(tun != null) * return tun; * * Utils.Sleep(THREAD_DELAY); * } * * return null; * } */ private void DoUpdate() { EddieLogger.Debug("DoUpdate - Begin"); while (!m_cancellationToken.IsCancellationRequested) { SupportTools.Sleep(THREAD_DELAY); NativeMethods.ovpn3_transport_stats stats = m_tunnel.GetTransportStats(); // EddieLogger.Debug("Tunnel stats: bytes_in={0}, bytes_out={1}, packets_in={2}, packets_out={3}, last_packet_received={4}", stats.bytes_in, stats.bytes_out, stats.packets_in, stats.packets_out, stats.last_packet_received); } EddieLogger.Debug("DoUpdate - End"); /* * FileInputStream channelIn = null; * FileOutputStream channelOut = null; * FileInputStream tunnelIn = null; * FileOutputStream tunnelOut = null; * * try * { * string inError = null; * string outError = null; * * channelIn = new FileInputStream(m_channelFileDescriptor.FileDescriptor); * channelOut = new FileOutputStream(m_channelFileDescriptor.FileDescriptor); * * tunnelIn = new FileInputStream(m_tunnelFileDescriptor.FileDescriptor); * tunnelOut = new FileOutputStream(m_tunnelFileDescriptor.FileDescriptor); * * TaskEx taskIn = Service.TasksManager.Add((CancellationToken c) => * { * ReadPackets(channelIn, tunnelOut, c, out inError); * }); * * TaskEx taskOut = Service.TasksManager.Add((CancellationToken c) => * { * WritePackets(tunnelIn, channelOut, c, out outError); * }); * * bool loop = true; * * while(loop) * { * Utils.Sleep(THREAD_DELAY); * * // TODO: update stats * * if(taskIn.IsCompleted || taskOut.IsCompleted || m_cancellationToken.IsCancellationRequested) * loop = false; * } * * EddieLogger.Debug("ExchangeData2"); * * taskIn.Cancel(); * taskIn.Wait(); * * EddieLogger.Debug("ExchangeData3"); * * taskOut.Cancel(); * taskOut.Wait(); * * EddieLogger.Debug("ExchangeData4"); * * if(Utils.Empty(inError) == false) * throw new Exception(inError); * * if(Utils.Empty(outError) == false) * throw new Exception(outError); * } * finally * { * Utils.SafeDispose(channelIn); * Utils.SafeDispose(channelOut); * * Utils.SafeDispose(tunnelIn); * Utils.SafeDispose(tunnelOut); * } * * EddieLogger.Debug("ExchangeData5"); */ }