mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-08-07 07:14:50 +00:00
f1f8f95653
* vendor Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Return agent changes Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Add missing import Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * remove vendor Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix formatting Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Formatting errors Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Update agent/api/grpc/client.go Signed off: WashingtonKK washingtonkigan@gmail.com Co-authored-by: Sammy Kerata Oina <44265300+SammyOina@users.noreply.github.com> * add linters and fix Signed-off-by: SammyOina <sammyoina@gmail.com> * update ci Signed-off-by: SammyOina <sammyoina@gmail.com> * remove deprecated dependencies and use local agent and manager Signed-off-by: SammyOina <sammyoina@gmail.com> * update mainflux Signed-off-by: SammyOina <sammyoina@gmail.com> * Fix Jaeger URL in agent and manager main.go files The Jaeger URL in the agent and manager main.go files was incorrect. This commit fixes the Jaeger URL by updating it to "http://localhost::4318/v1/traces". Signed-off-by: SammyOina <sammyoina@gmail.com> --------- Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> Signed-off-by: SammyOina <sammyoina@gmail.com> Co-authored-by: WashingtonKK <washingtonkigan@gmail.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package socket
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
"os"
|
|
)
|
|
|
|
func StartUnixSocketServer(socketPath string) (net.Listener, error) {
|
|
// Remove any existing socket file
|
|
_ = os.Remove(socketPath)
|
|
|
|
// Create a Unix domain socket listener
|
|
listener, err := net.Listen("unix", socketPath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating socket listener: %v", err)
|
|
}
|
|
|
|
fmt.Println("Unix domain socket server is listening on", socketPath)
|
|
|
|
return listener, nil
|
|
}
|
|
|
|
func AcceptConnection(listener net.Listener, dataChannel chan []byte, errorChannel chan error) {
|
|
conn, err := listener.Accept()
|
|
if err != nil {
|
|
errorChannel <- fmt.Errorf("error accepting connection:: %v", err)
|
|
}
|
|
|
|
handleConnection(conn, dataChannel, errorChannel)
|
|
}
|
|
|
|
func handleConnection(conn net.Conn, dataChannel chan []byte, errorChannel chan error) {
|
|
defer conn.Close()
|
|
|
|
// Create a dynamic buffer to store incoming data
|
|
var buffer []byte
|
|
tmp := make([]byte, 1024)
|
|
|
|
for {
|
|
// Read data into the temporary buffer
|
|
n, err := conn.Read(tmp)
|
|
if err != nil {
|
|
if err == io.EOF {
|
|
break
|
|
}
|
|
errorChannel <- err
|
|
}
|
|
buffer = append(buffer, tmp[:n]...)
|
|
}
|
|
|
|
dataChannel <- buffer
|
|
}
|