summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2012-01-29 18:11:33 +0100
committerYorhel <git@yorhel.nl>2012-01-29 18:11:33 +0100
commitc90d73095b5ef183f14ec32fd2e666ae111dd3fb (patch)
tree5fe85d076663349df394ae82f08dd1f939695368
parent204622208ea1887f8e43a960c8750016d6743dc9 (diff)
Make PatternReg a 32-bit integer + handle overflow
The Server-Server communication protocol assumes that pattern registration IDs are 32bit. 64bit IDs are a bit overkill, anyway.
-rw-r--r--server.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/server.go b/server.go
index 65123e2..64d3715 100644
--- a/server.go
+++ b/server.go
@@ -1,6 +1,6 @@
package tanja
-type PatternReg uint64
+type PatternReg int32
type Server struct {
ref chan<- int
@@ -57,6 +57,13 @@ type serverRegister struct {
reply chan<- PatternReg
}
+func (i *PatternReg) inc() {
+ *i++
+ if *i < 0 {
+ *i = 1
+ }
+}
+
// Manages a Matcher object and routes messages to sessions
func serverRouter(ref <-chan int, reg <-chan *serverRegister, unreg <-chan PatternReg, snd <-chan *serverSend) {
p := make(map[PatternReg]*MatcherItem)
@@ -69,12 +76,12 @@ func serverRouter(ref <-chan int, reg <-chan *serverRegister, unreg <-chan Patte
clients += n
case n := <-reg:
for p[lastId] != nil {
- lastId++
+ lastId.inc()
}
n.dat.id = lastId
p[lastId] = m.Add(n.pat, n.dat)
n.reply <- lastId
- lastId++
+ lastId.inc()
case n := <-unreg:
if r, e := p[n]; e {
m.Remove(r)