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

View file

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