PageRenderTime 70ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/man/poll.socket.Rd

https://github.com/brotchie/rzmq
Unknown | 100 lines | 83 code | 17 blank | 0 comment | 0 complexity | 9dfb4201f16969a0b5724b5f855e4c14 MD5 | raw file
  1. \name{poll.socket}
  2. \alias{poll.socket}
  3. \title{Polls a list of sockets, waiting for the presence of a nonblocking read, write, or error event.}
  4. \description{The zmq_poll() function shall poll a list of a sockets for either read, write, or error conditions subject to a millisecond resolution timeout.}
  5. \usage{
  6. socket.poll(sockets, events, timeout=0L)
  7. }
  8. \arguments{
  9. \item{sockets}{a list of zmq socket objects.}
  10. \item{events}{a list of character vectors containing one or more events in \{read, write, error\}. The first element in the list corresponds to the first zmq socket, and so on...}
  11. \item{timeout}{the numbers of seconds to wait for events. Fractional seconds are supported. ZeroMQ guarantees at most millisecond resolution. A timeout of -1L blocks until an event occurs; a timeout of 0L is non-blocking.}
  12. }
  13. \value{A list of pairlists corresponding to the polled zmq sockets. Each list has one of more tags from \{read, write, error\} with logical values indicating the results of the poll operation.}
  14. \references{
  15. http://www.zeromq.org
  16. http://api.zeromq.org
  17. http://zguide.zeromq.org/page:all
  18. }
  19. \author{
  20. ZMQ was written by Martin Sustrik <sustrik@250bpm.com> and Martin Lucina <mato@kotelna.sk>.
  21. rzmq was written by Whit Armstrong.
  22. }
  23. \seealso{
  24. \code{\link{connect.socket},\link{bind.socket},\link{receive.socket},\link{send.socket},\link{poll.socket}}
  25. }
  26. \examples{\dontrun{
  27. library(rzmq)
  28. # Create a set of REP-REQ sockets that
  29. # have a Send, Receive, Send, Receive, ...
  30. # pattern.
  31. context = init.context()
  32. in.socket = init.socket(context,"ZMQ_REP")
  33. bind.socket(in.socket,"tcp://*:5557")
  34. out.socket = init.socket(context,"ZMQ_REQ")
  35. connect.socket(out.socket,"tcp://*:5557")
  36. # Poll the REP and REQ sockets for all events.
  37. events <- poll.socket(list(in.socket, out.socket),
  38. list(c("read", "write", "error"),
  39. c("read", "write", "error")),
  40. timeout=0L)
  41. # The REQ socket is writable without blocking.
  42. paste("Is upstream REP socket readable without blocking?", events[[1]]$read)
  43. paste("Is upstream REP socket writable without blocking?", events[[1]]$write)
  44. paste("Is downstream REQ socket readable without blocking?", events[[2]]$read)
  45. paste("Is downstream REQ socket writable without blocking?", events[[2]]$write)
  46. # Send a message to the REP socket from the REQ socket. The
  47. # REQ socket must respond before the REP socket can send
  48. # another message.
  49. send.socket(out.socket, "Hello World")
  50. events <- poll.socket(list(in.socket, out.socket),
  51. list(c("read", "write", "error"),
  52. c("read", "write", "error")),
  53. timeout=0L)
  54. # The incoming message is readable on the REP socket.
  55. paste("Is upstream REP socket readable without blocking?", events[[1]]$read)
  56. paste("Is upstream REP socket writable without blocking?", events[[1]]$write)
  57. paste("Is downstream REQ socket readable without blocking?", events[[2]]$read)
  58. paste("Is downstream REQ socket writable without blocking?", events[[2]]$write)
  59. receive.socket(in.socket)
  60. events <- poll.socket(list(in.socket, out.socket),
  61. list(c("read", "write", "error"),
  62. c("read", "write", "error")),
  63. timeout=0L)
  64. # The REQ socket is waiting for a response from the REP socket.
  65. paste("Is upstream REP socket readable without blocking?", events[[1]]$read)
  66. paste("Is upstream REP socket writable without blocking?", events[[1]]$write)
  67. paste("Is downstream REQ socket readable without blocking?", events[[2]]$read)
  68. paste("Is downstream REQ socket writable without blocking?", events[[2]]$write)
  69. send.socket(in.socket, "Greetings")
  70. events <- poll.socket(list(in.socket, out.socket),
  71. list(c("read", "write", "error"),
  72. c("read", "write", "error")),
  73. timeout=0L)
  74. # The REP response is waiting to be read on the REQ socket.
  75. paste("Is upstream REP socket readable without blocking?", events[[1]]$read)
  76. paste("Is upstream REP socket writable without blocking?", events[[1]]$write)
  77. paste("Is downstream REQ socket readable without blocking?", events[[2]]$read)
  78. paste("Is downstream REQ socket writable without blocking?", events[[2]]$write)
  79. # Complete the REP-REQ transaction cycle by reading
  80. # the REP response.
  81. receive.socket(out.socket)
  82. }}
  83. \keyword{utilities}