mirror of https://bitbucket.org/ausocean/av.git
Replaced Unix sockets with IPConn. Sock_XXX funtions have been left as is for PR readability.
This commit is contained in:
parent
38998ab848
commit
04d7540b34
|
@ -139,7 +139,8 @@ type C_RTMPPacket struct {
|
|||
// typedef struct RTMPSockBuf
|
||||
// rtmp.h +127
|
||||
type C_RTMPSockBuf struct {
|
||||
conn *net.TCPConn
|
||||
conn *net.IPConn
|
||||
timeout int32
|
||||
sb_size int
|
||||
sb_start int
|
||||
sb_buf [RTMP_BUFFER_CACHE_SIZE]byte // port const
|
||||
|
|
|
@ -37,8 +37,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"time"
|
||||
)
|
||||
|
||||
// int RTMP_Connect(RTMP *r, RTMPPacket* cp);
|
||||
|
@ -54,11 +53,11 @@ func C_RTMP_Connect(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
|
|||
} else {
|
||||
hostname = fmt.Sprintf("%s:%d", r.Link.hostname, r.Link.port)
|
||||
}
|
||||
addr, err := net.ResolveTCPAddr("tcp4", hostname)
|
||||
addr, err := net.ResolveIPAddr("tcp4", hostname)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
r.m_sb.conn, err = net.DialTCP("tcp4", nil, addr)
|
||||
r.m_sb.conn, err = net.DialIP("tcp4", nil, addr)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
@ -68,25 +67,14 @@ func C_RTMP_Connect(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
|
|||
}
|
||||
}
|
||||
|
||||
f, err := r.m_sb.conn.File()
|
||||
if err != nil {
|
||||
log.Printf("failed to get fd to set timeout: %v", err)
|
||||
return false
|
||||
}
|
||||
tv := setTimeval(int(r.Link.timeout))
|
||||
err = unix.SetsockoptTimeval(int(f.Fd()), unix.SOL_SOCKET, unix.SO_RCVTIMEO, &tv)
|
||||
if err != nil {
|
||||
log.Printf("failed to set timeout: %v", err)
|
||||
}
|
||||
|
||||
r.m_sb.timeout= r.Link.timeout
|
||||
r.m_bSendCounter = true
|
||||
|
||||
return C_RTMP_Connect1(r, cp)
|
||||
}
|
||||
|
||||
// int SocksNegotiate(RTMP* r);
|
||||
// rtmp.c +1062
|
||||
func C_SocksNegotiate(r *C_RTMP, addr *net.TCPAddr) (ok bool) {
|
||||
func C_SocksNegotiate(r *C_RTMP, addr *net.IPAddr) (ok bool) {
|
||||
ip := addr.IP.To4()
|
||||
packet := []byte{
|
||||
0x4, // SOCKS version
|
||||
|
@ -116,7 +104,10 @@ func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int {
|
|||
if sb.sb_size == 0 {
|
||||
sb.sb_start = 0
|
||||
}
|
||||
|
||||
err := sb.conn.SetReadDeadline(time.Now().Local().Add(time.Second * time.Duration(sb.timeout)))
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
n, err := sb.conn.Read(sb.sb_buf[sb.sb_start+sb.sb_size:])
|
||||
if err != nil {
|
||||
return 0
|
||||
|
@ -129,6 +120,10 @@ func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int {
|
|||
// rtmp.c +4297
|
||||
// TODO replace send with golang net connection send
|
||||
func C_RTMPSockBuf_Send(sb *C_RTMPSockBuf, buf []byte) int32 {
|
||||
err := sb.conn.SetWriteDeadline(time.Now().Local().Add(time.Second * time.Duration(sb.timeout)))
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
n, err := sb.conn.Write(buf)
|
||||
if err != nil {
|
||||
return -1
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package rtmp
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
func setTimeval(sec int) unix.Timeval {
|
||||
return unix.Timeval{Sec: int64(sec)}
|
||||
}
|
Loading…
Reference in New Issue