xnet_windows.go 876 B

12345678910111213141516171819202122232425262728293031
  1. // +build windows
  2. package xnet
  3. import (
  4. "net"
  5. "time"
  6. "github.com/Microsoft/go-winio"
  7. )
  8. // ListenLocal opens a local socket for control communication
  9. func ListenLocal(socket string) (net.Listener, error) {
  10. // set up ACL for the named pipe
  11. // allow Administrators and SYSTEM
  12. sddl := "D:P(A;;GA;;;BA)(A;;GA;;;SY)"
  13. c := winio.PipeConfig{
  14. SecurityDescriptor: sddl,
  15. MessageMode: true, // Use message mode so that CloseWrite() is supported
  16. InputBufferSize: 65536, // Use 64KB buffers to improve performance
  17. OutputBufferSize: 65536,
  18. }
  19. // on windows, our socket is actually a named pipe
  20. return winio.ListenPipe(socket, &c)
  21. }
  22. // DialTimeoutLocal is a DialTimeout function for local sockets
  23. func DialTimeoutLocal(socket string, timeout time.Duration) (net.Conn, error) {
  24. // On windows, we dial a named pipe
  25. return winio.DialPipe(socket, &timeout)
  26. }