Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 104 additions & 9 deletions R/rzmq.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
## along with this program. If not, see <http:##www.gnu.org#licenses#>. ##
###########################################################################

zmq.version <- function() {
.Call("get_zmq_version", PACKAGE="rzmq")
}

zmq.errno <- function() {
.Call("get_zmq_errno", PACKAGE="rzmq")
}
Expand All @@ -27,10 +23,6 @@ zmq.strerror <- function() {
.Call("get_zmq_strerror", PACKAGE="rzmq")
}

init.context <- function() {
.Call("initContext", PACKAGE="rzmq")
}

init.socket <- function(context, socket.type) {
.Call("initSocket", context, socket.type, PACKAGE="rzmq")
}
Expand Down Expand Up @@ -105,7 +97,7 @@ receive.double <- function(socket) {
}

poll.socket <- function(sockets, events, timeout=0L) {
if (timeout != -1L) timeout <- as.integer(timeout * 1e3)
if (timeout != -1L) timeout <- as.integer(timeout * 1000000)
.Call("pollSocket", sockets, events, timeout)
}

Expand Down Expand Up @@ -200,3 +192,106 @@ set.send.timeout <- function(socket, option.value) {
get.send.timeout <- function(socket) {
.Call("get_sndtimeo", socket, PACKAGE="rzmq")
}

#################################################################################
# BDD functions
#################################################################################

zmq.version <- function( x = NULL ){

version__ <- invisible( .Call("get_zmq_version", PACKAGE="rzmq") )

if( is.null( x ) ){
return( version__ )
}else if( toupper( x ) == 'MAJOR' ){
return( as.integer( strsplit( split = '\\.', version__ )[[1]][1] ) )
}else if( toupper( x ) == 'MINOR' ){
return( as.integer( strsplit( split = '\\.', version__ )[[1]][2] ) )
}else if( toupper( x ) == 'PATCH' ){
return( as.integer( strsplit( split = '\\.', version__ )[[1]][3] ) )
}else{
stop( 'ERROR: x must be one of {NULL,"major","minor","patch"}.\n' )
}
}


init.context <- function( io_threads = 1 ){
io_threads <- as.integer( io_threads )
if( io_threads < 1 )
stop( 'ERROR: io_threads must be at least 1.\n' )
invisible( .Call( "initContext", io_threads, PACKAGE = "rzmq" ) )
}

close.socket <- function( socket ){
invisible( .Call( "closeSocket", socket, PACKAGE = "rzmq" ) )
}

get.keypair <- function(){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use get.keypair.\n' )
keypair <- invisible( .Call( "get_keypair", PACKAGE = "rzmq" ) )
names( keypair ) <- c( "public", "secret" )
return( keypair )
}

set.curve.server <- function( socket ){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use set.curve.server.\n' )
invisible( .Call( "set_curve_server", socket, PACKAGE = "rzmq" ) )
}

get.curve.server <- function( socket ){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use get.curve.server.\n' )
curve_server <- invisible( .Call( "get_curve_server", socket, PACKAGE = "rzmq" ) )
return( curve_server )
}


set.public.key <- function( socket, option.value ){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use set.public.key.\n' )
invisible( .Call( "set_key", socket, "PUBLIC", as.character( option.value ), PACKAGE = "rzmq" ) )
}

get.public.key <- function( socket ){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use get.public.key.\n' )
public_key <- invisible( .Call( "get_key", socket, "PUBLIC", PACKAGE = "rzmq" ) )
return( public_key )
}


set.secret.key <- function( socket, option.value ){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use set.secret.key.\n' )
invisible( .Call( "set_key", socket, "SECRET", as.character( option.value ), PACKAGE = "rzmq" ) )
}

get.secret.key <- function( socket ){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use get.secret.key.\n' )
secret_key <- invisible( .Call( "get_key", socket, "SECRET", PACKAGE = "rzmq" ) )
return( secret_key )
}


set.server.key <- function( socket, option.value ){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use set.server.key.\n' )
invisible( .Call( "set_key", socket, "SERVER", as.character( option.value ), PACKAGE = "rzmq" ) )
}

get.server.key <- function( socket ){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use get.server.key.\n' )
server_key <- invisible( .Call( "get_key", socket, "SERVER", PACKAGE = "rzmq" ) )
return( server_key )
}

get.io_threads <- function( context ){
if( zmq.version( 'major' ) < 4 )
stop( 'ERROR: ZeroMQ must be version 4 or newer to use get.io_threads.\n' )
io_threads <- invisible( .Call( "get_io_threads", context, PACKAGE = "rzmq" ) )
return( io_threads )
}
5 changes: 5 additions & 0 deletions inst/zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ namespace zmq
{
return ptr;
}

void* get_ptr(){
return ptr;
}

private:

void *ptr;
Expand Down
40 changes: 40 additions & 0 deletions man/close.socket.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
\name{close.socket}
\alias{close.socket}
\title{Close the connection to a socket.}
\description{Closes the connection to a socket.}
\usage{
close.socket(socket)
}
\arguments{
\item{socket}{a zmq socket object.}
}

\value{TRUE if operation succeeds or FALSE if the operation fails}

\references{
http://www.zeromq.org
http://api.zeromq.org
http://zguide.zeromq.org/page:all
}

\author{
ZMQ was written by Martin Sustrik <[email protected]> and Martin Lucina <[email protected]>.
rzmq was written by Whit Armstrong.
}


\seealso{
\code{\link{connect.socket},\link{bind.socket},\link{receive.socket},\link{send.socket},\link{poll.socket}}
}
\examples{\dontrun{

library(rzmq)
context = init.context()
in.socket = init.socket(context,"ZMQ_PULL")
bind.socket(in.socket,"tcp://*:5557")

out.socket = init.socket(context,"ZMQ_PUSH")
bind.socket(out.socket,"tcp://*:5558")
}}

\keyword{utilities}
40 changes: 40 additions & 0 deletions man/get.curve.server.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
\name{get.curve.server}
\alias{get.curve.server}
\title{Test whether a socket is a Curve server.}
\description{Test whether a socket is a Curve server.}
\usage{
get.curve.server(socket)
}
\arguments{
\item{socket}{a zmq socket object.}
}

\value{1 if the socket is a Curve server; 0 otherwise.}

\references{
http://www.zeromq.org
http://api.zeromq.org
http://zguide.zeromq.org/page:all
}

\author{
ZMQ was written by Martin Sustrik <[email protected]> and Martin Lucina <[email protected]>.
rzmq was written by Whit Armstrong.
}


\seealso{
\code{\link{connect.socket},\link{bind.socket},\link{receive.socket},\link{send.socket},\link{poll.socket}}
}
\examples{\dontrun{

library(rzmq)
context = init.context()
in.socket = init.socket(context,"ZMQ_PULL")
bind.socket(in.socket,"tcp://*:5557")

out.socket = init.socket(context,"ZMQ_PUSH")
bind.socket(out.socket,"tcp://*:5558")
}}

\keyword{utilities}
40 changes: 40 additions & 0 deletions man/get.io_threads.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
\name{get.io_threads}
\alias{get.io_threads}
\title{Get the number of io_threads used by a socket.}
\description{Get the number of io_threads used by a socket.}
\usage{
get.io_threads(context)
}
\arguments{
\item{context}{a zmq context object.}
}

\value{An integer value representing the number of io_threads used by a socket.}

\references{
http://www.zeromq.org
http://api.zeromq.org
http://zguide.zeromq.org/page:all
}

\author{
ZMQ was written by Martin Sustrik <[email protected]> and Martin Lucina <[email protected]>.
rzmq was written by Whit Armstrong.
}


\seealso{
\code{\link{connect.socket},\link{bind.socket},\link{receive.socket},\link{send.socket},\link{poll.socket}}
}
\examples{\dontrun{

library(rzmq)
context = init.context()
in.socket = init.socket(context,"ZMQ_PULL")
bind.socket(in.socket,"tcp://*:5557")

out.socket = init.socket(context,"ZMQ_PUSH")
bind.socket(out.socket,"tcp://*:5558")
}}

\keyword{utilities}
38 changes: 38 additions & 0 deletions man/get.keypair.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
\name{get.keypair}
\alias{get.keypair}
\title{Get a public and secret keypair for Curve authentication.}
\description{Get a public and secret keypair for Curve authentication.}
\usage{
get.keypair()
}

\value{A list of two strings, one representing the public key and one
representing the secret key.}

\references{
http://www.zeromq.org
http://api.zeromq.org
http://zguide.zeromq.org/page:all
}

\author{
ZMQ was written by Martin Sustrik <[email protected]> and Martin Lucina <[email protected]>.
rzmq was written by Whit Armstrong.
}


\seealso{
\code{\link{connect.socket},\link{bind.socket},\link{receive.socket},\link{send.socket},\link{poll.socket}}
}
\examples{\dontrun{

library(rzmq)
context = init.context()
in.socket = init.socket(context,"ZMQ_PULL")
bind.socket(in.socket,"tcp://*:5557")

out.socket = init.socket(context,"ZMQ_PUSH")
bind.socket(out.socket,"tcp://*:5558")
}}

\keyword{utilities}
40 changes: 40 additions & 0 deletions man/get.public.key.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
\name{get.public.key}
\alias{get.public.key}
\title{Get the public key associated with a socket.}
\description{Get the public key associated with a socket.}
\usage{
get.public.key(socket)
}
\arguments{
\item{socket}{a zmq socket object.}
}

\value{A string representing the public key of the socket.}

\references{
http://www.zeromq.org
http://api.zeromq.org
http://zguide.zeromq.org/page:all
}

\author{
ZMQ was written by Martin Sustrik <[email protected]> and Martin Lucina <[email protected]>.
rzmq was written by Whit Armstrong.
}


\seealso{
\code{\link{connect.socket},\link{bind.socket},\link{receive.socket},\link{send.socket},\link{poll.socket}}
}
\examples{\dontrun{

library(rzmq)
context = init.context()
in.socket = init.socket(context,"ZMQ_PULL")
bind.socket(in.socket,"tcp://*:5557")

out.socket = init.socket(context,"ZMQ_PUSH")
bind.socket(out.socket,"tcp://*:5558")
}}

\keyword{utilities}
40 changes: 40 additions & 0 deletions man/get.secret.key.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
\name{get.secret.key}
\alias{get.secret.key}
\title{Get the secret key associated with a socket.}
\description{Get the secret key associated with a socket.}
\usage{
get.secret.key(socket)
}
\arguments{
\item{socket}{a zmq socket object.}
}

\value{A string representing the secret key of the socket.}

\references{
http://www.zeromq.org
http://api.zeromq.org
http://zguide.zeromq.org/page:all
}

\author{
ZMQ was written by Martin Sustrik <[email protected]> and Martin Lucina <[email protected]>.
rzmq was written by Whit Armstrong.
}


\seealso{
\code{\link{connect.socket},\link{bind.socket},\link{receive.socket},\link{send.socket},\link{poll.socket}}
}
\examples{\dontrun{

library(rzmq)
context = init.context()
in.socket = init.socket(context,"ZMQ_PULL")
bind.socket(in.socket,"tcp://*:5557")

out.socket = init.socket(context,"ZMQ_PUSH")
bind.socket(out.socket,"tcp://*:5558")
}}

\keyword{utilities}
Loading