Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Bump nanomsg dep to 0.8-beta and add new functions for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Jan 6, 2016
1 parent f3e96f3 commit f58f485
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.8.0 (2016-01-06)

* Bump nanomsg to 0.8-beta
* Add new public (protocol-bind) and (protocol-connect) functions
* Simplify documentation and update license for 2016

## 0.7.0 (2015-11-01)

* Bump lib version
Expand Down
2 changes: 1 addition & 1 deletion EXPLAIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,4 @@ That's pretty much all I have to explain about the Nanomsg FFI binding. I'm very

This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/).

Copyright (c) 2015 Alexander Williams, Unscramble <license@unscramble.jp>
Copyright (c) 2015-2016 Alexander Williams, Unscramble <license@unscramble.jp>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Alexander Williams, Unscramble <license@unscramble.jp>
Copyright (c) 2015-2016 Alexander Williams, Unscramble <license@unscramble.jp>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PIL_SYMLINK_DIR ?= .lib
## Edit below
BUILD_REPO = https://github.com/nanomsg/nanomsg.git
BUILD_DIR = $(PIL_MODULE_DIR)/nanomsg/HEAD
BUILD_REF = 0.7-beta
BUILD_REF = 0.8-beta
LIB_DIR = .libs
TARGET = libnanomsg.so
BFLAGS = --enable-shared
Expand Down
50 changes: 20 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nanomsg FFI bindings for PicoLisp

