Skip to content

Commit 9a9c8fe

Browse files
committed
[2.101717.154] 10/17/17 at 10:07 PM | 1 updated tm modules | by DashBot
1 parent 44414bf commit 9a9c8fe

28 files changed

+2665
-384
lines changed

cluster-1.1.6.tm renamed to cluster-1.1.7.tm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,13 @@ if 0 {
170170
}
171171
proc ::cluster::join args {
172172
set config $::cluster::DEFAULT_CONFIG
173+
173174
if { [dict exists $args -protocols] } {
174175
set protocols [dict get $args -protocols]
175176
} else {
176177
set protocols [dict get $config protocols]
177178
}
179+
178180
dict for { k v } $args {
179181
set k [string trimleft $k -]
180182
if { ! [dict exists $config $k] && $k ni $protocols } {
@@ -188,7 +190,7 @@ proc ::cluster::join args {
188190
}
189191
dict set config $k $v
190192
}
191-
193+
192194
# in case a boolean is passed to remote value, we convert to number
193195
# style boolean
194196
set remote [dict get $config remote]

cluster/classes/cluster/cluster-api.tcl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@
3535
# removed from our cache.
3636
::oo::define ::cluster::cluster method ttl {} { return [dict get $CONFIG ttl] }
3737

38-
::oo::define ::cluster::cluster method protocols {} { return [dict get $CONFIG protocols] }
38+
::oo::define ::cluster::cluster method protocols {{objects false}} {
39+
if {$objects} {
40+
return [info commands ${NS}::protocols::*]
41+
} else {
42+
return [dict get $CONFIG protocols]
43+
}
44+
45+
}
3946

4047
::oo::define ::cluster::cluster method protocol { protocol } {
4148
if { [dict exists $PROTOCOLS $protocol] } {

cluster/classes/cluster/cluster.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
set PROTOCOLS [dict create]
8585
namespace eval ${NS}::protocols {}
8686
foreach protocol [dict get $CONFIG protocols] {
87-
if { [info commands ::cluster::protocol::$protocol] ne {} } {
87+
if {[info commands ::cluster::protocol::$protocol] ne {}} {
8888
dict set PROTOCOLS $protocol \
8989
[::cluster::protocol::$protocol create \
9090
${NS}::protocols::$protocol [self] $ID $CONFIG

cluster/protocols/cluster-unix.tcl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,28 @@ if {[info commands ::cluster::protocol::u] eq {}} {
3030
}
3131

3232
::oo::define ::cluster::protocol::u method SetServerPath config {
33-
set SERVER_PATH [file normalize \
33+
set path [file normalize \
3434
[file nativename [dict get $config u path]]
3535
]
36-
append SERVER_PATH - [$CLUSTER sid]
36+
37+
set filename [file tail $path]
38+
set dir [file dirname $path]
39+
40+
set extidx [string last "." $filename]
41+
42+
# index
43+
if {$extidx != -1 && $extidx != 0} {
44+
set ext [string range $filename $extidx end]
45+
set filename [string range $filename 0 end-[string length $ext]]
46+
} else {
47+
set ext {}
48+
}
49+
set SERVER_PATH [file join \
50+
$dir \
51+
${filename}-[$CLUSTER sid]${ext}
52+
]
53+
54+
puts $SERVER_PATH
3755
}
3856

3957
::oo::define ::cluster::protocol::u method CreateStream {} {

tcl-modules/bpacket-1.0.0.tm

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

tcl-modules/bpacket-1.3.2.tm

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
if 0 {
2+
@ bpacket @
3+
binary packet is used to encode and decode data in a way that
4+
is similar to protocol buffers.
5+
6+
it is composed of various parts. data is encoded using a given
7+
template and the template is used on each end to encode/decode
8+
for communication.
9+
10+
@type BPTemplate
11+
| This builds our binary format template. It is utilized by both the
12+
| encoding and decoding end to understand how to build and parse our
13+
| binary packets automatically.
14+
TODO:
15+
* asterix items are marked as required, although this is not
16+
* currently enforced.
17+
18+
> Format
19+
{(*)? (type_name) (...type_args) | (field_num)}
20+
@example
21+
{
22+
set template {
23+
1 flags props | type channel
24+
2 string hid
25+
3 string sid
26+
4 numlist nlist | known
27+
5 varint timestamp
28+
6 list protocols
29+
7 string ruid
30+
8 string op
31+
9 raw raw
32+
10 list tags
33+
11 boolean keepalive
34+
12 list filter
35+
13 string error
36+
14 dict data | {
37+
first_name
38+
last_name
39+
phone_number
40+
address
41+
employer
42+
}
43+
}
44+
set data [dict create \
45+
timestamp [clock microseconds] \
46+
hid 00:00:00:00:00:00 \
47+
sid a-7898 \
48+
props [list 0 10] \
49+
protocols [list a b c] \
50+
ruid MY_EVENT \
51+
keepalive true \
52+
data [dict create \
53+
first_name john \
54+
last_name smith \
55+
phone_number 6665554444 \
56+
address "Some address can go here" \
57+
employer "Acme, Inc"
58+
]
59+
]
60+
}
61+
}
62+
63+
set template {
64+
1 boolean compact
65+
2 varint schema
66+
}
67+
68+
namespace eval ::bpacket {
69+
namespace ensemble create
70+
namespace export {[a-z]*}
71+
72+
# the value used to indiciate the start of the header
73+
variable HEADER "\xC0\x8D"
74+
# end of packet - should not be the same as HEADER as we
75+
# will remove any number of $EOF THEN look for HEADER to
76+
# determine if we have multiple packets concatted
77+
variable EOF "\x00\x00"
78+
79+
# holds a hash map of $id -> $type and $type -> $id
80+
# of types that have been registered.
81+
#
82+
# types are required & registered when they are required by a template
83+
if {![info exists ::bpacket::REGISTRY]} {
84+
variable REGISTRY [dict create]
85+
}
86+
87+
# these types are required and will be required automatically
88+
# regardless of the given template.
89+
variable REQUIRED_TYPES [list varint string]
90+
}
91+
92+
namespace eval ::bpacket::decode {
93+
namespace ensemble create
94+
namespace export {[a-z]*}
95+
}
96+
97+
namespace eval ::bpacket::encode {
98+
namespace ensemble create
99+
namespace export {[a-z]*}
100+
}
101+
102+
namespace eval ::bpacket::type {
103+
namespace ensemble create
104+
namespace export {[a-z]*}
105+
}
106+
107+
source -encoding utf-8 [file join \
108+
[file dirname \
109+
[file normalize [info script]] \
110+
] \
111+
bpacket \
112+
utils.tcl
113+
]
114+
115+
if 0 {
116+
@ bpacket create | $type $name ...$args
117+
Allows creation of the various bpacket classes
118+
@arg type {io|stream}
119+
@type {io}
120+
creates a bpacket io object which is responsible for both
121+
encoding and decoding bpackets
122+
@type {stream}
123+
creates a bpacket stream object which receives a stream of
124+
data and outputs valid bpackets when they are found
125+
@arg name {string}
126+
@arg args
127+
@if | $type {io}
128+
@arg template {BPTemplate}
129+
the template that the given io handler should use.
130+
}
131+
proc ::bpacket::create {type name args} {
132+
switch -nocase -- $type {
133+
io {
134+
package require bpacket::classes::io
135+
}
136+
stream {
137+
package require bpacket::classes::stream
138+
}
139+
}
140+
tailcall ::bpacket::classes::[string tolower $type] create $name {*}$args
141+
}

0 commit comments

Comments
 (0)