sockopt_darwin.go 1.4 KB

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