Пример #1
0
func (s *UTPSocket) Connect(addr *UTPAddr) (int, error) {
	// func (s *UTPSocket) Connect(to *syscall.RawSockaddr, tolen int) int {

	if addr == nil {
		return 0, net.InvalidAddrError("No address given.")
	}

	sa, err := addr.Sockaddr()
	if err != nil {
		return 0, err
	}

	rsa, err := sockaddr.NewRawSockaddr(&sa)
	if err != nil {
		return 0, err
	}

	ptr := (*C.struct_sockaddr)(unsafe.Pointer(&rsa.Raw))
	ret := int(C.utp_connect(s.raw, ptr, C.socklen_t(rsa.Len)))
	return ret, nil
}
Пример #2
0
//UtpConnect starts to connect
func (s *UtpSocket) UtpConnect(addr *net.UDPAddr) int64 {
	addrinfo := C.getAddrInfo(C.CString(addr.IP.String()), (C.int)(addr.Port))
	size := C.utp_connect(s.s, addrinfo.ai_addr, (C.socklen_t)(addrinfo.ai_addrlen))
	C.freeaddrinfo(addrinfo)
	return (int64)(size)
}