зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1862740: Misc c++ style fixes r=bwc
Including, but not limited to: * Following the style guide wrt declaration order. * Use const whenever it makes sense. * Move members to be private where possible (e.g. mLock was previously public, which it didn't have to be). * Replaced DataChannel::mFlags with individual bools - easier to read. * Fix most compiler warnings. These kind of changes are rarely complete - there is always something that was missed. It's still a step in the right direction. Differential Revision: https://phabricator.services.mozilla.com/D192563
This commit is contained in:
Родитель
aef7e8c0f3
Коммит
7caa843fb9
|
@ -398,8 +398,8 @@ static RefPtr<DataChannelConnection> GetConnectionFromSocket(
|
|||
// Called when the buffer empties to the threshold value. This is called
|
||||
// from SctpDtlsInput() through the sctp stack. SctpDtlsInput() calls
|
||||
// usrsctp_conninput() under lock
|
||||
static int threshold_event(struct socket* sock, uint32_t sb_free,
|
||||
void* ulp_info) {
|
||||
int DataChannelConnection::OnThresholdEvent(struct socket* sock,
|
||||
uint32_t sb_free, void* ulp_info) {
|
||||
RefPtr<DataChannelConnection> connection = GetConnectionFromSocket(sock);
|
||||
connection->mLock.AssertCurrentThreadOwns();
|
||||
if (connection) {
|
||||
|
@ -527,9 +527,9 @@ bool DataChannelConnection::Init(const uint16_t aLocalPort,
|
|||
const Maybe<uint64_t>& aMaxMessageSize) {
|
||||
ASSERT_WEBRTC(NS_IsMainThread());
|
||||
|
||||
struct sctp_initmsg initmsg;
|
||||
struct sctp_assoc_value av;
|
||||
struct sctp_event event;
|
||||
struct sctp_initmsg initmsg = {};
|
||||
struct sctp_assoc_value av = {};
|
||||
struct sctp_event event = {};
|
||||
socklen_t len;
|
||||
|
||||
uint16_t event_types[] = {
|
||||
|
@ -553,10 +553,11 @@ bool DataChannelConnection::Init(const uint16_t aLocalPort,
|
|||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
// Open sctp with a callback
|
||||
if ((mMasterSocket = usrsctp_socket(
|
||||
AF_CONN, SOCK_STREAM, IPPROTO_SCTP, receive_cb, threshold_event,
|
||||
usrsctp_sysctl_get_sctp_sendspace() / 2,
|
||||
reinterpret_cast<void*>(mId))) == nullptr) {
|
||||
if ((mMasterSocket =
|
||||
usrsctp_socket(AF_CONN, SOCK_STREAM, IPPROTO_SCTP, receive_cb,
|
||||
&DataChannelConnection::OnThresholdEvent,
|
||||
usrsctp_sysctl_get_sctp_sendspace() / 2,
|
||||
reinterpret_cast<void*>(mId))) == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -644,7 +645,6 @@ bool DataChannelConnection::Init(const uint16_t aLocalPort,
|
|||
}
|
||||
|
||||
/* Enable the events of interest. */
|
||||
memset(&event, 0, sizeof(event));
|
||||
event.se_assoc_id = SCTP_ALL_ASSOC;
|
||||
event.se_on = 1;
|
||||
for (unsigned short event_type : event_types) {
|
||||
|
@ -656,7 +656,6 @@ bool DataChannelConnection::Init(const uint16_t aLocalPort,
|
|||
}
|
||||
}
|
||||
|
||||
memset(&initmsg, 0, sizeof(initmsg));
|
||||
len = sizeof(initmsg);
|
||||
if (usrsctp_getsockopt(mMasterSocket, IPPROTO_SCTP, SCTP_INITMSG, &initmsg,
|
||||
&len) < 0) {
|
||||
|
@ -912,8 +911,7 @@ void DataChannelConnection::CompleteConnect() {
|
|||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_conn addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
struct sockaddr_conn addr = {};
|
||||
addr.sconn_family = AF_CONN;
|
||||
# if defined(__Userspace_os_Darwin)
|
||||
addr.sconn_len = sizeof(addr);
|
||||
|
@ -933,10 +931,9 @@ void DataChannelConnection::CompleteConnect() {
|
|||
r = usrsctp_connect(
|
||||
mMasterSocket, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr));
|
||||
if (r >= 0 || errno == EINPROGRESS) {
|
||||
struct sctp_paddrparams paddrparams;
|
||||
struct sctp_paddrparams paddrparams = {};
|
||||
socklen_t opt_len;
|
||||
|
||||
memset(&paddrparams, 0, sizeof(struct sctp_paddrparams));
|
||||
memcpy(&paddrparams.spp_address, &addr, sizeof(struct sockaddr_conn));
|
||||
opt_len = (socklen_t)sizeof(struct sctp_paddrparams);
|
||||
r = usrsctp_getsockopt(mMasterSocket, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS,
|
||||
|
@ -1006,17 +1003,17 @@ void DataChannelConnection::ProcessQueuedOpens() {
|
|||
RefPtr<DataChannel> channel;
|
||||
|
||||
while (nullptr != (channel = temp.PopFront())) {
|
||||
if (channel->mFlags & DATA_CHANNEL_FLAGS_FINISH_OPEN) {
|
||||
if (channel->mHasFinishedOpen) {
|
||||
DC_DEBUG(("Processing queued open for %p (%u)", channel.get(),
|
||||
channel->mStream));
|
||||
channel->mFlags &= ~DATA_CHANNEL_FLAGS_FINISH_OPEN;
|
||||
channel->mHasFinishedOpen = false;
|
||||
// OpenFinish returns a reference itself, so we need to take it can
|
||||
// Release it
|
||||
channel = OpenFinish(channel.forget()); // may reset the flag and re-push
|
||||
} else {
|
||||
NS_ASSERTION(
|
||||
false,
|
||||
"How did a DataChannel get queued without the FINISH_OPEN flag?");
|
||||
NS_ASSERTION(false,
|
||||
"How did a DataChannel get queued without the "
|
||||
"mHasFinishedOpen flag?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1091,14 +1088,13 @@ int DataChannelConnection::SctpDtlsOutput(void* addr, void* buffer,
|
|||
// Blocks! - Don't call this from main thread!
|
||||
|
||||
bool DataChannelConnection::Listen(unsigned short port) {
|
||||
struct sockaddr_in addr;
|
||||
struct sockaddr_in addr = {};
|
||||
socklen_t addr_len;
|
||||
|
||||
NS_WARNING_ASSERTION(!NS_IsMainThread(),
|
||||
"Blocks, do not call from main thread!!!");
|
||||
|
||||
/* Acting as the 'server' */
|
||||
memset((void*)&addr, 0, sizeof(addr));
|
||||
# ifdef HAVE_SIN_LEN
|
||||
addr.sin_len = sizeof(struct sockaddr_in);
|
||||
# endif
|
||||
|
@ -1153,16 +1149,14 @@ bool DataChannelConnection::Listen(unsigned short port) {
|
|||
|
||||
// Blocks! - Don't call this from main thread!
|
||||
bool DataChannelConnection::Connect(const char* addr, unsigned short port) {
|
||||
struct sockaddr_in addr4;
|
||||
struct sockaddr_in6 addr6;
|
||||
struct sockaddr_in addr4 = {};
|
||||
struct sockaddr_in6 addr6 = {};
|
||||
|
||||
NS_WARNING_ASSERTION(!NS_IsMainThread(),
|
||||
"Blocks, do not call from main thread!!!");
|
||||
|
||||
/* Acting as the connector */
|
||||
DC_DEBUG(("Connecting to %s, port %u", addr, port));
|
||||
memset((void*)&addr4, 0, sizeof(struct sockaddr_in));
|
||||
memset((void*)&addr6, 0, sizeof(struct sockaddr_in6));
|
||||
# ifdef HAVE_SIN_LEN
|
||||
addr4.sin_len = sizeof(struct sockaddr_in);
|
||||
# endif
|
||||
|
@ -1247,7 +1241,7 @@ DataChannel* DataChannelConnection::FindChannelByStream(uint16_t stream) {
|
|||
return mChannels.Get(stream).get();
|
||||
}
|
||||
|
||||
uint16_t DataChannelConnection::FindFreeStream() {
|
||||
uint16_t DataChannelConnection::FindFreeStream() const {
|
||||
ASSERT_WEBRTC(NS_IsMainThread());
|
||||
uint16_t i, limit;
|
||||
|
||||
|
@ -1294,8 +1288,8 @@ uint32_t DataChannelConnection::GetCurrentStreamIndex() {
|
|||
}
|
||||
|
||||
bool DataChannelConnection::RequestMoreStreams(int32_t aNeeded) {
|
||||
struct sctp_status status;
|
||||
struct sctp_add_streams sas;
|
||||
struct sctp_status status = {};
|
||||
struct sctp_add_streams sas = {};
|
||||
uint32_t outStreamsNeeded;
|
||||
socklen_t len;
|
||||
|
||||
|
@ -1316,7 +1310,6 @@ bool DataChannelConnection::RequestMoreStreams(int32_t aNeeded) {
|
|||
|
||||
// Note: if multiple channel opens happen when we don't have enough space,
|
||||
// we'll call RequestMoreStreams() multiple times
|
||||
memset(&sas, 0, sizeof(sas));
|
||||
sas.sas_instrms = 0;
|
||||
sas.sas_outstrms = (uint16_t)outStreamsNeeded; /* XXX error handling */
|
||||
// Doesn't block, we get an event when it succeeds or fails
|
||||
|
@ -1339,7 +1332,7 @@ bool DataChannelConnection::RequestMoreStreams(int32_t aNeeded) {
|
|||
// Returns a POSIX error code.
|
||||
int DataChannelConnection::SendControlMessage(const uint8_t* data, uint32_t len,
|
||||
uint16_t stream) {
|
||||
struct sctp_sendv_spa info = {0};
|
||||
struct sctp_sendv_spa info = {};
|
||||
|
||||
// General flags
|
||||
info.sendv_flags = SCTP_SEND_SNDINFO_VALID;
|
||||
|
@ -1369,9 +1362,7 @@ int DataChannelConnection::SendControlMessage(const uint8_t* data, uint32_t len,
|
|||
|
||||
// Returns a POSIX error code.
|
||||
int DataChannelConnection::SendOpenAckMessage(uint16_t stream) {
|
||||
struct rtcweb_datachannel_ack ack;
|
||||
|
||||
memset(&ack, 0, sizeof(struct rtcweb_datachannel_ack));
|
||||
struct rtcweb_datachannel_ack ack = {};
|
||||
ack.msg_type = DATA_CHANNEL_ACK;
|
||||
|
||||
return SendControlMessage((const uint8_t*)&ack, sizeof(ack), stream);
|
||||
|
@ -1381,11 +1372,11 @@ int DataChannelConnection::SendOpenAckMessage(uint16_t stream) {
|
|||
int DataChannelConnection::SendOpenRequestMessage(
|
||||
const nsACString& label, const nsACString& protocol, uint16_t stream,
|
||||
bool unordered, DataChannelReliabilityPolicy prPolicy, uint32_t prValue) {
|
||||
const int label_len = label.Length(); // not including nul
|
||||
const int proto_len = protocol.Length(); // not including nul
|
||||
const size_t label_len = label.Length(); // not including nul
|
||||
const size_t proto_len = protocol.Length(); // not including nul
|
||||
// careful - request struct include one char for the label
|
||||
const int req_size = sizeof(struct rtcweb_datachannel_open_request) - 1 +
|
||||
label_len + proto_len;
|
||||
const size_t req_size = sizeof(struct rtcweb_datachannel_open_request) - 1 +
|
||||
label_len + proto_len;
|
||||
UniqueFreePtr<struct rtcweb_datachannel_open_request> req(
|
||||
(struct rtcweb_datachannel_open_request*)moz_xmalloc(req_size));
|
||||
|
||||
|
@ -1681,9 +1672,9 @@ void DataChannelConnection::HandleOpenAckMessage(
|
|||
}
|
||||
|
||||
DC_DEBUG(("OpenAck received for stream %u, waiting=%d", stream,
|
||||
(channel->mFlags & DATA_CHANNEL_FLAGS_WAITING_ACK) ? 1 : 0));
|
||||
channel->mWaitingForAck ? 1 : 0));
|
||||
|
||||
channel->mFlags &= ~DATA_CHANNEL_FLAGS_WAITING_ACK;
|
||||
channel->mWaitingForAck = false;
|
||||
}
|
||||
|
||||
// Caller must ensure that length <= SIZE_MAX
|
||||
|
@ -1774,7 +1765,7 @@ void DataChannelConnection::HandleDataMessage(const void* data, size_t length,
|
|||
// If the channel was opened on this side, and a message is received, this
|
||||
// indicates that the peer has already received the DATA_CHANNEL_ACK, as the
|
||||
// channel is ordered initially.
|
||||
channel->mFlags &= ~DATA_CHANNEL_FLAGS_WAITING_ACK;
|
||||
channel->mWaitingForAck = false;
|
||||
|
||||
bool is_binary = true;
|
||||
uint8_t bufferFlags;
|
||||
|
@ -1796,14 +1787,14 @@ void DataChannelConnection::HandleDataMessage(const void* data, size_t length,
|
|||
|
||||
// Remaining chunks of previously truncated message (due to the buffer being
|
||||
// full)?
|
||||
if (channel->mFlags & DATA_CHANNEL_FLAGS_CLOSING_TOO_LARGE) {
|
||||
if (channel->mClosingTooLarge) {
|
||||
DC_ERROR(
|
||||
("DataChannel: Ignoring partial message of length %u, buffer full and "
|
||||
"closing",
|
||||
data_length));
|
||||
// Only unblock if unordered
|
||||
if (!channel->mOrdered && (flags & MSG_EOR)) {
|
||||
channel->mFlags &= ~DATA_CHANNEL_FLAGS_CLOSING_TOO_LARGE;
|
||||
channel->mClosingTooLarge = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1815,7 +1806,7 @@ void DataChannelConnection::HandleDataMessage(const void* data, size_t length,
|
|||
("DataChannel: Buffered message would become too large to handle, "
|
||||
"closing channel"));
|
||||
channel->mRecvBuffer.Truncate(0);
|
||||
channel->mFlags |= DATA_CHANNEL_FLAGS_CLOSING_TOO_LARGE;
|
||||
channel->mClosingTooLarge = true;
|
||||
CloseLocked(channel);
|
||||
return;
|
||||
}
|
||||
|
@ -2633,7 +2624,7 @@ already_AddRefed<DataChannel> DataChannelConnection::OpenFinish(
|
|||
}
|
||||
DC_DEBUG(("Queuing channel %p (%u) to finish open", channel.get(), stream));
|
||||
// Also serves to mark we told the app
|
||||
channel->mFlags |= DATA_CHANNEL_FLAGS_FINISH_OPEN;
|
||||
channel->mHasFinishedOpen = true;
|
||||
mPending.Push(channel);
|
||||
return channel.forget();
|
||||
}
|
||||
|
@ -2651,7 +2642,7 @@ already_AddRefed<DataChannel> DataChannelConnection::OpenFinish(
|
|||
if (!channel->mNegotiated) {
|
||||
if (!channel->mOrdered) {
|
||||
// Don't send unordered until this gets cleared.
|
||||
channel->mFlags |= DATA_CHANNEL_FLAGS_WAITING_ACK;
|
||||
channel->mWaitingForAck = true;
|
||||
}
|
||||
|
||||
int error = SendOpenRequestMessage(channel->mLabel, channel->mProtocol,
|
||||
|
@ -2659,7 +2650,7 @@ already_AddRefed<DataChannel> DataChannelConnection::OpenFinish(
|
|||
channel->mPrPolicy, channel->mPrValue);
|
||||
if (error) {
|
||||
DC_ERROR(("SendOpenRequest failed, error = %d", error));
|
||||
if (channel->mFlags & DATA_CHANNEL_FLAGS_FINISH_OPEN) {
|
||||
if (channel->mHasFinishedOpen) {
|
||||
// We already returned the channel to the app.
|
||||
NS_ERROR("Failed to send open request");
|
||||
channel->AnnounceClosed();
|
||||
|
@ -2680,7 +2671,7 @@ already_AddRefed<DataChannel> DataChannelConnection::OpenFinish(
|
|||
return channel.forget();
|
||||
|
||||
request_error_cleanup:
|
||||
if (channel->mFlags & DATA_CHANNEL_FLAGS_FINISH_OPEN) {
|
||||
if (channel->mHasFinishedOpen) {
|
||||
// We already returned the channel to the app.
|
||||
NS_ERROR("Failed to request more streams");
|
||||
channel->AnnounceClosed();
|
||||
|
@ -2695,11 +2686,11 @@ request_error_cleanup:
|
|||
// Requires mLock to be locked!
|
||||
// Returns a POSIX error code directly instead of setting errno.
|
||||
int DataChannelConnection::SendMsgInternal(OutgoingMsg& msg, size_t* aWritten) {
|
||||
auto& info = msg.GetInfo().sendv_sndinfo;
|
||||
struct sctp_sndinfo& info = msg.GetInfo().sendv_sndinfo;
|
||||
int error;
|
||||
|
||||
// EOR set?
|
||||
bool eor_set = info.snd_flags & SCTP_EOR ? true : false;
|
||||
bool eor_set = (info.snd_flags & SCTP_EOR) != 0;
|
||||
|
||||
// Send until buffer is empty
|
||||
size_t left = msg.GetLeft();
|
||||
|
@ -2848,7 +2839,7 @@ int DataChannelConnection::SendDataMsgInternalOrBuffer(DataChannel& channel,
|
|||
return EINVAL; // TODO: Find a better error code
|
||||
}
|
||||
|
||||
struct sctp_sendv_spa info = {0};
|
||||
struct sctp_sendv_spa info = {};
|
||||
|
||||
// General flags
|
||||
info.sendv_flags = SCTP_SEND_SNDINFO_VALID;
|
||||
|
@ -2862,7 +2853,7 @@ int DataChannelConnection::SendDataMsgInternalOrBuffer(DataChannel& channel,
|
|||
// To avoid problems where an in-order OPEN is lost and an
|
||||
// out-of-order data message "beats" it, require data to be in-order
|
||||
// until we get an ACK.
|
||||
if (!channel.mOrdered && !(channel.mFlags & DATA_CHANNEL_FLAGS_WAITING_ACK)) {
|
||||
if (!channel.mOrdered && !channel.mWaitingForAck) {
|
||||
info.sendv_sndinfo.snd_flags |= SCTP_UNORDERED;
|
||||
}
|
||||
|
||||
|
@ -3269,8 +3260,11 @@ void DataChannel::Close() {
|
|||
|
||||
// Used when disconnecting from the DataChannelConnection
|
||||
void DataChannel::StreamClosedLocked() {
|
||||
MOZ_ASSERT(mConnection);
|
||||
if (!mConnection) {
|
||||
return;
|
||||
}
|
||||
mConnection->mLock.AssertCurrentThreadOwns();
|
||||
ENSURE_DATACONNECTION;
|
||||
|
||||
DC_DEBUG(("Destroying Data channel %u", mStream));
|
||||
MOZ_ASSERT_IF(mStream != INVALID_STREAM,
|
||||
|
|
|
@ -69,13 +69,15 @@ enum class DataChannelReliabilityPolicy {
|
|||
class OutgoingMsg {
|
||||
public:
|
||||
OutgoingMsg(struct sctp_sendv_spa& info, const uint8_t* data, size_t length);
|
||||
OutgoingMsg(OutgoingMsg&& other) = default;
|
||||
OutgoingMsg& operator=(OutgoingMsg&& other) = default;
|
||||
~OutgoingMsg() = default;
|
||||
;
|
||||
|
||||
void Advance(size_t offset);
|
||||
struct sctp_sendv_spa& GetInfo() { return *mInfo; };
|
||||
struct sctp_sendv_spa& GetInfo() const { return *mInfo; };
|
||||
size_t GetLength() const { return mLength; };
|
||||
size_t GetLeft() const { return mLength - mPos; };
|
||||
const uint8_t* GetData() { return (const uint8_t*)(mData + mPos); };
|
||||
const uint8_t* GetData() const { return (const uint8_t*)(mData + mPos); };
|
||||
|
||||
protected:
|
||||
OutgoingMsg() // Use this for inheritance only
|
||||
|
@ -90,7 +92,9 @@ class OutgoingMsg {
|
|||
// This class copies data of an outgoing message.
|
||||
class BufferedOutgoingMsg : public OutgoingMsg {
|
||||
public:
|
||||
explicit BufferedOutgoingMsg(OutgoingMsg& message);
|
||||
explicit BufferedOutgoingMsg(OutgoingMsg& msg);
|
||||
BufferedOutgoingMsg(BufferedOutgoingMsg&& other) = default;
|
||||
BufferedOutgoingMsg& operator=(BufferedOutgoingMsg&& other) = default;
|
||||
~BufferedOutgoingMsg();
|
||||
};
|
||||
|
||||
|
@ -104,7 +108,8 @@ class QueuedDataMessage {
|
|||
mData = static_cast<uint8_t*>(moz_xmalloc((size_t)length)); // infallible
|
||||
memcpy(mData, data, (size_t)length);
|
||||
}
|
||||
|
||||
QueuedDataMessage(QueuedDataMessage&& other) = default;
|
||||
QueuedDataMessage& operator=(QueuedDataMessage&& other) = default;
|
||||
~QueuedDataMessage() { free(mData); }
|
||||
|
||||
uint16_t mStream;
|
||||
|
@ -134,8 +139,6 @@ class DataChannelConnection final : public net::NeckoTargetHolder
|
|||
Data, // Outgoing data channel messages are pending.
|
||||
};
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DataChannelConnection)
|
||||
|
||||
class DataConnectionListener : public SupportsWeakPtr {
|
||||
public:
|
||||
virtual ~DataConnectionListener() = default;
|
||||
|
@ -164,6 +167,11 @@ class DataChannelConnection final : public net::NeckoTargetHolder
|
|||
MediaTransportHandler* aHandler, const uint16_t aLocalPort,
|
||||
const uint16_t aNumStreams, const Maybe<uint64_t>& aMaxMessageSize);
|
||||
|
||||
DataChannelConnection(const DataChannelConnection&) = delete;
|
||||
DataChannelConnection& operator=(const DataChannelConnection&) = delete;
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DataChannelConnection)
|
||||
|
||||
void Destroy(); // So we can spawn refs tied to runnables in shutdown
|
||||
// Finish Destroy on STS to avoid SCTP race condition with ABORT from far end
|
||||
void DestroyOnSTS(struct socket* aMasterSocket, struct socket* aSocket);
|
||||
|
@ -222,8 +230,6 @@ class DataChannelConnection final : public net::NeckoTargetHolder
|
|||
int ReceiveCallback(struct socket* sock, void* data, size_t datalen,
|
||||
struct sctp_rcvinfo rcv, int flags);
|
||||
|
||||
Mutex mLock;
|
||||
|
||||
void ReadBlob(already_AddRefed<DataChannelConnection> aThis, uint16_t aStream,
|
||||
nsIInputStream* aBlob);
|
||||
|
||||
|
@ -242,12 +248,37 @@ class DataChannelConnection final : public net::NeckoTargetHolder
|
|||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
// Avoid cycles with PeerConnectionImpl
|
||||
// Use from main thread only as WeakPtr is not threadsafe
|
||||
WeakPtr<DataConnectionListener> mListener;
|
||||
|
||||
private:
|
||||
class Channels {
|
||||
public:
|
||||
using ChannelArray = AutoTArray<RefPtr<DataChannel>, 16>;
|
||||
|
||||
Channels() : mMutex("DataChannelConnection::Channels::mMutex") {}
|
||||
Channels(const Channels&) = delete;
|
||||
Channels& operator=(const Channels&) = delete;
|
||||
|
||||
void Insert(const RefPtr<DataChannel>& aChannel);
|
||||
bool Remove(const RefPtr<DataChannel>& aChannel);
|
||||
RefPtr<DataChannel> Get(uint16_t aId) const;
|
||||
ChannelArray GetAll() const {
|
||||
MutexAutoLock lock(mMutex);
|
||||
return mChannels.Clone();
|
||||
}
|
||||
RefPtr<DataChannel> GetNextChannel(uint16_t aCurrentId) const;
|
||||
|
||||
private:
|
||||
struct IdComparator {
|
||||
bool Equals(const RefPtr<DataChannel>& aChannel, uint16_t aId) const;
|
||||
bool LessThan(const RefPtr<DataChannel>& aChannel, uint16_t aId) const;
|
||||
bool Equals(const RefPtr<DataChannel>& a1,
|
||||
const RefPtr<DataChannel>& a2) const;
|
||||
bool LessThan(const RefPtr<DataChannel>& a1,
|
||||
const RefPtr<DataChannel>& a2) const;
|
||||
};
|
||||
mutable Mutex mMutex;
|
||||
ChannelArray mChannels MOZ_GUARDED_BY(mMutex);
|
||||
};
|
||||
|
||||
DataChannelConnection(DataConnectionListener* aListener,
|
||||
nsISerialEventTarget* aTarget,
|
||||
MediaTransportHandler* aHandler);
|
||||
|
@ -262,6 +293,8 @@ class DataChannelConnection final : public net::NeckoTargetHolder
|
|||
}
|
||||
|
||||
void SetState(DataChannelConnectionState aState) MOZ_REQUIRES(mLock);
|
||||
static int OnThresholdEvent(struct socket* sock, uint32_t sb_free,
|
||||
void* ulp_info);
|
||||
|
||||
#ifdef SCTP_DTLS_SUPPORTED
|
||||
static void DTLSConnectThread(void* data);
|
||||
|
@ -270,7 +303,7 @@ class DataChannelConnection final : public net::NeckoTargetHolder
|
|||
const MediaPacket& packet);
|
||||
#endif
|
||||
DataChannel* FindChannelByStream(uint16_t stream) MOZ_REQUIRES(mLock);
|
||||
uint16_t FindFreeStream() MOZ_REQUIRES(mLock);
|
||||
uint16_t FindFreeStream() const MOZ_REQUIRES(mLock);
|
||||
bool RequestMoreStreams(int32_t aNeeded = 16) MOZ_REQUIRES(mLock);
|
||||
uint32_t UpdateCurrentStreamIndex() MOZ_REQUIRES(mLock);
|
||||
uint32_t GetCurrentStreamIndex() MOZ_REQUIRES(mLock);
|
||||
|
@ -313,7 +346,7 @@ class DataChannelConnection final : public net::NeckoTargetHolder
|
|||
MOZ_REQUIRES(mLock);
|
||||
uint8_t BufferMessage(nsACString& recvBuffer, const void* data,
|
||||
uint32_t length, uint32_t ppid, int flags);
|
||||
void HandleDataMessage(const void* buffer, size_t length, uint32_t ppid,
|
||||
void HandleDataMessage(const void* data, size_t length, uint32_t ppid,
|
||||
uint16_t stream, int flags) MOZ_REQUIRES(mLock);
|
||||
void HandleDCEPMessage(const void* buffer, size_t length, uint32_t ppid,
|
||||
uint16_t stream, int flags) MOZ_REQUIRES(mLock);
|
||||
|
@ -350,32 +383,10 @@ class DataChannelConnection final : public net::NeckoTargetHolder
|
|||
}
|
||||
#endif
|
||||
|
||||
class Channels {
|
||||
public:
|
||||
Channels() : mMutex("DataChannelConnection::Channels::mMutex") {}
|
||||
void Insert(const RefPtr<DataChannel>& aChannel);
|
||||
bool Remove(const RefPtr<DataChannel>& aChannel);
|
||||
RefPtr<DataChannel> Get(uint16_t aId) const;
|
||||
typedef AutoTArray<RefPtr<DataChannel>, 16> ChannelArray;
|
||||
ChannelArray GetAll() const {
|
||||
MutexAutoLock lock(mMutex);
|
||||
return mChannels.Clone();
|
||||
}
|
||||
RefPtr<DataChannel> GetNextChannel(uint16_t aCurrentId) const;
|
||||
|
||||
private:
|
||||
struct IdComparator {
|
||||
bool Equals(const RefPtr<DataChannel>& aChannel, uint16_t aId) const;
|
||||
bool LessThan(const RefPtr<DataChannel>& aChannel, uint16_t aId) const;
|
||||
bool Equals(const RefPtr<DataChannel>& a1,
|
||||
const RefPtr<DataChannel>& a2) const;
|
||||
bool LessThan(const RefPtr<DataChannel>& a1,
|
||||
const RefPtr<DataChannel>& a2) const;
|
||||
};
|
||||
mutable Mutex mMutex;
|
||||
ChannelArray mChannels MOZ_GUARDED_BY(mMutex);
|
||||
};
|
||||
|
||||
mutable Mutex mLock;
|
||||
// Avoid cycles with PeerConnectionImpl
|
||||
// Use from main thread only as WeakPtr is not threadsafe
|
||||
WeakPtr<DataConnectionListener> mListener;
|
||||
bool mSendInterleaved MOZ_GUARDED_BY(mLock) = false;
|
||||
// MainThread only
|
||||
bool mMaxMessageSizeSet = false;
|
||||
|
@ -432,19 +443,18 @@ class DataChannelConnection final : public net::NeckoTargetHolder
|
|||
uintptr_t mId = 0;
|
||||
};
|
||||
|
||||
#define ENSURE_DATACONNECTION \
|
||||
do { \
|
||||
MOZ_ASSERT(mConnection); \
|
||||
if (!mConnection) { \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
class DataChannel {
|
||||
friend class DataChannelOnMessageAvailable;
|
||||
friend class DataChannelConnection;
|
||||
|
||||
public:
|
||||
struct TrafficCounters {
|
||||
uint32_t mMessagesSent = 0;
|
||||
uint64_t mBytesSent = 0;
|
||||
uint32_t mMessagesReceived = 0;
|
||||
uint64_t mBytesReceived = 0;
|
||||
};
|
||||
|
||||
DataChannel(DataChannelConnection* connection, uint16_t stream,
|
||||
DataChannelState state, const nsACString& label,
|
||||
const nsACString& protocol, DataChannelReliabilityPolicy policy,
|
||||
|
@ -461,7 +471,6 @@ class DataChannel {
|
|||
mPrValue(value),
|
||||
mNegotiated(negotiated),
|
||||
mOrdered(ordered),
|
||||
mFlags(0),
|
||||
mIsRecvBinary(false),
|
||||
mBufferedThreshold(0), // default from spec
|
||||
mBufferedAmount(0),
|
||||
|
@ -469,6 +478,8 @@ class DataChannel {
|
|||
mStatsLock("netwer::sctp::DataChannel::mStatsLock") {
|
||||
NS_ASSERTION(mConnection, "NULL connection");
|
||||
}
|
||||
DataChannel(const DataChannel&) = delete;
|
||||
DataChannel& operator=(const DataChannel&) = delete;
|
||||
|
||||
private:
|
||||
~DataChannel();
|
||||
|
@ -548,39 +559,38 @@ class DataChannel {
|
|||
|
||||
void SendOrQueue(DataChannelOnMessageAvailable* aMessage);
|
||||
|
||||
struct TrafficCounters {
|
||||
uint32_t mMessagesSent = 0;
|
||||
uint64_t mBytesSent = 0;
|
||||
uint32_t mMessagesReceived = 0;
|
||||
uint64_t mBytesReceived = 0;
|
||||
};
|
||||
|
||||
TrafficCounters GetTrafficCounters() const;
|
||||
|
||||
protected:
|
||||
// These are both mainthread only
|
||||
DataChannelListener* mListener;
|
||||
nsCOMPtr<nsISupports> mContext;
|
||||
|
||||
private:
|
||||
nsresult AddDataToBinaryMsg(const char* data, uint32_t size);
|
||||
bool EnsureValidStream(ErrorResult& aRv);
|
||||
void WithTrafficCounters(const std::function<void(TrafficCounters&)>&);
|
||||
|
||||
// These are both mainthread only
|
||||
DataChannelListener* mListener;
|
||||
nsCOMPtr<nsISupports> mContext;
|
||||
|
||||
RefPtr<DataChannelConnection> mConnection;
|
||||
// mainthread only
|
||||
bool mEverOpened = false;
|
||||
nsCString mLabel;
|
||||
nsCString mProtocol;
|
||||
const nsCString mLabel;
|
||||
const nsCString mProtocol;
|
||||
// This is mainthread only
|
||||
DataChannelState mReadyState;
|
||||
uint16_t mStream;
|
||||
DataChannelReliabilityPolicy mPrPolicy;
|
||||
uint32_t mPrValue;
|
||||
const DataChannelReliabilityPolicy mPrPolicy;
|
||||
const uint32_t mPrValue;
|
||||
// Accessed on main and STS
|
||||
const bool mNegotiated;
|
||||
const bool mOrdered;
|
||||
uint32_t mFlags;
|
||||
// The data channel has completed the open procedure and the client has been
|
||||
// notified about it.
|
||||
bool mHasFinishedOpen = false;
|
||||
// The channel has been opened, but the peer has not yet acked - ensures that
|
||||
// the messages are sent ordered until this is cleared.
|
||||
bool mWaitingForAck = false;
|
||||
// A too large message was attempted to be sent - closing data channel.
|
||||
bool mClosingTooLarge = false;
|
||||
bool mIsRecvBinary;
|
||||
size_t mBufferedThreshold;
|
||||
// Read/written on main only. Decremented via message-passing, because the
|
||||
|
@ -590,7 +600,7 @@ class DataChannel {
|
|||
nsTArray<UniquePtr<BufferedOutgoingMsg>>
|
||||
mBufferedData; // MOZ_GUARDED_BY(mConnection->mLock)
|
||||
nsCOMPtr<nsISerialEventTarget> mMainThreadEventTarget;
|
||||
mutable Mutex mStatsLock; // protects mTrafficCounters
|
||||
mutable Mutex mStatsLock;
|
||||
TrafficCounters mTrafficCounters MOZ_GUARDED_BY(mStatsLock);
|
||||
};
|
||||
|
||||
|
@ -639,6 +649,9 @@ class DataChannelOnMessageAvailable : public Runnable {
|
|||
: Runnable("DataChannelOnMessageAvailable"),
|
||||
mType(aType),
|
||||
mConnection(aConnection) {}
|
||||
DataChannelOnMessageAvailable(const DataChannelOnMessageAvailable&) = delete;
|
||||
DataChannelOnMessageAvailable& operator=(
|
||||
const DataChannelOnMessageAvailable&) = delete;
|
||||
|
||||
NS_IMETHOD Run() override;
|
||||
|
||||
|
|
|
@ -38,10 +38,6 @@
|
|||
|
||||
#define DATA_CHANNEL_MAX_BINARY_FRAGMENT 0x4000
|
||||
|
||||
#define DATA_CHANNEL_FLAGS_FINISH_OPEN 0x00000004
|
||||
#define DATA_CHANNEL_FLAGS_WAITING_ACK 0x00000010
|
||||
#define DATA_CHANNEL_FLAGS_CLOSING_TOO_LARGE 0x00000020
|
||||
|
||||
#define DATA_CHANNEL_BUFFER_MESSAGE_FLAGS_TOO_LARGE 0x01
|
||||
#define DATA_CHANNEL_BUFFER_MESSAGE_FLAGS_BUFFERED 0x02
|
||||
#define DATA_CHANNEL_BUFFER_MESSAGE_FLAGS_COMPLETE 0x04
|
||||
|
|
Загрузка…
Ссылка в новой задаче