* Added logging messages.

* Implemented ping.
This commit is contained in:
Paulo Rogerio Panhoto 2018-02-22 18:14:07 -03:00
parent 2c8ea9c7ec
commit b71a72343c
2 changed files with 11 additions and 1 deletions

View file

@ -199,6 +199,7 @@ namespace TLSharp.Core.Network
uint code = messageReader.ReadUInt32();
messageReader.BaseStream.Position -= 4;
logger.Info("Processing message {0:x8}", code);
switch (code)
{
case 0x73f1f8dc: // container
@ -243,7 +244,7 @@ namespace TLSharp.Core.Network
case 0x11f1331c:
return HandleUpdate(code, sequence, messageReader, request);
default:
Console.WriteLine ("Msg code: {0:x8}", code);
logger.Info("unhandled message");
return false;
}
}

View file

@ -120,6 +120,8 @@ namespace TLSharp.Core
public async Task MainLoopAsync(int timeslicems)
{
logger.Trace("Entered loop");
await SendPingAsync();
var lastPing = DateTime.UtcNow;
for (;;)
{
try
@ -131,6 +133,12 @@ namespace TLSharp.Core
}
finally
{
var now = DateTime.UtcNow;
if ((now - lastPing).TotalSeconds >= 30)
{
await SendPingAsync();
lastPing = now;
}
if (IdleLoop != null)
{
logger.Trace("Running idle tasks");
@ -262,6 +270,7 @@ namespace TLSharp.Core
}
public async Task<T> SendRequestAsync<T>(TLMethod methodToExecute)
{
logger.Info("Sending Request: {0} {1:x8}", methodToExecute, methodToExecute.Constructor);
await RequestWithDcMigration(methodToExecute);
var result = methodToExecute.GetType().GetProperty("Response").GetValue(methodToExecute);