txlyre 1 tháng trước cách đây
mục cha
commit
c3dcc73b77
1 tập tin đã thay đổi với 7 bổ sung6 xóa
  1. 7 6
      main.go

+ 7 - 6
main.go

@@ -7,7 +7,6 @@ import (
 	"net/http"
 	"os"
 	"os/signal"
-	"time"
 
 	"golang.org/x/crypto/blake2b"
 
@@ -17,7 +16,7 @@ import (
 	"github.com/gorilla/websocket"
 )
 
-func sender(queue chan []byte, secret string, cooldown uint) {
+func sender(queue chan []byte, secret string) {
 	log.Println("start sender")
 
 	h := make(http.Header, 1)
@@ -42,7 +41,11 @@ func sender(queue chan []byte, secret string, cooldown uint) {
 				break
 			}
 
-			time.Sleep(time.Duration(cooldown) * time.Millisecond)
+			if _, _, err := ws.ReadMessage(); err != nil {
+				log.Println("connection lost")
+
+				break
+			}
 		}
 
 		ws.Close()
@@ -100,7 +103,6 @@ func main() {
 	var bufferSize uint
 	var processorsCount uint
 	var sendersCount uint
-	var sendCooldown uint
 	var ident string
 	var secret string
 
@@ -108,7 +110,6 @@ func main() {
 	flag.UintVar(&bufferSize, "bufferSize", 1024, "sending queue max capacity")
 	flag.UintVar(&processorsCount, "processorsCount", 1, "count of processor goroutines")
 	flag.UintVar(&sendersCount, "sendersCount", 1, "count of sender goroutines")
-	flag.UintVar(&sendCooldown, "sendCooldown", 80, "send cooldown (in ms)")
 	flag.StringVar(&ident, "ident", "", "yebi.su ident")
 	flag.StringVar(&secret, "secret", "", "yebi.su secret")
 
@@ -154,7 +155,7 @@ func main() {
 	defer close(senderQueue)
 
 	for i := 0; i < int(sendersCount); i++ {
-		go sender(senderQueue, secret, sendCooldown)
+		go sender(senderQueue, secret)
 	}
 
 	for i := 0; i < int(processorsCount); i++ {