upgrade to support writing to a memmap file

This commit is contained in:
2026-08-23 22:56:14 +01:00
parent 76a091b076
commit 9adc0a9456
10 changed files with 300 additions and 169 deletions
+88 -25
View File
@@ -1,53 +1,116 @@
//go:build (linux && cgo) || (darwin && cgo)
// +build linux,cgo darwin,cgo
package winutils
import (
"errors"
"sync"
"fmt"
"net"
"os"
"time"
)
const (
WAIT_OBJECT_0 = 0
WAIT_TIMEOUT = 258
)
var (
once sync.Once
ErrUnsupportedOS = errors.New("not found")
)
type utils struct {
socketPath string
listener *net.UnixConn
}
// INITIALIZATION
func newUtils() (*utils, error) {
return nil, ErrUnsupportedOS
return &utils{}, nil
}
func (u *utils) Close() {
if u.listener != nil {
u.listener.Close()
os.Remove(u.socketPath)
}
}
// openEvent opens a windows.Handle for a given event
// OpenEvent creates or connects to a Unix socket for event signaling on Linux
func (u *utils) OpenEvent(eventName string) error {
return ErrUnsupportedOS
u.socketPath = fmt.Sprintf("/tmp/iracing_%s.sock", eventName)
_ = os.Remove(u.socketPath)
addr, err := net.ResolveUnixAddr("unixgram", u.socketPath)
if err != nil {
return err
}
l, err := net.ListenUnixgram("unixgram", addr)
if err != nil {
return err
}
u.listener = l
return nil
}
// OpenBroadcastChannel opens up a broadcast channel to send commands to iracing
func (u *utils) OpenBroadcastChannel(name string) error {
return ErrUnsupportedOS
// No-op or log stub on Linux
return nil
}
// INITIALIZATION
// openEvent waits for a good response for some given time
// CheckValidDataEvent waits for a pulse byte sent over the socket
func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
return false
if u.listener == nil {
return false
}
_ = u.listener.SetReadDeadline(time.Now().Add(timeout))
buf := make([]byte, 1)
_, err := u.listener.Read(buf)
return err == nil
}
// SendBroadcastMessage sends a message trough the broadcast channel
func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
return ErrUnsupportedOS
return nil
}
// package winutils
//
// import (
// "errors"
// "sync"
// "time"
// )
//
// const (
// WAIT_OBJECT_0 = 0
// WAIT_TIMEOUT = 258
// )
//
// var (
// once sync.Once
// ErrUnsupportedOS = errors.New("not found")
// )
//
// type utils struct {
// }
//
// // INITIALIZATION
// func newUtils() (*utils, error) {
// return nil, ErrUnsupportedOS
// }
//
// func (u *utils) Close() {
// }
//
// // openEvent opens a windows.Handle for a given event
// func (u *utils) OpenEvent(eventName string) error {
// return ErrUnsupportedOS
// }
//
// // OpenBroadcastChannel opens up a broadcast channel to send commands to iracing
// func (u *utils) OpenBroadcastChannel(name string) error {
// return ErrUnsupportedOS
// }
//
// // INITIALIZATION
//
// // openEvent waits for a good response for some given time
// func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
// return false
// }
//
// // SendBroadcastMessage sends a message trough the broadcast channel
// func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
// return ErrUnsupportedOS
// }
+6 -9
View File
@@ -1,5 +1,4 @@
//go:build windows && cgo
// +build windows,cgo
// go:build windows
package winutils
@@ -16,13 +15,11 @@ const (
WAIT_TIMEOUT = 258
)
var (
once sync.Once
)
var once sync.Once
type utils struct {
user32DLL *windows.LazyDLL
wEvent *windows.Handle
wEvent windows.Handle
wBroadcastChn uintptr
}
@@ -34,7 +31,7 @@ func newUtils() (*utils, error) {
}
func (u *utils) Close() {
closeEvent(u.wEvent)
closeEvent(&u.wEvent)
// Do we need to unload the user32DLL ???
// Do we need to close the broadcast channel ???
}
@@ -50,7 +47,7 @@ func (u *utils) OpenEvent(eventName string) error {
if err != nil {
return err
}
u.wEvent = &event
u.wEvent = event
return nil
}
@@ -90,7 +87,7 @@ func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
t0 := time.Now().UnixNano()
timeoutInt := uint32(timeout / time.Millisecond)
result, err := windows.WaitForSingleObject(*u.wEvent, timeoutInt)
result, err := windows.WaitForSingleObject(u.wEvent, timeoutInt)
if err != nil {
remaining := timeoutInt - uint32((time.Now().UnixNano()-t0)/1000000)
if remaining > 0 {