sockopt_darwin.go 1.3 KB

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