Skip to content

Commit ceb940d

Browse files
authored
Merge pull request #7 from savi-lang/update/latest-savi
Update for breaking `AsioEvent` changes in latest Savi version.
2 parents 5a9a3a6 + b25b195 commit ceb940d

File tree

7 files changed

+42
-42
lines changed

7 files changed

+42
-42
lines changed

spec/TCP.Spec.savi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
:be dispose: @io.close
1212

13-
:fun ref _io_react(action IO.Action)
13+
:fun ref io_react(action IO.Action)
1414
case action == (
1515
| IO.Action.Opened |
1616
TCP.Spec.EchoClient.new(@env, Inspect[@io.listen_port_number])
@@ -36,7 +36,7 @@
3636
@io = TCP.Engine.accept(@, --ticket)
3737
@env.err.print("[Echoer] Accepted")
3838

39-
:fun ref _io_react(action IO.Action)
39+
:fun ref io_react(action IO.Action)
4040
case action == (
4141
| IO.Action.Read |
4242
@io.pending_reads -> (bytes_available |
@@ -63,15 +63,15 @@
6363
TCP.auth(@env.root).connect.to("localhost", port)
6464
)
6565

66-
// TODO: Can we make this trigger _io_react with IO.Action.OpenFailed
66+
// TODO: Can we make this trigger io_react with IO.Action.OpenFailed
6767
// automatically via the same mechanism we will use for queuing later
6868
// pending reads, instead of checking for this error case here?
6969
if (@io.connect_error != OSError.None) (
7070
@env.err.print("[EchoClient] Failed to connect:")
7171
@env.err.print(@io.connect_error.name)
7272
)
7373

74-
:fun ref _io_react(action IO.Action)
74+
:fun ref io_react(action IO.Action)
7575
case action == (
7676
| IO.Action.Opened |
7777
@env.err.print("[EchoClient] Connected")

src/TCP.Accept.Ticket.savi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
:: your program will eventually be unable to accept additional sockets.
3030
:fun iso reject
3131
@_listener.io_deferred_action(IO.Action.ClosedChild)
32-
_LibPonyOS.pony_os_socket_close(@_fd)
32+
_FFI.pony_os_socket_close(@_fd)

src/TCP.Engine.savi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
@write_stream = ByteStream.Writer.new(@io)
3232
@_listener = ticket._listener
3333

34-
:fun ref react(event CPointer(AsioEvent), flags U32, arg U32) @
34+
:fun ref react(event AsioEvent) @
3535
:yields IO.Action
36-
@io.react(event, flags, arg) -> (action |
36+
@io.react(event) -> (action |
3737
case action == (
3838
| IO.Action.Closed |
3939
// If this TCP connection is the child of a TCP listener, then let

src/TCP.Listen.Engine.savi

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
:let _actor IO.Actor(IO.Action)
55
:var _fd U32: -1
6-
:var _event CPointer(AsioEvent): CPointer(AsioEvent).null
6+
:var _event_id AsioEvent.ID: CPointer(AsioEvent.ID.Opaque).null // TODO: AsioEvent.ID.null
77

88
:var _count USize: 0
99
:var _limit USize
@@ -15,30 +15,30 @@
1515
:fun listen_port_number: _NetAddress._for_fd(@_fd).port // TODO: what happens if @_fd is invalid (-1)?
1616

1717
:new (@_actor, ticket TCP.Listen.Ticket, @_limit = 0)
18-
event = _LibPonyOS.pony_os_listen_tcp(
18+
event = _FFI.pony_os_listen_tcp(
1919
@_actor
2020
ticket.host.cstring
2121
ticket.port.cstring
2222
)
2323
if event.is_not_null (
24-
@_event = event
25-
@_fd = AsioEvent.fd(@_event)
24+
@_event_id = event
25+
@_fd = _FFI.pony_asio_event_fd(@_event_id)
2626
@_actor.io_deferred_action(IO.Action.Opened)
2727
|
28-
@listen_error = _LibPonyOS.pony_os_errno
28+
@listen_error = _FFI.pony_os_errno
2929
@_closed = True
3030
@_actor.io_deferred_action(IO.Action.OpenFailed)
3131
)
3232

3333
// TODO: Delegate much of the AsioEvent internals to an `IO.CoreEngine`.
34-
:fun ref react(event CPointer(AsioEvent), flags U32, arg U32) @
35-
if (@_event === event) (
36-
if AsioEvent.is_readable(flags) (
34+
:fun ref react(event AsioEvent) @
35+
if (event.id === @_event_id) (
36+
if event.is_readable (
3737
yield IO.Action.Read
3838
)
39-
if AsioEvent.is_disposable(flags) (
40-
AsioEvent.destroy(@_event)
41-
@_event = CPointer(AsioEvent).null
39+
if event.is_disposable (
40+
_FFI.pony_asio_event_destroy(@_event_id)
41+
@_event_id = CPointer(AsioEvent.ID.Opaque).null // TODO: AsioEvent.ID.null
4242
yield IO.Action.Closed
4343
)
4444
)
@@ -52,7 +52,7 @@
5252
if @_closed.not (
5353
try (
5454
while (@_limit == 0 || @_count < @_limit) (
55-
conn_fd = _LibPonyOS.pony_os_accept(@_event)
55+
conn_fd = _FFI.pony_os_accept(@_event_id)
5656
case conn_fd == (
5757
| 0 | error! // EWOULDBLOCK, don't try again
5858
| -1 | None // Some other error, so we can try again
@@ -82,11 +82,11 @@
8282
@
8383

8484
:fun ref close
85-
if (@_closed.not && @_event.is_not_null) (
85+
if (@_closed.not && @_event_id.is_not_null) (
8686
// When not on windows, unsubscribe immediately here instead of later.
87-
if Platform.is_windows.not AsioEvent.unsubscribe(@_event)
87+
if Platform.is_windows.not _FFI.pony_asio_event_unsubscribe(@_event_id)
8888

89-
_LibPonyOS.pony_os_socket_close(@_fd)
89+
_FFI.pony_os_socket_close(@_fd)
9090
@_fd = -1
9191
)
9292
@

src/_FFI.savi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
:module _FFI
2+
:ffi pony_asio_event_fd(event AsioEvent.ID) U32
3+
:ffi pony_asio_event_unsubscribe(event AsioEvent.ID) None
4+
:ffi pony_asio_event_destroy(event AsioEvent.ID) None
5+
6+
:ffi pony_os_listen_tcp(owner AsioEvent.Actor, host CPointer(U8), service CPointer(U8)) AsioEvent.ID
7+
:ffi pony_os_accept(event AsioEvent.ID) U32
8+
:ffi pony_os_socket_close(fd U32) None
9+
:ffi pony_os_errno OSError
10+
:ffi pony_os_sockname(fd U32, net_addr _NetAddress'ref) None
11+
:ffi pony_os_ipv4(net_addr _NetAddress'box) Bool
12+
:ffi pony_os_ipv6(net_addr _NetAddress'box) Bool

src/_Lib.savi

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/_NetAddress.savi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
:let _ipv6d U32: 0 :: Bits 97-128 of an IPv6 address in network byte order.
1313
:let _scope U32: 0 :: IPv6 scope (unicast, anycast, multicast, etc...).
1414

15-
:new _for_fd(fd): _LibPonyOS.pony_os_sockname(fd, @)
15+
:new _for_fd(fd): _FFI.pony_os_sockname(fd, @)
1616

17-
:fun is_ipv4: _LibPonyOS.pony_os_ipv4(@)
18-
:fun is_ipv6: _LibPonyOS.pony_os_ipv6(@)
17+
:fun is_ipv4: _FFI.pony_os_ipv4(@)
18+
:fun is_ipv6: _FFI.pony_os_ipv6(@)
1919

20-
:fun port: _LibC.ntohs(@_port) // (converted to host byte order)
21-
:fun scope: _LibC.ntohl(@_scope) // (converted to host byte order)
22-
:fun ipv4_addr: _LibC.ntohl(@_ipv4) // (converted to host byte order)
23-
// TODO: ipv6_addr (needs tuple return value)
24-
// TODO: family (needs Platform.is_big_endian)
20+
:fun port: @_port.be_to_native // (converted to host byte order)
21+
:fun scope: @_scope.be_to_native // (converted to host byte order)
22+
:fun ipv4_addr: @_ipv4.be_to_native // (converted to host byte order)
23+
// TODO: ipv6_addr
24+
// TODO: family
2525

2626
:fun "=="(other _NetAddress'box)
2727
@_family == other._family

0 commit comments

Comments
 (0)