summaryrefslogtreecommitdiff
path: root/src/hub
diff options
context:
space:
mode:
Diffstat (limited to 'src/hub')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvForward.go33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvForward.go b/src/hub/src/spreadspace.org/sfive/s5srvForward.go
index a479c2e..eeb2352 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srvForward.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srvForward.go
@@ -77,6 +77,22 @@ func fwdGetLastUpdate(baseurl string, client *http.Client, hubUuid string) (last
return
}
+func fwdWriteUpdates(updates []DataUpdateFull, pw *io.PipeWriter) {
+ defer pw.Close()
+
+ enc, err := NewStatefulEncoder(pw)
+ if err != nil {
+ s5l.Printf("fwd: failed encoding/sending init message: %v", err)
+ return
+ }
+ for _, upd := range updates {
+ if err := enc.Encode(upd); err != nil {
+ s5l.Printf("fwd: failed encoding/sending updates: %v", err)
+ return
+ }
+ }
+}
+
func fwdPostUpdates(client *http.Client, url string, pr *io.PipeReader) (int, error) {
resp, err := client.Post(url, "application/json", pr)
if err != nil {
@@ -126,22 +142,7 @@ tryResync:
}
pr, pw := io.Pipe()
- go func(pw *io.PipeWriter) {
- defer pw.Close()
-
- enc, err := NewStatefulEncoder(pw)
- if err != nil {
- s5l.Printf("fwd: failed encoding/sending init message: %v", err)
- return
- }
- for _, upd := range updates {
- if err := enc.Encode(upd); err != nil {
- s5l.Printf("fwd: failed encoding/sending updates: %v", err)
- return
- }
- }
- }(pw)
-
+ go fwdWriteUpdates(updates, pw)
if num, err := fwdPostUpdates(client, url, pr); err != nil {
s5l.Printf("fwd: failed sending updates: %v", err)
continue tryResync