summaryrefslogtreecommitdiff
path: root/src/lib.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.go')
-rw-r--r--src/lib.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/lib.go b/src/lib.go
index 60b0742..2bcb98c 100644
--- a/src/lib.go
+++ b/src/lib.go
@@ -7,6 +7,7 @@ import (
"errors"
"flag"
"fmt"
+ "io"
"io/ioutil"
"log/slog"
"net"
@@ -31,9 +32,10 @@ var (
Colour string
)
-var EmitActiveConnection = g.MakeGauge("active-connections")
-var EmitNicksInChannel = g.MakeGauge("nicks-in-channel")
-var EmitReceivedMessage = g.MakeCounter("received-message")
+var EmitActiveConnection = g.MakeGauge("active-connections")
+var EmitNicksInChannel = g.MakeGauge("nicks-in-channel")
+var EmitReceivedMessage = g.MakeCounter("received-message")
+var EmitWriteToClientError = g.MakeCounter("write-to-client")
const pingFrequency = time.Duration(30) * time.Second
const pongMaxLatency = time.Duration(5) * time.Second
@@ -50,6 +52,7 @@ type Context struct {
type Connection struct {
conn net.Conn
+ replyChan chan string
// id *UUID
id string
isAuthenticated bool
@@ -281,7 +284,21 @@ func ReadLoop(ctx *Context, connection *Connection) {
}
func WriteLoop(ctx *Context, connection *Connection) {
- // fmt.Println("WriteLoop")
+ for message := range connection.replyChan {
+ _, err := io.WriteString(connection.conn, message)
+ if err != nil {
+ g.Error(
+ "Failed to send data to user",
+ "user-reply-error",
+ "err", err,
+ )
+ EmitWriteToClientError()
+ continue
+ }
+ }
+
+ EmitActiveConnection.Dec()
+ connection.conn.Close()
}
func PingLoop(ctx *Context, connection *Connection) {