1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Stopped long queries, Read is_open() through TLS, Simplified answers and paging

- [server] query_time_limit (20 s by default) stops a client's query
  through SQLite's progress handler: refused with QueryTimedOut (11). A
  client closing while its query runs stops it too.
- The answer timeout in the DLL (BakaShrot_SetAnswerTimeout /
  GetAnswerTimeout, kept across connections), Python (answer_timeout)
  and C# (AnswerTimeoutMs); QueryTimedOut in every binding.
- is_open() reads what's waiting through TLS: a close_notify says
  closed, TLS's own records keep it open, unasked data or a broken
  stream close it.
- The Rust client checks an answer's type in one place (TryFrom per
  packet); Client::wait() pings while waiting (the tool's --follow).
- Pair::from(&Head), heads_after taking a Pair; simpler SyncState
  paging on both ends; the writer's redundant rollback check dropped.
- codes.rs: the bindings' error codes and copied values match Rust's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 12:17:28 +01:00
parent a6ade535d0
commit 1bae8ee182
37 changed files with 1064 additions and 264 deletions
+41
View File
@@ -434,6 +434,45 @@ fn exports() {
assert_eq!(BakaShrot_FreeClient(client), 1);
}
/// The answer timeout: set before connecting or while connected, kept
/// across connections; past it, `ConnectionLost` and the connection closed.
#[test]
fn answer_timeouts() {
let running = common::Running::start("answer-timeouts");
running.issue("kitchen", &["home"]);
let client = BakaShrot_CreateClient();
assert_eq!(BakaShrot_GetAnswerTimeout(client), 30_000);
for refused in [0, -1, i64::MIN] {
assert_eq!(BakaShrot_SetAnswerTimeout(client, refused), 0);
assert_eq!(error(client).0, code(ErrorCode::InvalidArgument));
}
assert_eq!(BakaShrot_SetAnswerTimeout(client, 60_000), 1);
assert_eq!(BakaShrot_FreeClient(client), 1);
let client = connected(&running, "kitchen");
assert_eq!(BakaShrot_SetAnswerTimeout(client, 300), 1);
assert_eq!(BakaShrot_GetAnswerTimeout(client), 300);
let forever =
a("WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n) SELECT count(*) FROM n");
let started = std::time::Instant::now();
unsafe {
assert_eq!(BakaShrot_QueryA(client, forever.as_ptr()), 0);
assert_eq!(error(client).0, code(ErrorCode::ConnectionLost));
assert!(started.elapsed() < std::time::Duration::from_secs(5));
assert_eq!(BakaShrot_IsConnected(client), 0);
// Connected again: the timeout kept.
let host = a("127.0.0.1");
assert_eq!(
BakaShrot_ConnectA(client, host.as_ptr(), i32::from(running.port)),
1
);
assert_eq!(BakaShrot_GetAnswerTimeout(client), 300);
assert_eq!(BakaShrot_QueryA(client, forever.as_ptr()), 0);
assert_eq!(error(client).0, code(ErrorCode::ConnectionLost));
}
assert_eq!(BakaShrot_FreeClient(client), 1);
}
/// A new client, connected as `name` (its certificate and key in files).
fn connected(running: &common::Running, name: &str) -> i64 {
let client = BakaShrot_CreateClient();
@@ -476,6 +515,8 @@ fn clients() {
assert!(why.contains("no client 99"), "{why}");
assert_eq!(BakaShrot_IsConnected(99), 0);
assert_eq!(BakaShrot_Ping(99), 0);
assert_eq!(BakaShrot_SetAnswerTimeout(99, 1000), 0);
assert_eq!(BakaShrot_GetAnswerTimeout(99), -1);
assert_eq!(BakaShrot_GetMessageId(-5), 0);
assert_eq!(get_w(99, BakaShrot_GetMessageDataW), "");
assert_eq!(BakaShrot_FreeClient(99), 0);