-
Notifications
You must be signed in to change notification settings - Fork 44
/
IO.fs
79 lines (63 loc) · 2.71 KB
/
IO.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//-----------------------------------------------------------------------
// <copyright file="IO.fs" company="Akka.NET Project">
// Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
// Copyright (C) 2013-2015 Akka.NET project <https://github.com/akkadotnet/akka.net>
// Copyright (C) 2015 Bartosz Sypytkowski <gttps://github.com/Horusiath>
// </copyright>
//-----------------------------------------------------------------------
namespace Akkling
module IO =
open Akka.IO
open System.Net
/// <summary>
/// Gets TCP manager for current actor.
/// </summary>
let Tcp(context: Actor<'Message>) : IActorRef<Akka.IO.Tcp.Command> =
typed (Akka.IO.Tcp.Manager(context.System))
/// <summary>
/// Gets UDP manager for current actor.
/// </summary>
let Udp(context: Actor<'Message>) : IActorRef<Akka.IO.Udp.Command> =
typed (Akka.IO.Udp.Manager(context.System))
type TcpMessage = Akka.IO.TcpMessage
module Tcp =
let (|Received|_|) (msg:obj) : ByteString option =
match msg with
| :? Tcp.Received as r -> Some (r.Data)
| _ -> None
let (|Connected|_|) (msg:obj) : (EndPoint * EndPoint) option =
match msg with
| :? Tcp.Connected as c -> Some (c.RemoteAddress, c.LocalAddress)
| _ -> None
let (|CommandFailed|_|) (msg:obj) : #Tcp.Command option =
match msg with
| :? Tcp.CommandFailed as c ->
if c.Cmd :? #Tcp.Command
then Some (c.Cmd :?> #Tcp.Command)
else None
| _ -> None
let (|ConnectionClosed|_|) (msg:obj) =
match msg with
| :? Tcp.ConnectionClosed as closed -> Some closed
| _ -> None
let (|Closed|Aborted|ConfirmedClosed|PeerClosed|ErrorClosed|) (msg:Tcp.ConnectionClosed) =
match msg with
| :? Tcp.Closed -> Closed
| :? Tcp.Aborted -> Aborted
| :? Tcp.ConfirmedClosed -> ConfirmedClosed
| :? Tcp.PeerClosed -> PeerClosed
| :? Tcp.ErrorClosed -> ErrorClosed
module Udp =
let inline Bind(ref: IActorRef<'t>, localAddress: EndPoint) =
Akka.IO.Udp.Bind(ref, localAddress) :> Udp.Command
let (|Received|_|) (msg:obj) : ByteString option =
match msg with
| :? Udp.Received as r -> Some (r.Data)
| _ -> None
let (|CommandFailed|_|) (msg:obj) : 'C option =
match msg with
| :? Udp.CommandFailed as c ->
if c.Cmd :? 'C
then Some (c.Cmd :?> 'C)
else None
| _ -> None