No matching definitions.

nng/socket

src/nng/socket.tur

socket lifecycle for nng (nanomsg-next-generation).

Since: Phase NG1

defopaque

Socket

(Socket)

a linear handle to an open nng socket.

Since: Phase NG1

defn

req-open

(req-open :)

open a REQ (request) socket.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (req-open))]
    (dial s "inproc://demo")
    (close s))

Since: Phase NG1

defn

rep-open

(rep-open :)

open a REP (reply) socket.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (rep-open))]
    (listen s "inproc://demo")
    (close s))

Since: Phase NG1

defn

pub-open

(pub-open :)

open a PUB (publish) socket.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (pub-open))]
    (listen s "inproc://feed")
    (close s))

Since: Phase NG1

defn

sub-open

(sub-open :)

open a SUB (subscribe) socket.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (sub-open))]
    (dial s "inproc://feed")
    (sub-subscribe s "")
    (close s))

Since: Phase NG1

defn

push-open

(push-open :)

open a PUSH (pipeline producer) socket.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (push-open))]
    (listen s "inproc://jobs")
    (close s))

Since: Phase NG1

defn

pull-open

(pull-open :)

open a PULL (pipeline consumer) socket.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (pull-open))]
    (dial s "inproc://jobs")
    (close s))

Since: Phase NG1

defn

pair-open

(pair-open :)

open a PAIR (one-to-one) socket, protocol version 1.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (pair-open))]
    (listen s "inproc://link")
    (close s))

Since: Phase NG1

defn

bus-open

(bus-open :)

open a BUS (many-to-many broadcast) socket.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (bus-open))]
    (listen s "inproc://bus")
    (close s))

Since: Phase NG1

defn

surveyor-open

(surveyor-open :)

open a SURVEYOR socket.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (surveyor-open))]
    (listen s "inproc://survey")
    (close s))

Since: Phase NG1

defn

respondent-open

(respondent-open :)

open a RESPONDENT socket.

(Result Socket int) -- err carries the nng error code.

(let [s (ok-val (respondent-open))]
    (dial s "inproc://survey")
    (close s))

Since: Phase NG1

defn

dial

(dial [^borrow s : Socket url : cstr])

connect the socket to a remote address.

sthe socket (borrowed)
urle.g. "inproc://jobs", "ipc:///tmp/x.sock", "tcp://host:5555",
"ws://host:8080/jobs"

(Result nil int) -- err carries the nng error code.

(dial s "inproc://jobs")

Since: Phase NG1

defn

listen

(listen [^borrow s : Socket url : cstr])

bind the socket to a local address.

sthe socket (borrowed)
urle.g. "inproc://jobs", "ipc:///tmp/x.sock", "tcp://0.0.0.0:5555",
"ws://0.0.0.0:8080/jobs"

(Result nil int) -- err carries the nng error code.

(listen s "inproc://jobs")

Since: Phase NG1

defn

listen-bound-port

(listen-bound-port [^borrow s : Socket url : cstr])

bind the socket and report the TCP port it got.

sthe socket (borrowed)
urla tcp:// or ws:// address; port 0 asks the OS for a free one

(Result int int) -- ok carries the bound port; err carries the nng error code.

(let [port (ok-val (listen-bound-port s "ws://127.0.0.1:0/jobs"))]
    (println port))   ; => e.g. 41733

Since: Phase NG-WS

defn

close

(close [s : Socket] :)

close the socket. The single linear consumer.

sthe socket, consumed. This is its one legal consumption, so any
later use of the handle is rejected under -Xsubstructural.
(close s)

Since: Phase NG1

defn

set-recv-timeout-ms

(set-recv-timeout-ms [^borrow s : Socket ms : int] :)

bound how long a receive may block.

sthe socket (borrowed)
msmilliseconds, or a negative value for "wait forever"

(Result nil int) -- err carries the nng error code.

(set-recv-timeout-ms s 100)

Since: Phase NG1

defn

set-send-timeout-ms

(set-send-timeout-ms [^borrow s : Socket ms : int] :)

bound how long a send may block.

sthe socket (borrowed)
msmilliseconds, or a negative value for "wait forever"

(Result nil int) -- err carries the nng error code.

(set-send-timeout-ms s 100)

Since: Phase NG1

defn

err-str

(err-str [code : int] :)

human-readable message for an nng error code.

codethe int an err result carries

cstr -- e.g. "Timed out", "Connection refused".

(println (err-str (err-val r)))

Since: Phase NG1

defn

timed-out?

(timed-out? [code : int] :)

does this error code mean the deadline expired?

codethe int an err result carries

bool -- true for NNG_ETIMEDOUT.

(if (timed-out? (err-val r)) (retry) (report r))

Since: Phase NG1

defopaque

PollFd

(PollFd)

a file descriptor that may only be polled.

Since: Phase NG-A

defn

poll-fd->int

(poll-fd->int [fd : PollFd] :)

the raw descriptor, for reactor-add-fd / local-park-fd.

fdthe poll fd

int -- the descriptor number. Poll it; never read, write or close it.

(reactor-add-fd r (poll-fd->int (ok-val (recv-poll-fd s))) READ cb ud)

Since: Phase NG-A

defn

recv-poll-fd

(recv-poll-fd [^borrow s : Socket] :)

an fd that is readable while a message is waiting.

sthe socket (borrowed)

(Result PollFd int) -- err carries NNG_ENOTSUP on a protocol that cannot receive (PUB, PUSH), or another nng error code.

(let [fd (ok-val (recv-poll-fd sub))]
    (reactor-add-fd r (poll-fd->int fd) READ drain-cb ud))

Since: Phase NG-A

defn

send-poll-fd

(send-poll-fd [^borrow s : Socket] :)

an fd that is READABLE while a send would not block.

sthe socket (borrowed)

(Result PollFd int) -- err carries NNG_ENOTSUP on a protocol that cannot send (SUB, PULL), or another nng error code.

(let [fd (ok-val (send-poll-fd push))]
    (reactor-add-fd r (poll-fd->int fd) READ flush-cb ud))

Since: Phase NG-A