udp_windows.go 965 B

12345678910111213141516171819202122232425262728293031323334
  1. // +build windows
  2. package dns
  3. import "net"
  4. type SessionUDP struct {
  5. raddr *net.UDPAddr
  6. }
  7. // ReadFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a
  8. // net.UDPAddr.
  9. func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *SessionUDP, error) {
  10. n, raddr, err := conn.ReadFrom(b)
  11. if err != nil {
  12. return n, nil, err
  13. }
  14. session := &SessionUDP{raddr.(*net.UDPAddr)}
  15. return n, session, err
  16. }
  17. // WriteToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *SessionUDP instead of a net.Addr.
  18. func WriteToSessionUDP(conn *net.UDPConn, b []byte, session *SessionUDP) (int, error) {
  19. n, err := conn.WriteTo(b, session.raddr)
  20. return n, err
  21. }
  22. func (s *SessionUDP) RemoteAddr() net.Addr { return s.raddr }
  23. // setUDPSocketOptions sets the UDP socket options.
  24. // This function is implemented on a per platform basis. See udp_*.go for more details
  25. func setUDPSocketOptions(conn *net.UDPConn) error {
  26. return nil
  27. }