summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2012-03-30 12:47:29 +0200
committerYorhel <git@yorhel.nl>2012-03-30 12:47:29 +0200
commit1e36c6d184fdebedbd897bb06593e7f733a33a28 (patch)
tree4887d71908e22d7dd53583ca3be0f0d1fea3e280
parent163fb3d7fbdb17a209518e7499a9538c6e7a917f (diff)
Store and pass around tuples as value rather than reference
This makes Tuples more convenient to use because the index expression (tup[n]) doesn't work on pointers to slices. There's one exception for Registration.send(), which will use the pointer to detect duplicates. (Pointers can be compared, slices can't).
-rw-r--r--msg.go4
-rw-r--r--node.go7
-rw-r--r--reg.go4
-rw-r--r--ses.go4
-rw-r--r--tuples.go6
5 files changed, 13 insertions, 12 deletions
diff --git a/msg.go b/msg.go
index f73e35d..da8599d 100644
--- a/msg.go
+++ b/msg.go
@@ -1,7 +1,7 @@
package tanja
type Message struct {
- Tup *Tuple
+ Tup Tuple
ret *ReturnPath
reg *Registration
}
@@ -17,7 +17,7 @@ func (m *Message) Dispatch() {
}
}
-func (*Message) Reply(t *Tuple) {
+func (*Message) Reply(t Tuple) {
// TODO
}
diff --git a/node.go b/node.go
index 0e1d8b4..fdb75a3 100644
--- a/node.go
+++ b/node.go
@@ -44,14 +44,15 @@ func (n *Node) reg(r *Registration) {
// TODO: notify links
}
-func (n *Node) send(t *Tuple, path *ReturnPath) {
+func (n *Node) send(t Tuple, path *ReturnPath) {
// TODO: Some way of preventing that a message is routed back to the link
// it came from.
n.lock.Lock()
defer n.lock.Unlock()
for _, r := range n.regs {
- if t.Match(*r.pat) {
- r.send(t, path)
+ if t.Match(r.pat) {
+ // Pass a reference to the Tuple to allow duplicate detection.
+ r.send(&t, path)
}
}
}
diff --git a/reg.go b/reg.go
index cfcaa88..b6ac69d 100644
--- a/reg.go
+++ b/reg.go
@@ -1,7 +1,7 @@
package tanja
type Registration struct {
- pat *Tuple
+ pat Tuple
id int32
active bool
willReply bool
@@ -64,7 +64,7 @@ func (r *Registration) unreg() {
// Called while the node lock is held.
func (r *Registration) send(t *Tuple, path *ReturnPath) {
if s, ok := r.recv.(*Session); ok {
- s.disp <- &Message{t, path, r}
+ s.disp <- &Message{*t, path, r}
}
// TODO: links
}
diff --git a/ses.go b/ses.go
index 160a037..2ef4ae0 100644
--- a/ses.go
+++ b/ses.go
@@ -77,7 +77,7 @@ func (n *Node) Session() *Session {
return s
}
-func (s *Session) Register(p *Tuple, willReply bool) *Registration {
+func (s *Session) Register(p Tuple, willReply bool) *Registration {
r := &Registration{}
r.recv = s
r.pat = p
@@ -134,7 +134,7 @@ func (s *Session) Run() {
}
}
-func (s *Session) Send(t *Tuple, wantReply bool) *ReturnPath {
+func (s *Session) Send(t Tuple, wantReply bool) *ReturnPath {
// TODO: fix a return path
var r *ReturnPath
s.node.send(t, r)
diff --git a/tuples.go b/tuples.go
index de128be..8a7df78 100644
--- a/tuples.go
+++ b/tuples.go
@@ -120,11 +120,11 @@ func (t Tuple) Match(p Tuple) bool {
return true
}
-// Same as &Tuple{El(a), El(b), ..}
-func Tup(t ...interface{}) *Tuple {
+// Same as Tuple{El(a), El(b), ..}
+func Tup(t ...interface{}) Tuple {
r := make(Tuple, len(t))
for i, v := range t {
r[i] = El(v)
}
- return &r
+ return r
}