listen.go 754 B

1234567891011121314151617181920212223242526
  1. // Copyright (c) 2016 Arista Networks, Inc.
  2. // Use of this source code is governed by the Apache License 2.0
  3. // that can be found in the COPYING file.
  4. // Package dscp provides helper functions to apply DSCP / ECN / CoS flags to sockets.
  5. package dscp
  6. import (
  7. "net"
  8. )
  9. // ListenTCPWithTOS is similar to net.ListenTCP but with the socket configured
  10. // to the use the given ToS (Type of Service), to specify DSCP / ECN / class
  11. // of service flags to use for incoming connections.
  12. func ListenTCPWithTOS(address *net.TCPAddr, tos byte) (*net.TCPListener, error) {
  13. lsnr, err := net.ListenTCP("tcp", address)
  14. if err != nil {
  15. return nil, err
  16. }
  17. if err = setTOS(address.IP, lsnr, tos); err != nil {
  18. lsnr.Close()
  19. return nil, err
  20. }
  21. return lsnr, err
  22. }