提交 d8305410 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

SctpAssociation.cpp: Initialize this->socket in the constructor (fixes #348)

上级 22346bdb
...@@ -96,37 +96,6 @@ namespace RTC ...@@ -96,37 +96,6 @@ namespace RTC
// Register ourselves in usrsctp. // Register ourselves in usrsctp.
usrsctp_register_address(static_cast<void*>(this)); usrsctp_register_address(static_cast<void*>(this));
DepUsrSCTP::IncreaseSctpAssociations();
}
SctpAssociation::~SctpAssociation()
{
MS_TRACE();
if (this->socket)
{
usrsctp_set_ulpinfo(this->socket, nullptr);
usrsctp_close(this->socket);
}
// Deregister ourselves from usrsctp.
usrsctp_deregister_address(static_cast<void*>(this));
DepUsrSCTP::DecreaseSctpAssociations();
delete[] this->messageBuffer;
}
void SctpAssociation::TransportConnected()
{
MS_TRACE();
// Just run the SCTP stack if our state is 'new'.
if (this->state != SctpState::NEW)
return;
try
{
int ret; int ret;
this->socket = usrsctp_socket( this->socket = usrsctp_socket(
...@@ -166,8 +135,9 @@ namespace RTC ...@@ -166,8 +135,9 @@ namespace RTC
ret = usrsctp_setsockopt(this->socket, IPPROTO_SCTP, SCTP_ENABLE_STREAM_RESET, &av, sizeof(av)); ret = usrsctp_setsockopt(this->socket, IPPROTO_SCTP, SCTP_ENABLE_STREAM_RESET, &av, sizeof(av));
if (ret < 0) if (ret < 0)
MS_THROW_ERROR( {
"usrsctp_setsockopt(SCTP_ENABLE_STREAM_RESET) failed: %s", std::strerror(errno)); MS_THROW_ERROR("usrsctp_setsockopt(SCTP_ENABLE_STREAM_RESET) failed: %s", std::strerror(errno));
}
// Set SCTP_NODELAY. // Set SCTP_NODELAY.
uint32_t noDelay = 1; uint32_t noDelay = 1;
...@@ -221,7 +191,35 @@ namespace RTC ...@@ -221,7 +191,35 @@ namespace RTC
if (ret < 0) if (ret < 0)
MS_THROW_ERROR("usrsctp_bind() failed: %s", std::strerror(errno)); MS_THROW_ERROR("usrsctp_bind() failed: %s", std::strerror(errno));
// Client side. DepUsrSCTP::IncreaseSctpAssociations();
}
SctpAssociation::~SctpAssociation()
{
MS_TRACE();
usrsctp_set_ulpinfo(this->socket, nullptr);
usrsctp_close(this->socket);
// Deregister ourselves from usrsctp.
usrsctp_deregister_address(static_cast<void*>(this));
DepUsrSCTP::DecreaseSctpAssociations();
delete[] this->messageBuffer;
}
void SctpAssociation::TransportConnected()
{
MS_TRACE();
// Just run the SCTP stack if our state is 'new'.
if (this->state != SctpState::NEW)
return;
try
{
int ret;
struct sockaddr_conn rconn; // NOLINT(cppcoreguidelines-pro-type-member-init) struct sockaddr_conn rconn; // NOLINT(cppcoreguidelines-pro-type-member-init)
std::memset(&rconn, 0, sizeof(rconn)); std::memset(&rconn, 0, sizeof(rconn));
......
...@@ -107,6 +107,7 @@ namespace RTC ...@@ -107,6 +107,7 @@ namespace RTC
if (jsonIsDataChannelIt != data.end() && jsonIsDataChannelIt->is_boolean()) if (jsonIsDataChannelIt != data.end() && jsonIsDataChannelIt->is_boolean())
isDataChannel = jsonIsDataChannelIt->get<bool>(); isDataChannel = jsonIsDataChannelIt->get<bool>();
// This may throw.
this->sctpAssociation = this->sctpAssociation =
new RTC::SctpAssociation(this, os, mis, maxSctpMessageSize, isDataChannel); new RTC::SctpAssociation(this, os, mis, maxSctpMessageSize, isDataChannel);
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论