1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Merge remote-tracking branch 'upstream/feature/rtc' into sdp

This commit is contained in:
xiaozhihong 2020-03-30 15:16:44 +08:00
commit 9dadcdffd6
45 changed files with 740 additions and 198 deletions

View file

@ -198,19 +198,32 @@ srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq)
srs_error_t err = srs_success;
SrsStSocket skt;
if ((err = skt.initialize(stfd)) != srs_success) {
return srs_error_wrap(err, "init socket");
}
if ((err = parser->parse_message(&skt, preq)) != srs_success) {
return srs_error_wrap(err, "parse message");
// Check user interrupt by interval.
skt.set_recv_timeout(3 * SRS_UTIME_SECONDS);
// drop all request body.
char body[4096];
while (true) {
if ((err = trd->pull()) != srs_success) {
return srs_error_wrap(err, "timeout");
}
if ((err = skt.read(body, 4096, NULL)) != srs_success) {
// Because we use timeout to check trd state, so we should ignore any timeout.
if (srs_error_code(err) == ERROR_SOCKET_TIMEOUT) {
srs_freep(err);
continue;
}
return srs_error_wrap(err, "read response");
}
}
// Attach owner connection to message.
SrsHttpMessage* hreq = (SrsHttpMessage*)(*preq);
hreq->set_connection(this);
return err;
}
@ -219,12 +232,12 @@ srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg)
srs_error_t err = srs_success;
ISrsHttpResponseReader* br = msg->body_reader();
// when not specified the content length, ignore.
if (msg->content_length() == -1) {
return err;
}
// drop all request body.
char body[4096];
while (!br->eof()) {
@ -236,6 +249,11 @@ srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg)
return err;
}
void SrsResponseOnlyHttpConn::expire()
{
SrsHttpConn::expire();
}
SrsHttpServer::SrsHttpServer(SrsServer* svr)
{
server = svr;

View file

@ -101,6 +101,9 @@ public:
virtual srs_error_t pop_message(ISrsHttpMessage** preq);
public:
virtual srs_error_t on_got_http_message(ISrsHttpMessage* msg);
public:
// Set connection to expired.
virtual void expire();
};
// The http server, use http stream or static server to serve requests.

View file

@ -593,10 +593,15 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
SrsAutoFree(SrsPithyPrint, pprint);
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
// Use receive thread to accept the close event to avoid FD leak.
// @see https://github.com/ossrs/srs/issues/636#issuecomment-298208427
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
SrsResponseOnlyHttpConn* hc = dynamic_cast<SrsResponseOnlyHttpConn*>(hr->connection());
// update the statistic when source disconveried.
SrsStatistic* stat = SrsStatistic::instance();
if ((err = stat->on_client(_srs_context->get_id(), req, NULL, SrsRtmpConnPlay)) != srs_success) {
if ((err = stat->on_client(_srs_context->get_id(), req, hc, SrsRtmpConnPlay)) != srs_success) {
return srs_error_wrap(err, "stat on client");
}
@ -614,11 +619,6 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
}
SrsFlvStreamEncoder* ffe = dynamic_cast<SrsFlvStreamEncoder*>(enc);
// Use receive thread to accept the close event to avoid FD leak.
// @see https://github.com/ossrs/srs/issues/636#issuecomment-298208427
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
SrsResponseOnlyHttpConn* hc = dynamic_cast<SrsResponseOnlyHttpConn*>(hr->connection());
// Set the socket options for transport.
bool tcp_nodelay = _srs_config->get_tcp_nodelay(req->vhost);

View file

