Increase chunk size to send fewer messages.

Fixed logging lock (causes color issues in parallel env)
This commit is contained in:
Michael Chen 2022-01-18 10:43:15 +01:00
parent f912b9db8f
commit a55af9f667
No known key found for this signature in database
GPG Key ID: 1CBC7AA5671437BB
2 changed files with 19 additions and 15 deletions

View File

@ -1,9 +1,12 @@
local secretToken = "$TOKEN"
local connectionUri = "$HOST"
local waitSeconds = 5
-- https://github.com/cc-tweaked/CC-Tweaked/blob/9cf70b10effeeed23e0e9c537bbbe0b2ff0d1a0f/src/main/java/dan200/computercraft/core/apis/http/options/AddressRule.java#L29
-- Chunk size must be less than packet size (type reply, success, chunkids, content: chunk) 16 kb for buffer
local maxMessageSize = (128 - 16) * 1024
local function chunkString(value, chunkSize)
if not chunkSize then chunkSize = 10000 end
if not chunkSize then chunkSize = maxMessageSize end
local length = value:len()
local total = math.ceil(length / chunkSize)
local chunks = {}

View File

@ -274,6 +274,7 @@ public class Program : IDisposable, ICommandHandler<ResponseType>, IUserRoleMana
}
public static void Log(LogMessage msg) {
lock (LogLock) {
var oldColor = Console.ForegroundColor;
try {
Console.ForegroundColor = msg.Severity switch {
@ -285,12 +286,12 @@ public class Program : IDisposable, ICommandHandler<ResponseType>, IUserRoleMana
LogSeverity.Debug => ConsoleColor.DarkBlue,
_ => ConsoleColor.Cyan,
};
lock (LogLock)
Console.WriteLine(msg.ToString());
} finally {
Console.ForegroundColor = oldColor;
}
}
}
protected virtual void Dispose(bool disposing) {
if (!disposedValue) {