Hi Ben,
I assume this challenge needs to be tackled in the R realm: If the Java client is used, no sleep is required at all.
Hope this helps, Christian
On Wed, Dec 8, 2021 at 12:53 PM Ben Engbers Ben.Engbers@be-logical.nl wrote:
Hi Christian,
All my previous packages for RBaseX were based on using a blocking socket. Every attempt to use a non-blocking socket failed because I couldn't authenticate. In R each read-operation on a blocking socket uses a timeout of at least 1 second. Consequence was that executing 53 tests on my pacakge took at least 116 seconds on my machine.
I finally managed to use a non-blocking socket. Execution of the same tests now take 3.8 seconds. It showed that the crucial needed step was to introduce a sleep/wait between sending the authentication nonce and checking the statusbyte:
code <- md5(paste(md5(code), nonce, sep = "")) %>% charToRaw() # send username + code auth <- c(charToRaw(username), as.raw(0x00), code, as.raw(0x00)) writeBin(auth, private$conn)
==> Sys.sleep(.1) Accepted <- readBin(conn, what = "raw", n = 1) ==0
My knowledge of working with sockets is limited so maybe you can answer my question. Does the need of using a sleep means I need to fix a bug in the R code or should I use a setting in BaseX that takes into account the required delay?
Ben Engbers