|
@@ -155,7 +155,6 @@ public class Call {
|
|
|
/// Parameter data: the message data to send
|
|
/// Parameter data: the message data to send
|
|
|
/// - Throws: `CallError` if fails to call. `CallWarning` if blocked.
|
|
/// - Throws: `CallError` if fails to call. `CallWarning` if blocked.
|
|
|
public func sendMessage(data: Data, completion: ((Error?) -> Void)? = nil) throws {
|
|
public func sendMessage(data: Data, completion: ((Error?) -> Void)? = nil) throws {
|
|
|
- messageQueueEmpty.enter()
|
|
|
|
|
try sendMutex.synchronize {
|
|
try sendMutex.synchronize {
|
|
|
if writing {
|
|
if writing {
|
|
|
if let messageQueueMaxLength = Call.messageQueueMaxLength,
|
|
if let messageQueueMaxLength = Call.messageQueueMaxLength,
|
|
@@ -166,14 +165,16 @@ public class Call {
|
|
|
} else {
|
|
} else {
|
|
|
writing = true
|
|
writing = true
|
|
|
try sendWithoutBlocking(data: data, completion: completion)
|
|
try sendWithoutBlocking(data: data, completion: completion)
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ messageQueueEmpty.enter()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// helper for sending queued messages
|
|
/// helper for sending queued messages
|
|
|
private func sendWithoutBlocking(data: Data, completion: ((Error?) -> Void)?) throws {
|
|
private func sendWithoutBlocking(data: Data, completion: ((Error?) -> Void)?) throws {
|
|
|
- try perform(OperationGroup(call: self,
|
|
|
|
|
- operations: [.sendMessage(ByteBuffer(data: data))]) { operationGroup in
|
|
|
|
|
|
|
+ try perform(OperationGroup(
|
|
|
|
|
+ call: self,
|
|
|
|
|
+ operations: [.sendMessage(ByteBuffer(data: data))]) { operationGroup in
|
|
|
// Always enqueue the next message, even if sending this one failed. This ensures that all send completion
|
|
// Always enqueue the next message, even if sending this one failed. This ensures that all send completion
|
|
|
// handlers are called eventually.
|
|
// handlers are called eventually.
|
|
|
self.sendMutex.synchronize {
|
|
self.sendMutex.synchronize {
|