Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huumn/suv
async io (tcp sockets now) for Chez Scheme via libuv
https://github.com/huumn/suv
asyncio libuv scheme socket tcp
Last synced: 11 days ago
JSON representation
async io (tcp sockets now) for Chez Scheme via libuv
- Host: GitHub
- URL: https://github.com/huumn/suv
- Owner: huumn
- License: mit
- Created: 2020-04-03T14:44:29.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-22T02:23:34.000Z (over 4 years ago)
- Last Synced: 2024-10-06T06:43:08.289Z (3 months ago)
- Topics: asyncio, libuv, scheme, socket, tcp
- Language: C
- Homepage:
- Size: 29.3 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# suv
async io (tcp sockets now) for [Chez Scheme](https://scheme.com) via [libuv](https://github.com/libuv/libuv)## Heads up
The api is *guaranteed* to change## Getting Started
Install libuv then ...
```bash
git clone [email protected]:huumn/suv.git
cd suv
cc -o3 -fPIC -shared c/suv.c -luv -o libsuv.so
mkdir lib
ln -s `pwd` lib
scheme --libdirs .. --script examples/echo.sc
```## Examples
### Echo
```Scheme
(import (suv suv))(suv-listen "127.0.0.1"
8000
(lambda (client)
(suv-accept client)
(suv-read-start client
(lambda (req)
(suv-write client
req)))
(suv-write client
(format "Welcome to Echo server, ~a!\r\n"
(suv-getpeername client)))))(suv-run)
```### State via closure
```Scheme
(import (suv suv))(suv-listen "127.0.0.1"
8000
(lambda (client)
(suv-accept client)
(suv-read-start client
(let ([acc '()])
(lambda (req)
(set! acc (append acc (list req)))
(if (> (length acc) 1)
(begin
(suv-write client
(apply string-append
acc))
(set! acc '()))))))
(suv-write client
"Welcome, I echo after 2 requests!\r\n")))(suv-run)
```### Client
```Scheme
(import (suv suv))(suv-connect "127.0.0.1"
8000
(lambda (server)
(suv-read-start server
(lambda (req)
(display req)
(flush-output-port)))
(suv-write server
"Howdy, echo server!\r\n")))(suv-run)
```## Note
* Again, the API *will* change
* The library only supports operations on TCP sockets currently
* Performance is not really considered (and likely won't be for some time). That said, making it higher performing is straightfoward
- Use a mempool
- Don't copy memory on the request/response path (e.g. when calling in and out of Chez)
- Provide an async api for other blocking operations that might be performed