1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/3rdparty/srs-bench/vendor/github.com/haivision/srtgo/read.go
Winlin 1f9309ae25
SmartPtr: Support load test for source by srs-bench. v6.0.130 (#4097)
1. Add live benchmark support in srs-bench, which only connects and
disconnects without any media transport, to test source creation and
disposal and verify source memory leaks.
2. SmartPtr: Support cleanup of HTTP-FLV stream. Unregister the HTTP-FLV
handler for the pattern and clean up the objects and resources.
3. Support benchmarking RTMP/SRT with srs-bench by integrating the gosrt
and oryx RTMP libraries.
4. Refine SRT and RTC sources by using a timer to clean up the sources,
following the same strategy as the Live source.

---------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: Jacob Su <suzp1984@gmail.com>
2024-06-21 07:13:12 +08:00

54 lines
1.1 KiB
Go

package srtgo
/*
#cgo LDFLAGS: -lsrt
#include <srt/srt.h>
int srt_recvmsg2_wrapped(SRTSOCKET u, char* buf, int len, SRT_MSGCTRL *mctrl, int *srterror, int *syserror)
{
int ret = srt_recvmsg2(u, buf, len, mctrl);
if (ret < 0) {
*srterror = srt_getlasterror(syserror);
}
return ret;
}
*/
import "C"
import (
"errors"
"syscall"
"unsafe"
)
func srtRecvMsg2Impl(u C.SRTSOCKET, buf []byte, msgctrl *C.SRT_MSGCTRL) (n int, err error) {
srterr := C.int(0)
syserr := C.int(0)
n = int(C.srt_recvmsg2_wrapped(u, (*C.char)(unsafe.Pointer(&buf[0])), C.int(len(buf)), msgctrl, &srterr, &syserr))
if n < 0 {
srterror := SRTErrno(srterr)
if syserr < 0 {
srterror.wrapSysErr(syscall.Errno(syserr))
}
err = srterror
n = 0
}
return
}
// Read data from the SRT socket
func (s SrtSocket) Read(b []byte) (n int, err error) {
//Fastpath
if !s.blocking {
s.pd.reset(ModeRead)
}
n, err = srtRecvMsg2Impl(s.socket, b, nil)
for {
if !errors.Is(err, error(EAsyncRCV)) || s.blocking {
return
}
s.pd.wait(ModeRead)
n, err = srtRecvMsg2Impl(s.socket, b, nil)
}
}