Skip to contents

Prevents further pipe connections from being established at a Socket. If a socket is locked, new pipe connections are closed before they can be added to the socket.

Usage

lock(socket, cv = NULL)

unlock(socket)

Arguments

socket

a Socket.

cv

(optional) a ‘conditionVariable’. If supplied, the socket is locked only whilst the condition variable is an odd value. This is designed to allow an initial connection, as well as subsequent re-connections after a connection has ended, if the conditon variable is also registered with pipe_notify for both add and remove pipe events.

Value

Invisibly, zero on success (will otherwise error).

Examples

s <- socket("bus", listen = "inproc://nanolock")
s1 <- socket("bus", dial = "inproc://nanolock")
lock(s)
s2 <- socket("bus", dial = "inproc://nanolock")

send(s, "test")
#> [1] 0
recv(s1)
#> [1] "test"
recv(s2)
#> 'errorValue' int 8 | Try again

unlock(s)
s3 <- socket("bus", dial = "inproc://nanolock")
send(s, "test")
#> [1] 0
recv(s1)
#> [1] "test"
recv(s3)
#> [1] "test"

close(s)
close(s1)
close(s2)
close(s3)