mdlayher / vsock

Package vsock provides access to Linux VM sockets (AF_VSOCK) for communication between a hypervisor and its virtual machines. MIT Licensed.
MIT License
328 stars 65 forks source link

how to simply add keepAlive feature in vsock like in use tcp socket? #52

Closed brodyxchen closed 1 year ago

brodyxchen commented 1 year ago

I search source code of golang net/http package, and found the keepAlive feature depends on linux syscall.

// this is golang net/http source code in src/net/sockopt_posix.go: 118 func setKeepAlive(fd *netFD, keepalive bool) error { err := fd.pfd.SetsockoptInt(syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, boolint(keepalive)) runtime.KeepAlive(fd) return wrapSyscallError("setsockopt", err) }

I am develop a new package like net/http, depend on this vsock package instead of socket. But I dont now how to add keepAlive with linux syscall.

mdlayher commented 1 year ago

If keep alive works on AF_VSOCK, that's your answer. If not, it's something the Linux kernel would have to support in order to allow us to use it.

Note that we implement net.Listener and net/http just works over vsock. I don't think there's anything to do here, so closing.