connections.anubis
2.73 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
*Project* The Anubis Project
*Title* Unifying the handling of connections.
*Copyright* Copyright (c) Alain Prouté 2003.
*Author* Alain Prouté
*Overview*
Anubis knows several sorts of connections:
* connections to files (on disk)
* TCP/IP connections
* SSL connections.
Unfortunatly, the system (at least for version 1) has not been conceived
consistently. Actually, file and TCP/IP connections are of type ?Addr(Int8), while SSL
connections are of type SSL_Connection.
In order to unify the handling of all sorts of connections, we first define the
following type:
public type Connection:
file(RAddr(Int8)),
file(WAddr(Int8)),
file(RWAddr(Int8)),
tcp(RWAddr(Int8)),
ssl(SSL_Connection).
The operations on connections are:
- opening connections (closing is automatic),
- writing to a connection
- reading from a connection.
For opening connections, see 'file', 'connect' and 'open_SSL_connection' in
'predefined.anubis'.
Now, here are the unified tools for reading and writing:
public define Maybe(ByteArray) // result of reading
read
(
Connection c,
Int32 n, // maximal number of bytes to read
Int32 timeout // in seconds
).
public define Maybe(Int32) // number of bytes actually written
write
(
Connection c,
ByteArray ba
).
--- That's all for the public part. ---------------------------------------------------
public define Maybe(ByteArray) // result of reading
read
(
Connection c,
Int32 n,
Int32 timeout
) =
if c is
{
file(ra) then read(ra,n,timeout),
file(wa) then alert,
file(rwa) then read(weaken(rwa),n,timeout),
tcp(a) then read(weaken(a),n,timeout),
ssl(a) then read(a,n,timeout)
}.
public define Maybe(Int32) // number of bytes actually written
write
(
Connection c,
ByteArray ba
) =
if c is
{
file(ra) then alert,
file(wa) then write(wa,ba),
file(rwa) then write(weaken(rwa),ba),
tcp(a) then write(weaken(a),ba),
ssl(a) then write(a,ba)
}.
public define (Int32,Int32)
remote_IP_address_and_port
(
Connection c
) =
if c is
{
file(ra) then alert,
file(wa) then alert,
file(rwa) then alert,
tcp(a) then remote_IP_address_and_port(a),
ssl(a) then remote_SSL_address_and_port(a)
}.