r - R socketConnection - 读取和超时
问题描述
我(仍在)为 Basex 开发 R 客户端,这是一个强大的 XML 数据库。客户端使用 socketConnection: conn <- private$conn <- socketConnection(host = "localhost", port, open = "w+b", server = FALSE, blocking = TRUE, encoding = "UTF-8", timeout = 1)
。应用程序使用此函数从连接中读取:
readBin_ <- function(conn, n) {
chars_read <- raw(0)
rd <- readBin(conn, what = "raw", BUF_SIZE)
while(length(rd) == BUF_SIZE) {
chars_read <- c(chars_read, rd)
rd <- readBin(conn, "raw", BUF_SIZE)
}
if (length(rd) > 0) chars_read <- c(chars_read, rd)
return(chars_read)
}
这是包测试的输出:
==> devtools::test(
ℹ Loading RBaseX
ℹ Testing RBaseX
✓ | OK F W S | Context
✓ | 3 | 01_first [13.5 s]
✓ | 4 | 02_RbaseX [4.1 s]
✓ | 8 | 03_QueryClass [7.1 s]
✓ | 10 | 04_Utility [18.3 s]
✓ | 25 | 05_Wrappers [63.6 s]
══ Results ═══════════════════════════════════════════
Duration: 106.7 s
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 50 ]
从这个输出中,我可以看出 01_first 包含 13 个测试。从数据库读取需要 13 秒,处理需要 0.5 秒。
问题1:
有没有办法从套接字读取并忽略超时?
问题 2:
R 套接字连接是否有任何 C++ 替代方案(以及如何使用它们的示例,我使用 C++ 的经验很少)
本
解决方案
推荐阅读
- php - 后备资源无法正常工作
- docker - 如何将配置文件传递给 docker 容器?
- python - 从列表中查找最大值并将其分配给饼图 MatPlotLib Python 中的爆炸值
- javascript - 我将如何使用 js 将十进制数转换为十六进制字符串?
- php - 如何获得用户拥有的徽章?
- nuxt.js - 登录后无法立即获取用户,但刷新工作@nuxt-auth
- node.js - API 请求返回状态码 404 未找到
- python - 一行子图的共享颜色条
- google-apps-script - Google Apps Script public doPost 访问错误
- javascript - 每当 DOM 更新时,在 Safari OSX 和 iOS 中与指针事件属性一起使用时,CSS 颜色属性不起作用