-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
What version of Go are you using (go version)?
go version go1.16.2 linux/amd64
I'm using EPOLL(7) from the sys/unix package, since epoll_event struct have a C union epoll_data
typedef union epoll_data {
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;
struct epoll_event {
uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
};The sys/unix package supporting the struct EpollEvent with Pad
at the end of the struct to fill the union size.
type EpollEvent struct {
Events uint32
Fd int32
Pad int32
}The goal of this issue, is to use EpollEvent with void *ptr and not int fd
I created a struct epollEvent and called the syscall manually
To try to implement the change.
type epollEvent struct {
Events uint32
Ptr uintptr
}
func epollWait(epfd int, events []epollEvent, msec int) (n int, err error) {
var _p0 unsafe.Pointer
if len(events) > 0 {
_p0 = unsafe.Pointer(&events[0])
} else {
_p0 = unsafe.Pointer(&_zero)
}
r0, _, e1 := unix.Syscall6(unix.SYS_EPOLL_WAIT, uintptr(epfd), uintptr(_p0), uintptr(len(events)), uintptr(msec), 0, 0)
n = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}The implementation issue
When I initialize my slice epollEvent and all Ptr uintpr to a struct instance associated to an epoll event.
And I call epollWait I retrieve my address associated to the event.
But the problem here is the Golang runtime, sometime the runtime move or GC the data associated to my address.
I tried to use unsafe.Pointer insteaf of uintptr but the issue is the same.
In this case what is the best way to create data and associate it to my Ptr
To be retrieved it later by epoll_wait(2) syscall?
Do you think the Idea I would like to realize it possible, if yes I could propose some change to support both in sys/unix package fdmode and ptr mode.
Thanks a lot
Metadata
Metadata
Assignees
Labels
Type
Projects
Status