Skip to content

Commit

Permalink
update to libdill 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
paulofaria committed May 13, 2017
1 parent e3dd7f2 commit a497d55
Show file tree
Hide file tree
Showing 99 changed files with 15,454 additions and 1,554 deletions.
8 changes: 4 additions & 4 deletions .jazzy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ xcodebuild_arguments:
- Venice

custom_categories:
- name: Handles
children:
- Handle

- name: Coroutines
children:
- Coroutine
Expand All @@ -27,10 +31,6 @@ custom_categories:
- Deadline
- Int

- name: Handles
children:
- Handle

- name: Errors
children:
- VeniceError
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ What you end up with is a tree of coroutines rooted in the `main` function. This

![call-tree](http://libdill.org/index3.jpeg "Call Tree")

Venice implements structured concurrency by allowing you to cancel a running coroutine.
Venice implements structured concurrency by allowing you to close a running coroutine.

```swift
let coroutine = try Coroutine {
Expand All @@ -71,12 +71,12 @@ let coroutine = try Coroutine {
}

try Coroutine.wakeUp(1.second.fromNow())
try coroutine.cancel()
try coroutine.close()
```

When a coroutine is being canceled all blocking calls will start to throw `VeniceError.canceledCoroutine`. On one hand, this forces the function to finish quickly (there's not much you can do without blocking functions); on the other hand, it provides an opportunity for cleanup.
When a coroutine is being closed all blocking calls will start to throw `VeniceError.canceled`. On one hand, this forces the function to finish quickly (there's not much you can do without blocking functions); on the other hand, it provides an opportunity for cleanup.

In the example above, when `coroutine.cancel` is called the call to `Coroutine.wakeUp` inside the coroutine will throw `VeniceError.canceledCoroutine` and then the `defer` statement will run, thus releasing the memory allocated for `resource`.
In the example above, when `coroutine.close` is called the call to `Coroutine.wakeUp` inside the coroutine will throw `VeniceError.canceled` and then the `defer` statement will run, thus releasing the memory allocated for `resource`.

# Threads

Expand Down Expand Up @@ -109,5 +109,5 @@ This project is released under the MIT license. See [LICENSE](LICENSE) for detai
[codebeat-badge]: https://codebeat.co/badges/bd12fff5-d499-4636-83e6-d4edf89585c5
[codebeat-url]: https://codebeat.co/projects/github-com-zewo-venice

[docs-badge]: http://www.zewo.io/Venice/badge.svg
[docs-badge]: http://zewo.github.io/Venice/badge.svg
[docs-url]: http://www.zewo.io/Venice/
25 changes: 25 additions & 0 deletions Sources/CLibdill/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Full list of copyright holders:

Alex Cornejo <acornejo@gmail.com>
Bent Cardan <bent@nothingsatisfies.com>
Constantine Tarasenkov <constantine@protonmail.com>
Jim Jagielski <jimjag@gmail.com>
Jim Schimpf <jim.schimpf@gmail.com>
Luca Barbato <luca.barbato@gmail.com>
Martin Lucina <martin@lucina.net>
Martin Sustrik <sustrik@250bpm.com>*
Maximilian Pudelko <maximilian.pudelko@gmail.com>
Michael Gehring <mg@ebfe.org>
Nick Desaulniers <nick@mozilla.com>
Nir Soffer <nsoffer@redhat.com>
Paul Banks <banks@banksdesigns.co.uk>
Petr Skocik <pskocik@gmail.com>
Sergey Avseyev <sergey.avseyev@gmail.com>
Tai Chi Minh Ralph Eastwood <tcmreastwood@gmail.com>*
Yue Xu <red_angelx@qq.com>
Zach Banks <zbanks@mit.edu>

* Future patches by this author are submitted under the MIT/X11 license

Copyrights for DNS resolution library in dns subdirectory are owned by:
William Ahern <william@25thandClement.com>
19 changes: 19 additions & 0 deletions Sources/CLibdill/COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

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 the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

62 changes: 62 additions & 0 deletions Sources/CLibdill/bsock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright (c) 2017 Martin Sustrik
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 the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/

#include <errno.h>
#include <stddef.h>

#include "libdillimpl.h"
#include "utils.h"

dill_unique_id(bsock_type);

int bsend(int s, const void *buf, size_t len, int64_t deadline) {
struct bsock_vfs *b = hquery(s, bsock_type);
if(dill_slow(!b)) return -1;
struct iolist iol = {(void*)buf, len, NULL, 0};
return b->bsendl(b, &iol, &iol, deadline);
}

int brecv(int s, void *buf, size_t len, int64_t deadline) {
struct bsock_vfs *b = hquery(s, bsock_type);
if(dill_slow(!b)) return -1;
struct iolist iol = {buf, len, NULL, 0};
return b->brecvl(b, &iol, &iol, deadline);
}

int bsendl(int s, struct iolist *first, struct iolist *last, int64_t deadline) {
struct bsock_vfs *b = hquery(s, bsock_type);
if(dill_slow(!b)) return -1;
if(dill_slow(!first || !last || last->iol_next)) {
errno = EINVAL; return -1;}
return b->bsendl(b, first, last, deadline);
}

int brecvl(int s, struct iolist *first, struct iolist *last, int64_t deadline) {
struct bsock_vfs *b = hquery(s, bsock_type);
if(dill_slow(!b)) return -1;
if(dill_slow((first && !last) || (!first && last) || last->iol_next)) {
errno = EINVAL; return -1;}
return b->brecvl(b, first, last, deadline);
}

Loading

0 comments on commit a497d55

Please sign in to comment.