Skip to content

Commit

Permalink
update regex to handle sub-millisecond response times
Browse files Browse the repository at this point in the history
the regular expression used to search through ping output for response times only
matches on an equals sign

this change  modifies:
- the regular expression in ping_os() so that less than or equals will both produce matches
- the capture group in ping() is modified accordingly

response time will be reported as 1ms.

closes #24
  • Loading branch information
edavidaja committed Aug 21, 2024
1 parent 78903e3 commit 09d50c0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pingr (development version)

* `ping()` now handles sub-millisecond response times (#24).

# pingr 2.0.3

* `ping_port()` now correctly prints the port if `version = TRUE`.
Expand Down
4 changes: 2 additions & 2 deletions R/ping-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ping <- function(destination, continuous = FALSE, verbose = continuous,

if (!continuous) {
timings <- grep(os$regex, output, value = TRUE, perl = TRUE)
times <- sub(os$regex, "\\1", timings, perl = TRUE)
times <- sub(os$regex, "\\2", timings, perl = TRUE)
res <- as.numeric(times)
length(res) <- count
res
Expand Down Expand Up @@ -132,7 +132,7 @@ ping_os <- function(destination, continuous, count, timeout) {
)
}

list(cmd = cmd, env = env, regex = "^.*time=(.+)[ ]?ms.*$")
list(cmd = cmd, env = env, regex = "^.*time(=|<)(.+)[ ]?ms.*$")
}

#' Is the computer online?
Expand Down

0 comments on commit 09d50c0

Please sign in to comment.