[![GitHub release](https://img.shields.io/github/release/aw/picolisp-nanomsg.svg)](https://github.com/aw/picolisp-nanomsg) [![Build Status](https://travis-ci.org/aw/picolisp-nanomsg.svg?branch=master)](https://travis-ci.org/aw/picolisp-nanomsg) [![Dependency](https://img.shields.io/badge/%5Bdeps%5D%20Nanomsg-0.7--beta-ff69b4.svg)](https://github.com/nanomsg/nanomsg) [![Dependency](https://img.shields.io/badge/[deps] picolisp--unit-v1.0.0-ff69b4.svg)](https://github.com/aw/picolisp-unit.git)
[![GitHub release](https://img.shields.io/github/release/aw/picolisp-nanomsg.svg)](https://github.com/aw/picolisp-nanomsg) [![Build Status](https://travis-ci.org/aw/picolisp-nanomsg.svg?branch=master)](https://travis-ci.org/aw/picolisp-nanomsg) [![Dependency](https://img.shields.io/badge/%5Bdeps%5D%20Nanomsg-0.8--beta-ff69b4.svg)](https://github.com/nanomsg/nanomsg) [![Dependency](https://img.shields.io/badge/[deps] picolisp--unit-v1.0.0-ff69b4.svg)](https://github.com/aw/picolisp-unit.git)

[Nanomsg](http://nanomsg.org/index.html) FFI bindings for [PicoLisp](http://picolisp.com/).

Expand All @@ -11,7 +11,7 @@ The following protocols are supported:
3. [BUS](#example-bus)
4. [PAIR](#example-pair)
5. [PUSH/PULL (PIPELINE)](#example-pushpull---pipeline)
6. [SURVEY](#example-survey)
6. [SURVEYOR/RESPONDENT](#example-survey)

# Requirements

Expand Down Expand Up @@ -49,23 +49,13 @@ To keep everything updated, type:

Only the following functions are exported publicly, and namespaced with `(symbols 'nanomsg)` (or the prefix: `nanomsg~`):

* `rep-bind`: bind a `REP` socket (inproc, ipc, tcp)
* `req-connect`: connect to a `REQ` socket (inproc, ipc, tcp)
* `pub-bind`: bind to a `PUB` socket (inproc, ipc, tcp)
* `sub-connect`: connect to a `SUB` socket (inproc, ipc, tcp)
* `protocol-bind`: bind a `REP, PUB, BUS, PAIR, PULL, or SURVEYOR` socket (inproc, ipc, tcp)
* `protocol-connect`: connect to a `REQ, SUB, BUS, PAIR, PUSH, RESPONDENT` socket (inproc, ipc, tcp)
* `end-sock`: shutdown and close a socket
* `msg-recv`: receive a message (blocking/non-blocking)
* `msg-send`: send a message (blocking/non-blocking)
* `subscribe`: subscribe to a `PUB/SUB` topic
* `unsubscribe`: unsubscribe from a `PUB/SUB` topic
* `bus-bind`: bind to a `BUS` socket (inproc, ipc, tcp)
* `bus-connect`: connect to a `BUS` socket (inproc, ipc, tcp)
* `pair-bind`: bind to a `PAIR` socket (inproc, ipc, tcp)
* `pair-connect`: connect to a `PAIR` socket (inproc, ipc, tcp)
* `pull-bind`: bind to a `PULL` socket (inproc, ipc, tcp)
* `push-connect`: connect to a `PUSH` socket (inproc, ipc, tcp)
* `survey-bind`: bind to a `SURVEY` socket (inproc, ipc, tcp)
* `respond-connect`: connect to a `SURVEY` socket (inproc, ipc, tcp)

> **Note:** These functions are not namespace [local symbols](http://software-lab.de/doc/refL.html#local), which means they would redefine symbols with the same name in the `'pico` namespace.
Expand All @@ -80,7 +70,7 @@ pil +
(symbols 'nanomsg)
(let Error
(catch 'InternalError
(rep-bind "tcpz://127.0.0.1:5560")
(protocol-bind "REP" "tcpz://127.0.0.1:5560" "AF_SP_RAW")
(prinl "you shouldn't see this") NIL)
(when Error (println @)) )
Expand All @@ -98,7 +88,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(rep-bind "tcp://127.0.0.1:5560")
(protocol-bind "REP" "tcp://127.0.0.1:5560")
(prinl (msg-recv (car Sockpair)))
(msg-send (car Sockpair) "Yep I can see it!" T) # non-blocking
Expand All @@ -119,7 +109,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(req-connect "tcp://127.0.0.1:5560")
(protocol-connect "REQ" "tcp://127.0.0.1:5560")
(msg-send (car Sockpair) "Can you see this?")
(prinl (msg-recv (car Sockpair)))
(end-sock Sockpair) )
Expand All @@ -139,7 +129,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(sub-connect "tcp://127.0.0.1:5560")
(protocol-connect "SUB" "tcp://127.0.0.1:5560")
(subscribe (car Sockpair) "test")
(while T (prinl "RECEIVED: " (msg-recv (car Sockpair))) (wait 1000 (unsubscribe 0 "test")))
(end-sock Sockpair) )
Expand All @@ -156,7 +146,7 @@ pil +
(symbols 'nanomsg)
(let Sockpair
(pub-bind "tcp://127.0.0.1:5560")
(protocol-bind "PUB" "tcp://127.0.0.1:5560")
(while T (msg-send (car Sockpair) "test Hello World!"))
(end-sock Sockpair) )
```
Expand All @@ -172,7 +162,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(bus-connect "tcp://127.0.0.1:5560")
(protocol-connect "BUS" "tcp://127.0.0.1:5560")
(prinl (msg-recv (car Sockpair)))
(end-sock Sockpair) )
(bye) )
Expand All @@ -189,7 +179,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(bus-bind "tcp://127.0.0.1:5560")
(protocol-bind "BUS" "tcp://127.0.0.1:5560")
(msg-send (car Sockpair) "Hello World!")
(end-sock Sockpair) )
(bye) )
Expand All @@ -206,7 +196,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(pair-connect "tcp://127.0.0.1:5560")
(protocol-connect "PAIR" "tcp://127.0.0.1:5560")
(prinl (msg-recv (car Sockpair)))
(end-sock Sockpair) )
(bye) )
Expand All @@ -223,7 +213,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(pair-bind "tcp://127.0.0.1:5560")
(protocol-bind "PAIR" "tcp://127.0.0.1:5560")
(prinl (msg-send (car Sockpair) "Hello World!"))
(end-sock Sockpair) )
(bye) )
Expand All @@ -240,7 +230,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(pull-bind "tcp://127.0.0.1:5560")
(protocol-bind "PULL" "tcp://127.0.0.1:5560")
(prinl (msg-recv (car Sockpair)))
(end-sock Sockpair) )
(bye) )
Expand All @@ -257,15 +247,15 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(push-connect "tcp://127.0.0.1:5560")
(protocol-connect "PUSH" "tcp://127.0.0.1:5560")
(prinl (msg-send (car Sockpair) "Hello Pipeline"))
(end-sock Sockpair) )
(bye) )
```

# Example (SURVEY)
# Example (SURVEYOR/RESPONDENT)

> **Note:** The _Survey_ protocol in Nanomsg is buggy, it's possible for this not to
> **Note:** The _Surveyor_ protocol in Nanomsg is buggy, it's possible for this not to
work as expected.

## Server
Expand All @@ -276,7 +266,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair (survey-bind "tcp://127.0.0.1:5560")
(let Sockpair (protocol-bind "SURVEYOR" "tcp://127.0.0.1:5560")
(msg-send (car Sockpair) "Knock knock.")
(prinl (msg-recv (car Sockpair)))
(end-sock Sockpair) )
Expand All @@ -294,7 +284,7 @@ pil +
(symbols 'nanomsg)
(unless (fork)
(let Sockpair
(respond-connect "tcp://127.0.0.1:5560")
(protocol-connect "RESPONDENT" "tcp://127.0.0.1:5560")
(prinl (msg-recv (car Sockpair)))
(msg-send (car Sockpair) "Who's there?")
(end-sock Sockpair) )
Expand Down Expand Up @@ -337,4 +327,4 @@ If you want to improve this library, please make a pull-request.
# License

[MIT License](LICENSE)
Copyright (c) 2015 Alexander Williams, Unscramble <license@unscramble.jp>
Copyright (c) 2015-2016 Alexander Williams, Unscramble <license@unscramble.jp>
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2015 Alexander Williams, Unscramble <license@unscramble.jp>
# Copyright (c) 2015-2016 Alexander Williams, Unscramble <license@unscramble.jp>
# MIT License
#
# For backwards compatibility
Expand Down
6 changes: 3 additions & 3 deletions module.l
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[de MODULE_INFO
("name" "nanomsg")
("version" "0.7.0")
("version" "0.8.0")
("summary" "Nanomsg ffi-binding for PicoLisp")
("source" "https://github.com/aw/picolisp-nanomsg.git")
("author" "Alexander Williams")
("license" "MIT")
("copyright" "(c) 2015 Alexander Williams, Unscramble <license@unscramble.jp>")
("copyright" "(c) 2015-2016 Alexander Williams, Unscramble <license@unscramble.jp>")
("install" "make")
("requires"
("picolisp-unit" "v1.0.0" "https://github.com/aw/picolisp-unit.git")
("nanomsg" "0.7-beta" "https://github.com/nanomsg/nanomsg.git") ]
("nanomsg" "0.8-beta" "https://github.com/nanomsg/nanomsg.git") ]
8 changes: 7 additions & 1 deletion nanomsg.l
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# The MIT License (MIT)
#
# Copyright (c) 2015 Alexander Williams, Unscramble <license@unscramble.jp>
# Copyright (c) 2015-2016 Alexander Williams, Unscramble <license@unscramble.jp>

(symbols 'nanomsg 'pico)

Expand Down Expand Up @@ -241,3 +241,9 @@
(let Result (nn-send Sock Msg (size Msg) (non-blocking-io Dontwait) )
(unless (exit-with-error-maybe Dontwait Result Sock)
Result ]

(de protocol-bind (Protocol Addr Domain)
(make-socket Addr (pack "NN_" Protocol) "BIND" Domain) )

(de protocol-connect (Protocol Addr Domain)
(make-socket Addr (pack "NN_" Protocol) NIL Domain) )
20 changes: 19 additions & 1 deletion test/test_nanomsg.l
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@
Result
"Successfully send/receive a message using PAIR protocol" ]

[de test-protocol-bind ()
(let (Sockpair (protocol-bind "REP" "tcp://127.0.0.1:5560")
Result (unit~assert-equal '(0 . 1)
Sockpair
"Protocol REP-BIND socket is created") )
(end-sock Sockpair)
Result ]

[de test-protocol-connect ()
(let (Sockpair (protocol-connect "REQ" "tcp://127.0.0.1:5560")
Result (unit~assert-equal '(0 . 1)
Sockpair
"Protocol REQ-CONNECT socket is created") )
(end-sock Sockpair)
Result ]

[unit~execute
'(unit~assert-throws 'InternalError
'(NanomsgError . "Protocol not supported")
Expand All @@ -138,4 +154,6 @@
'(test-push-connect)
'(test-survey-bind)
'(test-respond-connect)
'(test-send-recv) ]
'(test-send-recv)
'(test-protocol-bind)
'(test-protocol-connect) ]

0 comments on commit f58f485

Please sign in to comment.