2024-12-28 19:11:50 +01:00
|
|
|
package msghandlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"daemonSocketExample/daemonconn"
|
|
|
|
"log/slog"
|
2024-12-29 03:06:56 +01:00
|
|
|
"time"
|
2024-12-28 19:11:50 +01:00
|
|
|
)
|
|
|
|
|
2024-12-29 03:06:56 +01:00
|
|
|
func handleEchoRequest(ctx HandlerContext, msg daemonconn.Message) error {
|
2024-12-28 19:11:50 +01:00
|
|
|
echoRequest := msg.(daemonconn.EchoRequest)
|
2024-12-29 03:06:56 +01:00
|
|
|
slog.Info("Got echo request", "echoByte", echoRequest.EchoByte, "updatesCount", echoRequest.UpdatesCount)
|
|
|
|
|
|
|
|
for i := 0; i < int(echoRequest.UpdatesCount); i++ {
|
|
|
|
err := ctx.conn.WriteMessage(daemonconn.EchoUpdate{EchoByte: echoRequest.EchoByte})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
slog.Info("Sent echo update", "i", i)
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
echoResponse := daemonconn.EchoResponse{EchoByte: echoRequest.EchoByte}
|
|
|
|
err := ctx.conn.WriteMessage(echoResponse)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
slog.Info("Sent echo response", "echoByte", echoResponse.EchoByte)
|
2024-12-28 19:11:50 +01:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|