Przeglądaj źródła

Make copying optional when receiving data (#428)

* Reduce memory usage

Reduce memory usage by discarding, not resetting, the frame data buffer.
Let delegate control copying.

* Delegate methods expect `self`

* Add `-sendWithoutCopyingData:error:`

* Add `-webSocket:shouldCopyReceivedData:`

* Fix error messages

* Remove `-webSocket:shouldCopyReceivedData:`

* Revert "Fix error messages"

This reverts commit 4d5f5f018d0c953c9f9c9394f284f8358a039f90.

* Fix typo

* Copy only control frames

* Fix error message
Erik Price 8 lat temu
rodzic
commit
877ac7438b
1 zmienionych plików z 7 dodań i 7 usunięć
  1. 7 7
      SocketRocket/SRWebSocket.m

+ 7 - 7
SocketRocket/SRWebSocket.m

@@ -765,19 +765,19 @@ static inline BOOL closeCodeIsValid(int closeCode) {
 
 - (void)_handleFrameWithData:(NSData *)frameData opCode:(SROpCode)opcode
 {
-    //frameData will be copied before passing to handlers
-    //otherwise there can be misbehaviours when value at the pointer is changed
-    frameData = [frameData copy];
-
     // Check that the current data is valid UTF8
 
     BOOL isControlFrame = (opcode == SROpCodePing || opcode == SROpCodePong || opcode == SROpCodeConnectionClose);
-    if (!isControlFrame) {
-        [self _readFrameNew];
-    } else {
+    if (isControlFrame) {
+        //frameData will be copied before passing to handlers
+        //otherwise there can be misbehaviours when value at the pointer is changed
+        frameData = [frameData copy];
+
         dispatch_async(_workQueue, ^{
             [self _readFrameContinue];
         });
+    } else {
+        [self _readFrameNew];
     }
 
     switch (opcode) {