Browse Source

Improvements

master
Tim Schuster 2 years ago
parent
commit
e5e069ff27
Signed by: Tim Schuster <mail@timschuster.info> GPG Key ID: F9E27097EFB77F61
2 changed files with 11 additions and 1 deletions
  1. 5
    1
      app/main.go
  2. 6
    0
      wsserver/main.go

+ 5
- 1
app/main.go View File

@@ -1,7 +1,11 @@
1 1
 package main
2 2
 
3
-import "git.timschuster.info/tscs37/chocococon"
3
+import (
4
+	"git.timschuster.info/tscs37/chocococon"
5
+	"github.com/chzyer/readline"
6
+)
4 7
 
5 8
 func main() {
9
+	readline.SetHistoryPath(".chocococon-hist")
6 10
 	chocococon.Run()
7 11
 }

+ 6
- 0
wsserver/main.go View File

@@ -66,6 +66,8 @@ type ServerInstance struct {
66 66
 
67 67
 	ioLock sync.Mutex
68 68
 	rpiLock sync.Mutex
69
+
70
+	rpiRetrLock sync.RWMutex
69 71
 }
70 72
 
71 73
 const (
@@ -105,6 +107,8 @@ func (si *ServerInstance) hasRpi(w http.ResponseWriter, r *http.Request) {
105 107
 }
106 108
 
107 109
 func (si *ServerInstance) httpRetrieve(w http.ResponseWriter, r *http.Request) {
110
+	si.rpiRetrLock.RLock()
111
+	defer si.rpiRetrLock.RUnlock()
108 112
 	si.ioLock.Lock()
109 113
 	defer si.ioLock.Unlock()
110 114
 	if r.URL.Query().Get("cb") == "" {
@@ -216,6 +220,7 @@ func (si *ServerInstance) httpPut(w http.ResponseWriter, r *http.Request) {
216 220
 	go func(callbackUrl string) {
217 221
 		si.rpiLock.Lock()
218 222
 		defer si.rpiLock.Unlock()
223
+		defer si.rpiRetrLock.Unlock()
219 224
 		var msgDat = []byte{}
220 225
 		if !si.fakeMode {
221 226
 			_, msg, err := si.rpi.ReadMessage()
@@ -249,6 +254,7 @@ func (si *ServerInstance) httpPut(w http.ResponseWriter, r *http.Request) {
249 254
 }
250 255
 
251 256
 func (si *ServerInstance) httpRetrPos(w http.ResponseWriter, r *http.Request) {
257
+	si.rpiRetrLock.Lock()
252 258
 	si.ioLock.Lock()
253 259
 	defer si.ioLock.Unlock()
254 260
 	if r.URL.Query().Get("cb") == "" {

Loading…
Cancel
Save