Capstan is a Golang web framework that shares some similarities with others in its segment.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
662B

  1. // +build !windows
  2. package capstan
  3. import (
  4. "fmt"
  5. "syscall"
  6. )
  7. // Duplicate the file descriptor underlying `conn`. This is called by the parent
  8. // process following Relaunch to ensure that client failures don't close the
  9. // parent's descriptors.
  10. func duplicate(conn syscall.Conn) (uintptr, error) {
  11. var errno syscall.Errno
  12. var dupfd uintptr
  13. raw, err := conn.SyscallConn()
  14. if err != nil {
  15. return 0, err
  16. }
  17. err = raw.Control(func(fd uintptr) {
  18. dupfd, _, errno = syscall.Syscall(syscall.SYS_FCNTL, fd, syscall.F_DUPFD, 0)
  19. })
  20. if err != nil {
  21. return 0, err
  22. }
  23. if errno != 0 {
  24. return dupfd, fmt.Errorf("errno: %v", errno)
  25. }
  26. return dupfd, nil
  27. }