summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-06-24 16:50:41 -0300
committerEuAndreh <eu@euandre.org>2024-06-24 16:50:41 -0300
commit90aecdeb14078457f59594c966b3958470f411d4 (patch)
treed2bec8897eeb77dbd6a2ac5749f70ff4141ee309 /src
parentrm -rf src/static/ (diff)
downloadpapod-90aecdeb14078457f59594c966b3958470f411d4.tar.gz
papod-90aecdeb14078457f59594c966b3958470f411d4.tar.xz
src/lib.go: Add simplistic scaffold of the connection WriteLoop()
Diffstat (limited to 'src')
-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) {