split src/devices/input into src/devices/input/{raw,wrap}

This commit is contained in:
bel
2023-03-24 19:51:38 -06:00
parent ab673a81f0
commit 38b00e55b0
16 changed files with 161 additions and 159 deletions

View File

@@ -0,0 +1,39 @@
package raw
import (
"log"
"net"
"os"
"strconv"
)
type UDP struct {
conn net.PacketConn
}
func NewUDP(port int) UDP {
conn, err := net.ListenPacket("udp", ":"+strconv.Itoa(port))
if err != nil {
panic(err)
}
return UDP{
conn: conn,
}
}
func (udp UDP) Read() []byte {
panic("NEEDS TO BE IN BG THREAD SO WE CAN SHUT DOWN WITHOUT BLOCKING ON READ OR AT LEAST BE RESPONSIVE")
buff := make([]byte, 1024)
n, _, err := udp.conn.ReadFrom(buff)
if err != nil {
panic(err)
}
if os.Getenv("DEBUG") == "true" {
log.Printf("raw.UDP.Read() => %s", buff[:n])
}
return buff[:n]
}
func (udp UDP) Close() {
udp.conn.Close()
}