@ -659,6 +659,13 @@ srs_error_t SrsRtcSession::check_source()
return err;
}
#ifdef SRS_AUTO_OSX
// These functions are similar to the older byteorder(3) family of functions.
// For example, be32toh() is identical to ntohl().
// @see https://linux.die.net/man/3/be32toh
#define be32toh ntohl
#endif
srs_error_t SrsRtcSession::on_binding_request(SrsUdpMuxSocket* udp_mux_skt, SrsStunPacket* stun_req)
{
srs_error_t err = srs_success;

View file

@ -30,7 +30,9 @@
#include <fcntl.h>
#include <unistd.h>
#include <algorithm>
#ifndef SRS_AUTO_OSX
#include <sys/inotify.h>
#endif
using namespace std;
#include <srs_kernel_log.hpp>
@ -481,6 +483,7 @@ srs_error_t SrsInotifyWorker::start()
{
srs_error_t err = srs_success;
#ifndef SRS_AUTO_OSX
// Whether enable auto reload config.
bool auto_reload = _srs_config->inotify_auto_reload();
if (!auto_reload && _srs_in_docker && _srs_config->auto_reload_for_docker()) {
@ -551,6 +554,7 @@ srs_error_t SrsInotifyWorker::start()
if ((err = trd->start()) != srs_success) {
return srs_error_wrap(err, "inotify");
}
#endif
return err;
}
@ -559,6 +563,7 @@ srs_error_t SrsInotifyWorker::cycle()
{
srs_error_t err = srs_success;
#ifndef SRS_AUTO_OSX
string config_path = _srs_config->config();
string config_file = srs_path_basename(config_path);
string k8s_file = "..data";
@ -598,6 +603,7 @@ srs_error_t SrsInotifyWorker::cycle()
srs_usleep(3000 * SRS_UTIME_MILLISECONDS);
}
#endif
return err;
}
@ -761,7 +767,7 @@ srs_error_t SrsServer::initialize(ISrsServerCycle* ch)
srs_error_t SrsServer::initialize_st()
{
srs_error_t err = srs_success;
// @remark, st alloc segment use mmap, which only support 32757 threads,
// if need to support more, for instance, 100k threads, define the macro MALLOC_STACK.
// TODO: FIXME: maybe can use "sysctl vm.max_map_count" to refine.

View file

@ -35,6 +35,9 @@
#include <sys/time.h>
#include <math.h>
#include <map>
#ifdef SRS_AUTO_OSX
#include <sys/sysctl.h>
#endif
using namespace std;
#include <srs_kernel_log.hpp>
@ -326,6 +329,7 @@ SrsProcSystemStat* srs_get_system_proc_stat()
bool get_proc_system_stat(SrsProcSystemStat& r)
{
#ifndef SRS_AUTO_OSX
FILE* f = fopen("/proc/stat", "r");
if (f == NULL) {
srs_warn("open system cpu stat failed, ignore");
@ -355,6 +359,7 @@ bool get_proc_system_stat(SrsProcSystemStat& r)
}
fclose(f);
#endif
r.ok = true;
@ -363,6 +368,7 @@ bool get_proc_system_stat(SrsProcSystemStat& r)
bool get_proc_self_stat(SrsProcSelfStat& r)
{
#ifndef SRS_AUTO_OSX
FILE* f = fopen("/proc/self/stat", "r");
if (f == NULL) {
srs_warn("open self cpu stat failed, ignore");
@ -389,6 +395,7 @@ bool get_proc_self_stat(SrsProcSelfStat& r)
&r.guest_time, &r.cguest_time);
fclose(f);
#endif
r.ok = true;
@ -484,6 +491,7 @@ SrsDiskStat* srs_get_disk_stat()
bool srs_get_disk_vmstat_stat(SrsDiskStat& r)
{
#ifndef SRS_AUTO_OSX
FILE* f = fopen("/proc/vmstat", "r");
if (f == NULL) {
srs_warn("open vmstat failed, ignore");
@ -503,6 +511,7 @@ bool srs_get_disk_vmstat_stat(SrsDiskStat& r)
}
fclose(f);
#endif
r.ok = true;
@ -513,13 +522,14 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
{
r.ok = true;
r.sample_time = srsu2ms(srs_get_system_time());
#ifndef SRS_AUTO_OSX
// if disabled, ignore all devices.
SrsConfDirective* conf = _srs_config->get_stats_disk_device();
if (conf == NULL) {
return true;
}
FILE* f = fopen("/proc/diskstats", "r");
if (f == NULL) {
srs_warn("open vmstat failed, ignore");
@ -584,6 +594,7 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
}
fclose(f);
#endif
r.ok = true;
@ -675,7 +686,8 @@ SrsMemInfo* srs_get_meminfo()
void srs_update_meminfo()
{
SrsMemInfo& r = _srs_system_meminfo;
#ifndef SRS_AUTO_OSX
FILE* f = fopen("/proc/meminfo", "r");
if (f == NULL) {
srs_warn("open meminfo failed, ignore");
@ -701,6 +713,7 @@ void srs_update_meminfo()
}
fclose(f);
#endif
r.sample_time = srsu2ms(srs_get_system_time());
r.MemActive = r.MemTotal - r.MemFree;
@ -767,7 +780,8 @@ void srs_update_platform_info()
SrsPlatformInfo& r = _srs_system_platform_info;
r.srs_startup_time = srsu2ms(srs_get_system_startup_time());
#ifndef SRS_AUTO_OSX
if (true) {
FILE* f = fopen("/proc/uptime", "r");
if (f == NULL) {
@ -796,7 +810,44 @@ void srs_update_platform_info()
fclose(f);
}
#else
// man 3 sysctl
if (true) {
struct timeval tv;
size_t len = sizeof(timeval);
int mib[2];
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
if (sysctl(mib, 2, &tv, &len, NULL, 0) < 0) {
srs_warn("sysctl boottime failed, ignore");
return;
}
time_t bsec = tv.tv_sec;
time_t csec = ::time(NULL);
r.os_uptime = difftime(csec, bsec);
}
// man 3 sysctl
if (true) {
struct loadavg la;
size_t len = sizeof(loadavg);
int mib[2];
mib[0] = CTL_VM;
mib[1] = VM_LOADAVG;
if (sysctl(mib, 2, &la, &len, NULL, 0) < 0) {
srs_warn("sysctl loadavg failed, ignore");
return;
}
r.load_one_minutes = (double)la.ldavg[0] / la.fscale;
r.load_five_minutes = (double)la.ldavg[1] / la.fscale;
r.load_fifteen_minutes = (double)la.ldavg[2] / la.fscale;
}
#endif
r.ok = true;
}
@ -842,6 +893,7 @@ int srs_get_network_devices_count()
void srs_update_network_devices()
{
#ifndef SRS_AUTO_OSX
if (true) {
FILE* f = fopen("/proc/net/dev", "r");
if (f == NULL) {
@ -878,6 +930,7 @@ void srs_update_network_devices()
fclose(f);
}
#endif
}
SrsNetworkRtmpServer::SrsNetworkRtmpServer()
@ -924,7 +977,8 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
int nb_tcp_total = 0;
int nb_tcp_mem = 0;
int nb_udp4 = 0;
#ifndef SRS_AUTO_OSX
if (true) {
FILE* f = fopen("/proc/net/sockstat", "r");
if (f == NULL) {
@ -954,9 +1008,20 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
fclose(f);
}
#else
// TODO: FIXME: impelments it.
nb_socks = 0;
nb_tcp4_hashed = 0;
nb_tcp_orphans = 0;
nb_tcp_tws = 0;
nb_tcp_total = 0;
nb_tcp_mem = 0;
nb_udp4 = 0;
#endif
int nb_tcp_estab = 0;
#ifndef SRS_AUTO_OSX
if (true) {
FILE* f = fopen("/proc/net/snmp", "r");
if (f == NULL) {
@ -986,6 +1051,7 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
fclose(f);
}
#endif
// @see: https://github.com/shemminger/iproute2/blob/master/misc/ss.c
// TODO: FIXME: ignore the slabstat, @see: get_slabstat()