sockopt_darwin.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package internet
  2. import (
  3. "syscall"
  4. "v2ray.com/core/common/net"
  5. )
  6. const (
  7. TCP_FASTOPEN = 0x105
  8. TCP_FASTOPEN_SERVER = 0x01
  9. TCP_FASTOPEN_CLIENT = 0x02
  10. )
  11. func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
  12. if isTCPSocket(network) {
  13. switch config.Tfo {
  14. case SocketConfig_Enable:
  15. if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, TCP_FASTOPEN_CLIENT); err != nil {
  16. return err
  17. }
  18. case SocketConfig_Disable:
  19. if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil {
  20. return err
  21. }
  22. }
  23. }
  24. return nil
  25. }
  26. func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
  27. if isTCPSocket(network) {
  28. switch config.Tfo {
  29. case SocketConfig_Enable:
  30. if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, TCP_FASTOPEN_SERVER); err != nil {
  31. return err
  32. }
  33. case SocketConfig_Disable:
  34. if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil {
  35. return err
  36. }
  37. }
  38. }
  39. return nil
  40. }
  41. func bindAddr(fd uintptr, address net.Address, port net.Port) error {
  42. return nil
  43. }