Skip to content

connection keep alive #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: integration
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TallyDB/Core/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using static System.Environment;
using static System.Environment;

namespace TallyDB.Core
{
Expand All @@ -14,5 +14,6 @@ public static class Constants
#else
public static string TallyRoot = Path.Join(GetFolderPath(SpecialFolder.ApplicationData), "TallyDB/");
#endif
public static TimeSpan ConnectionTimeout = TimeSpan.FromMinutes(1);
}
}
11 changes: 11 additions & 0 deletions TallyDB/Server/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using TallyDB.Config;
using TallyDB.Config.Auth;
using TallyDB.Core;
using TallyDB.Server.QueryProcessor;
using TallyDB.Server.Types;

Expand All @@ -20,6 +21,7 @@ public void Handle(Socket client)
User? authUser = null;
var authStorage = new AuthStorage(new FileOperator());
var requestProcessor = new RequestProcessor();
var connectionTimeout = DateTime.Now.Add(Constants.ConnectionTimeout);

while (true)
{
Expand All @@ -42,6 +44,15 @@ public void Handle(Socket client)
value += (Convert.ToChar(data[i]));
}

#region Connection Keep Alive
// reset connection timeout
if (connectionTimeout < DateTime.Now)
{
break;
}
connectionTimeout = DateTime.Now.Add(Constants.ConnectionTimeout);
#endregion

var request = JsonConvert.DeserializeObject<QueryRequest>(value);

if (request != null)
Expand Down