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

C++ clean up: Make destuctor private for those classes that must be explicitely…

C++ clean up: Make destuctor private for those classes that must be explicitely "destroyed" via a Destroy() method.
上级 de1b7ecd
...@@ -12,9 +12,6 @@ namespace Channel ...@@ -12,9 +12,6 @@ namespace Channel
{ {
public: public:
explicit Notifier(Channel::UnixStreamSocket* channel); explicit Notifier(Channel::UnixStreamSocket* channel);
virtual ~Notifier();
void Close();
void Emit(uint32_t targetId, std::string event); void Emit(uint32_t targetId, std::string event);
void Emit(uint32_t targetId, std::string event, Json::Value& data); void Emit(uint32_t targetId, std::string event, Json::Value& data);
......
...@@ -24,8 +24,11 @@ namespace Channel ...@@ -24,8 +24,11 @@ namespace Channel
public: public:
explicit UnixStreamSocket(int fd); explicit UnixStreamSocket(int fd);
private:
virtual ~UnixStreamSocket(); virtual ~UnixStreamSocket();
public:
void SetListener(Listener* listener); void SetListener(Listener* listener);
void Send(Json::Value &json); void Send(Json::Value &json);
void SendLog(char* ns_payload, size_t ns_payload_len); void SendLog(char* ns_payload, size_t ns_payload_len);
......
...@@ -76,16 +76,16 @@ namespace RTC ...@@ -76,16 +76,16 @@ namespace RTC
virtual void onDtlsConnected(DtlsTransport* dtlsTransport, RTC::SrtpSession::Profile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len, std::string& remoteCert) = 0; virtual void onDtlsConnected(DtlsTransport* dtlsTransport, RTC::SrtpSession::Profile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len, std::string& remoteCert) = 0;
// The DTLS connection has been closed as the result of an error (such as a // The DTLS connection has been closed as the result of an error (such as a
// DTLS alert or a failure to validate the remote fingerprint). // DTLS alert or a failure to validate the remote fingerprint).
// NOTE: The caller MUST NOT call Close() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void onDtlsFailed(DtlsTransport* dtlsTransport) = 0; virtual void onDtlsFailed(DtlsTransport* dtlsTransport) = 0;
// The DTLS connection has been closed due to receipt of a close_notify alert. // The DTLS connection has been closed due to receipt of a close_notify alert.
// NOTE: The caller MUST NOT call Close() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void onDtlsClosed(DtlsTransport* dtlsTransport) = 0; virtual void onDtlsClosed(DtlsTransport* dtlsTransport) = 0;
// Need to send DTLS data to the peer. // Need to send DTLS data to the peer.
// NOTE: The caller MUST NOT call Close() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void onOutgoingDtlsData(DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; virtual void onOutgoingDtlsData(DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0;
// DTLS application data received. // DTLS application data received.
// NOTE: The caller MUST NOT call Close() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void onDtlsApplicationData(DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; virtual void onDtlsApplicationData(DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0;
}; };
...@@ -115,9 +115,12 @@ namespace RTC ...@@ -115,9 +115,12 @@ namespace RTC
public: public:
explicit DtlsTransport(Listener* listener); explicit DtlsTransport(Listener* listener);
private:
virtual ~DtlsTransport(); virtual ~DtlsTransport();
void Close(); public:
void Destroy();
void Dump() const; void Dump() const;
void Run(Role localRole); void Run(Role localRole);
void SetRemoteFingerprint(Fingerprint fingerprint); void SetRemoteFingerprint(Fingerprint fingerprint);
......
...@@ -44,7 +44,7 @@ namespace RTC ...@@ -44,7 +44,7 @@ namespace RTC
public: public:
IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password); IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password);
void Close(); void Destroy();
void ProcessStunMessage(RTC::StunMessage* msg, RTC::TransportTuple* tuple); void ProcessStunMessage(RTC::StunMessage* msg, RTC::TransportTuple* tuple);
const std::string& GetUsernameFragment() const; const std::string& GetUsernameFragment() const;
const std::string& GetPassword() const; const std::string& GetPassword() const;
......
...@@ -47,9 +47,12 @@ namespace RTC ...@@ -47,9 +47,12 @@ namespace RTC
public: public:
Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName); Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName);
private:
virtual ~Peer(); virtual ~Peer();
void Close(); public:
void Destroy();
Json::Value toJson() const; Json::Value toJson() const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
bool HasCapabilities() const; bool HasCapabilities() const;
......
...@@ -39,9 +39,12 @@ namespace RTC ...@@ -39,9 +39,12 @@ namespace RTC
public: public:
Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data); Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data);
private:
virtual ~Room(); virtual ~Room();
void Close(); public:
void Destroy();
Json::Value toJson() const; Json::Value toJson() const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
const RTC::RtpCapabilities& GetCapabilities() const; const RTC::RtpCapabilities& GetCapabilities() const;
......
...@@ -41,9 +41,12 @@ namespace RTC ...@@ -41,9 +41,12 @@ namespace RTC
public: public:
RtpReceiver(Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind); RtpReceiver(Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind);
private:
virtual ~RtpReceiver(); virtual ~RtpReceiver();
void Close(); public:
void Destroy();
Json::Value toJson() const; Json::Value toJson() const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
void SetTransport(RTC::Transport* transport); void SetTransport(RTC::Transport* transport);
......
...@@ -31,25 +31,18 @@ namespace RTC ...@@ -31,25 +31,18 @@ namespace RTC
virtual void onRtpSenderClosed(RtpSender* rtpSender) = 0; virtual void onRtpSenderClosed(RtpSender* rtpSender) = 0;
}; };
// NOTE: Comment for now.
// private:
// struct Data
// {
// std::string muxId;
// RTC::RtpCodecMime mediaMime;
// uint32_t mediaSsrc = 0;
// // TODO: Add much more and move supportedPayloadTypes here.
// };
private: private:
// Container of RTP packets to retransmit. // Container of RTP packets to retransmit.
static std::vector<RTC::RtpPacket*> rtpRetransmissionContainer; static std::vector<RTC::RtpPacket*> rtpRetransmissionContainer;
public: public:
RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind); RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind);
private:
virtual ~RtpSender(); virtual ~RtpSender();
void Close(); public:
void Destroy();
Json::Value toJson() const; Json::Value toJson() const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
void SetPeerCapabilities(RTC::RtpCapabilities* peerCapabilities); void SetPeerCapabilities(RTC::RtpCapabilities* peerCapabilities);
......
...@@ -34,9 +34,12 @@ namespace RTC ...@@ -34,9 +34,12 @@ namespace RTC
public: public:
SrtpSession(Type type, Profile profile, uint8_t* key, size_t key_len); SrtpSession(Type type, Profile profile, uint8_t* key, size_t key_len);
private:
~SrtpSession(); ~SrtpSession();
void Close(); public:
void Destroy();
bool EncryptRtp(const uint8_t** data, size_t* len); bool EncryptRtp(const uint8_t** data, size_t* len);
bool DecryptSrtp(const uint8_t* data, size_t* len); bool DecryptSrtp(const uint8_t* data, size_t* len);
bool EncryptRtcp(const uint8_t** data, size_t* len); bool EncryptRtcp(const uint8_t** data, size_t* len);
......
...@@ -18,8 +18,11 @@ namespace RTC ...@@ -18,8 +18,11 @@ namespace RTC
public: public:
TcpConnection(Listener* listener, size_t bufferSize); TcpConnection(Listener* listener, size_t bufferSize);
virtual ~TcpConnection();
private:
virtual ~TcpConnection() {};
public:
void Send(const uint8_t* data, size_t len); void Send(const uint8_t* data, size_t len);
/* Pure virtual methods inherited from ::TcpConnection. */ /* Pure virtual methods inherited from ::TcpConnection. */
......
...@@ -39,6 +39,8 @@ namespace RTC ...@@ -39,6 +39,8 @@ namespace RTC
public: public:
TcpServer(Listener* listener, RTC::TcpConnection::Listener* connListener, int address_family); TcpServer(Listener* listener, RTC::TcpConnection::Listener* connListener, int address_family);
private:
virtual ~TcpServer() {}; virtual ~TcpServer() {};
/* Pure virtual methods inherited from ::TcpServer. */ /* Pure virtual methods inherited from ::TcpServer. */
......
...@@ -46,9 +46,12 @@ namespace RTC ...@@ -46,9 +46,12 @@ namespace RTC
public: public:
Transport(Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data); Transport(Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data);
private:
virtual ~Transport(); virtual ~Transport();
void Close(); public:
void Destroy();
Json::Value toJson() const; Json::Value toJson() const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
void AddRtpReceiver(RTC::RtpReceiver* rtpReceiver); void AddRtpReceiver(RTC::RtpReceiver* rtpReceiver);
......
...@@ -22,7 +22,6 @@ namespace RTC ...@@ -22,7 +22,6 @@ namespace RTC
TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr); TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr);
explicit TransportTuple(RTC::TcpConnection* tcpConnection); explicit TransportTuple(RTC::TcpConnection* tcpConnection);
void Close();
Json::Value toJson() const; Json::Value toJson() const;
void Dump() const; void Dump() const;
void StoreUdpRemoteAddress(); void StoreUdpRemoteAddress();
...@@ -44,13 +43,6 @@ namespace RTC ...@@ -44,13 +43,6 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline
void TransportTuple::Close()
{
if (this->protocol == Protocol::TCP)
this->tcpConnection->Close();
}
inline inline
TransportTuple::TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr) : TransportTuple::TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr) :
udpSocket(udpSocket), udpSocket(udpSocket),
......
...@@ -37,6 +37,8 @@ namespace RTC ...@@ -37,6 +37,8 @@ namespace RTC
public: public:
UdpSocket(Listener* listener, int address_family); UdpSocket(Listener* listener, int address_family);
private:
virtual ~UdpSocket() {}; virtual ~UdpSocket() {};
/* Pure virtual methods inherited from ::UdpSocket. */ /* Pure virtual methods inherited from ::UdpSocket. */
......
...@@ -20,7 +20,11 @@ public: ...@@ -20,7 +20,11 @@ public:
public: public:
explicit SignalsHandler(Listener* listener); explicit SignalsHandler(Listener* listener);
void Close(); private:
~SignalsHandler() {};
public:
void Destroy();
void AddSignal(int signum, std::string name); void AddSignal(int signum, std::string name);
/* Callbacks fired by UV events. */ /* Callbacks fired by UV events. */
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#include <string> #include <string>
#include <uv.h> #include <uv.h>
// Avoid cyclic #include problem by declaring classes instead of including
// the corresponding header files.
class TcpServer;
class TcpConnection class TcpConnection
{ {
public: public:
...@@ -26,13 +30,19 @@ public: ...@@ -26,13 +30,19 @@ public:
uint8_t store[1]; uint8_t store[1];
}; };
// Let the TcpServer class directly call the destructor of TcpConnection.
friend class TcpServer;
public: public:
explicit TcpConnection(size_t bufferSize); explicit TcpConnection(size_t bufferSize);
TcpConnection& operator=(const TcpConnection&) = delete; TcpConnection& operator=(const TcpConnection&) = delete;
TcpConnection(const TcpConnection&) = delete; TcpConnection(const TcpConnection&) = delete;
protected:
virtual ~TcpConnection(); virtual ~TcpConnection();
void Close(); public:
void Destroy();
virtual void Dump() const; virtual void Dump() const;
void Setup(Listener* listener, struct sockaddr_storage* localAddr, const std::string &localIP, uint16_t localPort); void Setup(Listener* listener, struct sockaddr_storage* localAddr, const std::string &localIP, uint16_t localPort);
bool IsClosing() const; bool IsClosing() const;
......
...@@ -15,9 +15,12 @@ public: ...@@ -15,9 +15,12 @@ public:
* uvHandle must be an already initialized and binded uv_tcp_t pointer. * uvHandle must be an already initialized and binded uv_tcp_t pointer.
*/ */
TcpServer(uv_tcp_t* uvHandle, int backlog); TcpServer(uv_tcp_t* uvHandle, int backlog);
protected:
virtual ~TcpServer(); virtual ~TcpServer();
void Close(); public:
void Destroy();
virtual void Dump() const; virtual void Dump() const;
bool IsClosing() const; bool IsClosing() const;
const struct sockaddr* GetLocalAddress() const; const struct sockaddr* GetLocalAddress() const;
......
...@@ -21,7 +21,11 @@ public: ...@@ -21,7 +21,11 @@ public:
Timer& operator=(const Timer&) = delete; Timer& operator=(const Timer&) = delete;
Timer(const Timer&) = delete; Timer(const Timer&) = delete;
void Close(); private:
~Timer() {};
public:
void Destroy();
void Start(uint64_t timeout); void Start(uint64_t timeout);
void Stop(); void Stop();
......
...@@ -27,9 +27,12 @@ public: ...@@ -27,9 +27,12 @@ public:
explicit UdpSocket(uv_udp_t* uvHandle); explicit UdpSocket(uv_udp_t* uvHandle);
UdpSocket& operator=(const UdpSocket&) = delete; UdpSocket& operator=(const UdpSocket&) = delete;
UdpSocket(const UdpSocket&) = delete; UdpSocket(const UdpSocket&) = delete;
protected:
virtual ~UdpSocket(); virtual ~UdpSocket();
void Close(); public:
void Destroy();
virtual void Dump() const; virtual void Dump() const;
void Send(const uint8_t* data, size_t len, const struct sockaddr* addr); void Send(const uint8_t* data, size_t len, const struct sockaddr* addr);
void Send(const std::string &data, const struct sockaddr* addr); void Send(const std::string &data, const struct sockaddr* addr);
......
...@@ -20,9 +20,12 @@ public: ...@@ -20,9 +20,12 @@ public:
UnixStreamSocket(int fd, size_t bufferSize); UnixStreamSocket(int fd, size_t bufferSize);
UnixStreamSocket& operator=(const UnixStreamSocket&) = delete; UnixStreamSocket& operator=(const UnixStreamSocket&) = delete;
UnixStreamSocket(const UnixStreamSocket&) = delete; UnixStreamSocket(const UnixStreamSocket&) = delete;
protected:
virtual ~UnixStreamSocket(); virtual ~UnixStreamSocket();
void Close(); public:
void Destroy();
bool IsClosing() const; bool IsClosing() const;
void Write(const uint8_t* data, size_t len); void Write(const uint8_t* data, size_t len);
void Write(const std::string &data); void Write(const std::string &data);
......
...@@ -14,18 +14,6 @@ namespace Channel ...@@ -14,18 +14,6 @@ namespace Channel
MS_TRACE(); MS_TRACE();
} }
Notifier::~Notifier()
{
MS_TRACE();
}
void Notifier::Close()
{
MS_TRACE();
delete this;
}
void Notifier::Emit(uint32_t targetId, std::string event) void Notifier::Emit(uint32_t targetId, std::string event)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -56,7 +56,7 @@ void Loop::Close() ...@@ -56,7 +56,7 @@ void Loop::Close()
// Close the SignalsHandler. // Close the SignalsHandler.
if (this->signalsHandler) if (this->signalsHandler)
this->signalsHandler->Close(); this->signalsHandler->Destroy();
// Close all the Rooms. // Close all the Rooms.
// NOTE: Upon Room closure the onRoomClosed() method is called which // NOTE: Upon Room closure the onRoomClosed() method is called which
...@@ -67,15 +67,15 @@ void Loop::Close() ...@@ -67,15 +67,15 @@ void Loop::Close()
RTC::Room* room = it->second; RTC::Room* room = it->second;
it = this->rooms.erase(it); it = this->rooms.erase(it);
room->Close(); room->Destroy();
} }
// Close the Notifier. // Delete the Notifier.
this->notifier->Close(); delete this->notifier;
// Close the Channel socket. // Close the Channel socket.
if (this->channel) if (this->channel)
this->channel->Close(); this->channel->Destroy();
} }
RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, uint32_t* roomId) RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, uint32_t* roomId)
......
...@@ -541,7 +541,7 @@ namespace RTC ...@@ -541,7 +541,7 @@ namespace RTC
} }
} }
void DtlsTransport::Close() void DtlsTransport::Destroy()
{ {
MS_TRACE(); MS_TRACE();
...@@ -552,8 +552,8 @@ namespace RTC ...@@ -552,8 +552,8 @@ namespace RTC
SendPendingOutgoingDtlsData(); SendPendingOutgoingDtlsData();
} }
// Close the DTLS timer. // Destroy the DTLS timer.
this->timer->Close(); this->timer->Destroy();
delete this; delete this;
} }
......
...@@ -24,7 +24,7 @@ namespace RTC ...@@ -24,7 +24,7 @@ namespace RTC
MS_DEBUG_TAG(ice, "[usernameFragment:%s, password:%s]", this->usernameFragment.c_str(), this->password.c_str()); MS_DEBUG_TAG(ice, "[usernameFragment:%s, password:%s]", this->usernameFragment.c_str(), this->password.c_str());
} }
void IceServer::Close() void IceServer::Destroy()
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -37,11 +37,11 @@ namespace RTC ...@@ -37,11 +37,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Close the RTCP timer. // Destroy the RTCP timer.
this->timer->Close(); this->timer->Destroy();
} }
void Peer::Close() void Peer::Destroy()
{ {
MS_TRACE(); MS_TRACE();
...@@ -55,7 +55,7 @@ namespace RTC ...@@ -55,7 +55,7 @@ namespace RTC
RTC::RtpReceiver* rtpReceiver = it->second; RTC::RtpReceiver* rtpReceiver = it->second;
it = this->rtpReceivers.erase(it); it = this->rtpReceivers.erase(it);
rtpReceiver->Close(); rtpReceiver->Destroy();
} }
// Close all the RtpSenders. // Close all the RtpSenders.
...@@ -64,18 +64,18 @@ namespace RTC ...@@ -64,18 +64,18 @@ namespace RTC
RTC::RtpSender* rtpSender = it->second; RTC::RtpSender* rtpSender = it->second;
it = this->rtpSenders.erase(it); it = this->rtpSenders.erase(it);
rtpSender->Close(); rtpSender->Destroy();
} }
// Close all the Transports. // Close all the Transports.
// NOTE: It is critical to close Transports after RtpReceivers/RtpSenders // NOTE: It is critical to close Transports after RtpReceivers/RtpSenders
// because RtcReceiver.Close() fires an event in the Transport. // because RtcReceiver.Destroy() fires an event in the Transport.
for (auto it = this->transports.begin(); it != this->transports.end();) for (auto it = this->transports.begin(); it != this->transports.end();)
{ {
RTC::Transport* transport = it->second; RTC::Transport* transport = it->second;
it = this->transports.erase(it); it = this->transports.erase(it);
transport->Close(); transport->Destroy();
} }
// Notify. // Notify.
...@@ -156,7 +156,7 @@ namespace RTC ...@@ -156,7 +156,7 @@ namespace RTC
uint32_t peerId = this->peerId; uint32_t peerId = this->peerId;
#endif #endif
Close(); Destroy();
MS_DEBUG_DEV("Peer closed [peerId:%" PRIu32 "]", peerId); MS_DEBUG_DEV("Peer closed [peerId:%" PRIu32 "]", peerId);
......
...@@ -110,7 +110,7 @@ namespace RTC ...@@ -110,7 +110,7 @@ namespace RTC
MS_TRACE(); MS_TRACE();
} }
void Room::Close() void Room::Destroy()
{ {
MS_TRACE(); MS_TRACE();
...@@ -127,7 +127,7 @@ namespace RTC ...@@ -127,7 +127,7 @@ namespace RTC
RTC::Peer* peer = it->second; RTC::Peer* peer = it->second;
it = this->peers.erase(it); it = this->peers.erase(it);
peer->Close(); peer->Destroy();
} }
// Notify. // Notify.
...@@ -211,7 +211,7 @@ namespace RTC ...@@ -211,7 +211,7 @@ namespace RTC
uint32_t roomId = this->roomId; uint32_t roomId = this->roomId;
#endif #endif
Close(); Destroy();
MS_DEBUG_DEV("Room closed [roomId:%" PRIu32 "]", roomId); MS_DEBUG_DEV("Room closed [roomId:%" PRIu32 "]", roomId);
...@@ -569,7 +569,7 @@ namespace RTC ...@@ -569,7 +569,7 @@ namespace RTC
// RtpSenders associated to the closed RtpReceiver. // RtpSenders associated to the closed RtpReceiver.
if (this->mapRtpReceiverRtpSenders.find(rtpReceiver) != this->mapRtpReceiverRtpSenders.end()) if (this->mapRtpReceiverRtpSenders.find(rtpReceiver) != this->mapRtpReceiverRtpSenders.end())
{ {
// Make a copy of the set of RtpSenders given that Close() will be called // Make a copy of the set of RtpSenders given that Destroy() will be called
// in all of them, producing onPeerRtpSenderClosed() that will remove it // in all of them, producing onPeerRtpSenderClosed() that will remove it
// from the map. // from the map.
auto rtpSenders = this->mapRtpReceiverRtpSenders[rtpReceiver]; auto rtpSenders = this->mapRtpReceiverRtpSenders[rtpReceiver];
...@@ -577,7 +577,7 @@ namespace RTC ...@@ -577,7 +577,7 @@ namespace RTC
// Safely iterate the copy of the set. // Safely iterate the copy of the set.
for (auto& rtpSender : rtpSenders) for (auto& rtpSender : rtpSenders)
{ {
rtpSender->Close(); rtpSender->Destroy();
} }
// Finally delete the RtpReceiver entry in the map. // Finally delete the RtpReceiver entry in the map.
......
...@@ -41,7 +41,7 @@ namespace RTC ...@@ -41,7 +41,7 @@ namespace RTC
ClearRtpStreams(); ClearRtpStreams();
} }
void RtpReceiver::Close() void RtpReceiver::Destroy()
{ {
MS_TRACE(); MS_TRACE();
...@@ -114,7 +114,7 @@ namespace RTC ...@@ -114,7 +114,7 @@ namespace RTC
uint32_t rtpReceiverId = this->rtpReceiverId; uint32_t rtpReceiverId = this->rtpReceiverId;
#endif #endif
Close(); Destroy();
MS_DEBUG_DEV("RtpReceiver closed [rtpReceiverId:%" PRIu32 "]", rtpReceiverId); MS_DEBUG_DEV("RtpReceiver closed [rtpReceiverId:%" PRIu32 "]", rtpReceiverId);
......
...@@ -43,7 +43,7 @@ namespace RTC ...@@ -43,7 +43,7 @@ namespace RTC
delete this->rtpStream; delete this->rtpStream;
} }
void RtpSender::Close() void RtpSender::Destroy()
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -113,7 +113,7 @@ namespace RTC ...@@ -113,7 +113,7 @@ namespace RTC
} }
} }
void SrtpSession::Close() void SrtpSession::Destroy()
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -17,11 +17,6 @@ namespace RTC ...@@ -17,11 +17,6 @@ namespace RTC
MS_TRACE(); MS_TRACE();
} }
TcpConnection::~TcpConnection()
{
MS_TRACE();
}
void TcpConnection::userOnTcpConnectionRead() void TcpConnection::userOnTcpConnectionRead()
{ {
MS_TRACE(); MS_TRACE();
...@@ -50,7 +45,7 @@ namespace RTC ...@@ -50,7 +45,7 @@ namespace RTC
while (true) while (true)
{ {
// We may receive multiple packets in the same TCP chunk. If one of them is // We may receive multiple packets in the same TCP chunk. If one of them is
// a DTLS Close Alert this would be closed (Close() called) so we cannot call // a DTLS Close Alert this would be closed (Destroy() called) so we cannot call
// our listeners anymore. // our listeners anymore.
if (IsClosing()) if (IsClosing())
return; return;
...@@ -125,7 +120,7 @@ namespace RTC ...@@ -125,7 +120,7 @@ namespace RTC
MS_WARN_DEV("no more space in the buffer for the unfinished frame being parsed, closing the connection"); MS_WARN_DEV("no more space in the buffer for the unfinished frame being parsed, closing the connection");
// Close the socket. // Close the socket.
Close(); Destroy();
} }
} }
// The buffer is not full. // The buffer is not full.
......
...@@ -220,7 +220,7 @@ namespace RTC ...@@ -220,7 +220,7 @@ namespace RTC
// Allow just MAX_TCP_CONNECTIONS_PER_SERVER. // Allow just MAX_TCP_CONNECTIONS_PER_SERVER.
if (GetNumConnections() > MAX_TCP_CONNECTIONS_PER_SERVER) if (GetNumConnections() > MAX_TCP_CONNECTIONS_PER_SERVER)
connection->Close(); connection->Destroy();
} }
void TcpServer::userOnTcpConnectionClosed(::TcpConnection* connection, bool is_closed_by_peer) void TcpServer::userOnTcpConnectionClosed(::TcpConnection* connection, bool is_closed_by_peer)
......
...@@ -191,7 +191,7 @@ namespace RTC ...@@ -191,7 +191,7 @@ namespace RTC
// Ensure there is at least one IP:port binding. // Ensure there is at least one IP:port binding.
if (!this->udpSockets.size() && !this->tcpServers.size()) if (!this->udpSockets.size() && !this->tcpServers.size())
{ {
Close(); Destroy();
MS_THROW_ERROR("could not open any IP:port"); MS_THROW_ERROR("could not open any IP:port");
} }
...@@ -199,7 +199,7 @@ namespace RTC ...@@ -199,7 +199,7 @@ namespace RTC
// Create a DTLS agent. // Create a DTLS agent.
this->dtlsTransport = new RTC::DtlsTransport(this); this->dtlsTransport = new RTC::DtlsTransport(this);
// Hack to avoid that Close() above attempts to delete this. // Hack to avoid that Destroy() above attempts to delete this.
this->allocated = true; this->allocated = true;
} }
...@@ -208,7 +208,7 @@ namespace RTC ...@@ -208,7 +208,7 @@ namespace RTC
MS_TRACE(); MS_TRACE();
} }
void Transport::Close() void Transport::Destroy()
{ {
MS_TRACE(); MS_TRACE();
...@@ -217,23 +217,23 @@ namespace RTC ...@@ -217,23 +217,23 @@ namespace RTC
Json::Value event_data(Json::objectValue); Json::Value event_data(Json::objectValue);
if (this->srtpRecvSession) if (this->srtpRecvSession)
this->srtpRecvSession->Close(); this->srtpRecvSession->Destroy();
if (this->srtpSendSession) if (this->srtpSendSession)
this->srtpSendSession->Close(); this->srtpSendSession->Destroy();
if (this->dtlsTransport) if (this->dtlsTransport)
this->dtlsTransport->Close(); this->dtlsTransport->Destroy();
if (this->iceServer) if (this->iceServer)
this->iceServer->Close(); this->iceServer->Destroy();
for (auto socket : this->udpSockets) for (auto socket : this->udpSockets)
socket->Close(); socket->Destroy();
this->udpSockets.clear(); this->udpSockets.clear();
for (auto server : this->tcpServers) for (auto server : this->tcpServers)
server->Close(); server->Destroy();
this->tcpServers.clear(); this->tcpServers.clear();
this->selectedTuple = nullptr; this->selectedTuple = nullptr;
...@@ -382,7 +382,7 @@ namespace RTC ...@@ -382,7 +382,7 @@ namespace RTC
uint32_t transportId = this->transportId; uint32_t transportId = this->transportId;
#endif #endif
Close(); Destroy();
MS_DEBUG_DEV("Transport closed [transportId:%" PRIu32 "]", transportId); MS_DEBUG_DEV("Transport closed [transportId:%" PRIu32 "]", transportId);
request->Accept(); request->Accept();
...@@ -968,7 +968,7 @@ namespace RTC ...@@ -968,7 +968,7 @@ namespace RTC
this->notifier->Emit(this->transportId, "icestatechange", event_data); this->notifier->Emit(this->transportId, "icestatechange", event_data);
// This is a fatal error so close the transport. // This is a fatal error so close the transport.
Close(); Destroy();
} }
void Transport::onDtlsConnecting(RTC::DtlsTransport* dtlsTransport) void Transport::onDtlsConnecting(RTC::DtlsTransport* dtlsTransport)
...@@ -1005,12 +1005,12 @@ namespace RTC ...@@ -1005,12 +1005,12 @@ namespace RTC
// Close it if it was already set and update it. // Close it if it was already set and update it.
if (this->srtpSendSession) if (this->srtpSendSession)
{ {
this->srtpSendSession->Close(); this->srtpSendSession->Destroy();
this->srtpSendSession = nullptr; this->srtpSendSession = nullptr;
} }
if (this->srtpRecvSession) if (this->srtpRecvSession)
{ {
this->srtpRecvSession->Close(); this->srtpRecvSession->Destroy();
this->srtpRecvSession = nullptr; this->srtpRecvSession = nullptr;
} }
...@@ -1033,7 +1033,7 @@ namespace RTC ...@@ -1033,7 +1033,7 @@ namespace RTC
{ {
MS_ERROR("error creating SRTP receiving session: %s", error.what()); MS_ERROR("error creating SRTP receiving session: %s", error.what());
this->srtpSendSession->Close(); this->srtpSendSession->Destroy();
this->srtpSendSession = nullptr; this->srtpSendSession = nullptr;
} }
...@@ -1062,7 +1062,7 @@ namespace RTC ...@@ -1062,7 +1062,7 @@ namespace RTC
this->notifier->Emit(this->transportId, "dtlsstatechange", event_data); this->notifier->Emit(this->transportId, "dtlsstatechange", event_data);
// This is a fatal error so close the transport. // This is a fatal error so close the transport.
Close(); Destroy();
} }
void Transport::onDtlsClosed(RTC::DtlsTransport* dtlsTransport) void Transport::onDtlsClosed(RTC::DtlsTransport* dtlsTransport)
...@@ -1083,7 +1083,7 @@ namespace RTC ...@@ -1083,7 +1083,7 @@ namespace RTC
this->notifier->Emit(this->transportId, "dtlsstatechange", event_data); this->notifier->Emit(this->transportId, "dtlsstatechange", event_data);
// This is a fatal error so close the transport. // This is a fatal error so close the transport.
Close(); Destroy();
} }
void Transport::onOutgoingDtlsData(RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) void Transport::onOutgoingDtlsData(RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len)
......
...@@ -52,7 +52,7 @@ void SignalsHandler::AddSignal(int signum, std::string name) ...@@ -52,7 +52,7 @@ void SignalsHandler::AddSignal(int signum, std::string name)
this->uvHandles.push_back(uvHandle); this->uvHandles.push_back(uvHandle);
} }
void SignalsHandler::Close() void SignalsHandler::Destroy()
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -97,7 +97,7 @@ void TcpConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr ...@@ -97,7 +97,7 @@ void TcpConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr
this->localPort = localPort; this->localPort = localPort;
} }
void TcpConnection::Close() void TcpConnection::Destroy()
{ {
MS_TRACE(); MS_TRACE();
...@@ -195,7 +195,7 @@ void TcpConnection::Write(const uint8_t* data, size_t len) ...@@ -195,7 +195,7 @@ void TcpConnection::Write(const uint8_t* data, size_t len)
{ {
MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written)); MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written));
Close(); Destroy();
return; return;
} }
...@@ -255,7 +255,7 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data ...@@ -255,7 +255,7 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
{ {
MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written)); MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written));
Close(); Destroy();
return; return;
} }
...@@ -360,7 +360,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -360,7 +360,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
this->isClosedByPeer = true; this->isClosedByPeer = true;
// Close server side of the connection. // Close server side of the connection.
Close(); Destroy();
} }
// Some error. // Some error.
else else
...@@ -370,7 +370,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -370,7 +370,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
this->hasError = true; this->hasError = true;
// Close server side of the connection. // Close server side of the connection.
Close(); Destroy();
} }
} }
...@@ -387,7 +387,7 @@ void TcpConnection::onUvWriteError(int error) ...@@ -387,7 +387,7 @@ void TcpConnection::onUvWriteError(int error)
MS_WARN_DEV("write error, closing the connection: %s", uv_strerror(error)); MS_WARN_DEV("write error, closing the connection: %s", uv_strerror(error));
Close(); Destroy();
} }
inline inline
......
...@@ -125,7 +125,7 @@ TcpServer::~TcpServer() ...@@ -125,7 +125,7 @@ TcpServer::~TcpServer()
delete this->uvHandle; delete this->uvHandle;
} }
void TcpServer::Close() void TcpServer::Destroy()
{ {
MS_TRACE(); MS_TRACE();
...@@ -147,7 +147,7 @@ void TcpServer::Close() ...@@ -147,7 +147,7 @@ void TcpServer::Close()
for (auto it = this->connections.begin(); it != this->connections.end(); ++it) for (auto it = this->connections.begin(); it != this->connections.end(); ++it)
{ {
TcpConnection* connection = *it; TcpConnection* connection = *it;
connection->Close(); connection->Destroy();
} }
} }
} }
...@@ -232,7 +232,7 @@ void TcpServer::onUvConnection(int status) ...@@ -232,7 +232,7 @@ void TcpServer::onUvConnection(int status)
{ {
MS_ERROR("cannot run the TCP connection, closing the connection: %s", error.what()); MS_ERROR("cannot run the TCP connection, closing the connection: %s", error.what());
connection->Close(); connection->Destroy();
// NOTE: Don't return here so the user won't be notified about a TCP connection // NOTE: Don't return here so the user won't be notified about a TCP connection
// closure for which there was not a previous creation event. // closure for which there was not a previous creation event.
...@@ -261,8 +261,8 @@ void TcpServer::onTcpConnectionClosed(TcpConnection* connection, bool is_closed_ ...@@ -261,8 +261,8 @@ void TcpServer::onTcpConnectionClosed(TcpConnection* connection, bool is_closed_
// NOTE: // NOTE:
// Worst scenario is that in which this is the latest connection, // Worst scenario is that in which this is the latest connection,
// which is remotely closed (no TcpServer.Close() was called) and the user // which is remotely closed (no TcpServer.Destroy() was called) and the user
// call TcpServer.Close() on userOnTcpConnectionClosed() callback, so Close() // call TcpServer.Destroy() on userOnTcpConnectionClosed() callback, so Destroy()
// is called with zero connections and calls uv_close(), but then // is called with zero connections and calls uv_close(), but then
// onTcpConnectionClosed() continues and finds that isClosing is true and // onTcpConnectionClosed() continues and finds that isClosing is true and
// there are zero connections, so calls uv_close() again and get a crash. // there are zero connections, so calls uv_close() again and get a crash.
......
...@@ -41,7 +41,7 @@ Timer::Timer(Listener* listener) : ...@@ -41,7 +41,7 @@ Timer::Timer(Listener* listener) :
} }
} }
void Timer::Close() void Timer::Destroy()
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -151,7 +151,7 @@ UdpSocket::~UdpSocket() ...@@ -151,7 +151,7 @@ UdpSocket::~UdpSocket()
delete this->uvHandle; delete this->uvHandle;
} }
void UdpSocket::Close() void UdpSocket::Destroy()
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -107,7 +107,7 @@ UnixStreamSocket::~UnixStreamSocket() ...@@ -107,7 +107,7 @@ UnixStreamSocket::~UnixStreamSocket()
delete[] this->buffer; delete[] this->buffer;
} }
void UnixStreamSocket::Close() void UnixStreamSocket::Destroy()
{ {
MS_TRACE_STD(); MS_TRACE_STD();
...@@ -174,7 +174,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) ...@@ -174,7 +174,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len)
{ {
MS_ERROR_STD("uv_try_write() failed, closing the socket: %s", uv_strerror(written)); MS_ERROR_STD("uv_try_write() failed, closing the socket: %s", uv_strerror(written));
Close(); Destroy();
return; return;
} }
...@@ -241,7 +241,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -241,7 +241,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf)
this->isClosedByPeer = true; this->isClosedByPeer = true;
// Close local side of the pipe. // Close local side of the pipe.
Close(); Destroy();
} }
// Some error. // Some error.
else else
...@@ -251,7 +251,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -251,7 +251,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf)
this->hasError = true; this->hasError = true;
// Close the socket. // Close the socket.
Close(); Destroy();
} }
} }
...@@ -268,7 +268,7 @@ void UnixStreamSocket::onUvWriteError(int error) ...@@ -268,7 +268,7 @@ void UnixStreamSocket::onUvWriteError(int error)
MS_ERROR_STD("write error, closing the pipe: %s", uv_strerror(error)); MS_ERROR_STD("write error, closing the pipe: %s", uv_strerror(error));
Close(); Destroy();
} }
inline inline
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论