gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

transport_tcp.go (797B)


      1 package dbus
      2 
      3 import (
      4 	"errors"
      5 	"net"
      6 )
      7 
      8 func init() {
      9 	transports["tcp"] = newTcpTransport
     10 }
     11 
     12 func tcpFamily(keys string) (string, error) {
     13 	switch getKey(keys, "family") {
     14 	case "":
     15 		return "tcp", nil
     16 	case "ipv4":
     17 		return "tcp4", nil
     18 	case "ipv6":
     19 		return "tcp6", nil
     20 	default:
     21 		return "", errors.New("dbus: invalid tcp family (must be ipv4 or ipv6)")
     22 	}
     23 }
     24 
     25 func newTcpTransport(keys string) (transport, error) {
     26 	host := getKey(keys, "host")
     27 	port := getKey(keys, "port")
     28 	if host == "" || port == "" {
     29 		return nil, errors.New("dbus: unsupported address (must set host and port)")
     30 	}
     31 
     32 	protocol, err := tcpFamily(keys)
     33 	if err != nil {
     34 		return nil, err
     35 	}
     36 	socket, err := net.Dial(protocol, net.JoinHostPort(host, port))
     37 	if err != nil {
     38 		return nil, err
     39 	}
     40 	return NewConn(socket)
     41 }