From 7c12fbab8dd539d42a50e9b06a23568630951579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Obr=C3=A1til?= Date: Wed, 21 Jan 2015 16:58:31 +0100 Subject: [PATCH 1/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 33f5acf..e953f8e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This Cordova plugin provides JavaScript API, that allows you to communicate with Currently we support these platforms: iOS, Android, WP8. +You can also get information about this plugin from our blog post http://www.blocshop.cz/blog/?p=6 + ## Installation Install this plugin simply by: From 04cb562ac3912ec49e79ff5534f52fbf7169bbdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Obr=C3=A1til?= Date: Wed, 20 May 2015 14:09:26 -0700 Subject: [PATCH 2/3] Update SocketAdapter.m Improved scalability of write operation for iOS platform --- .../SocketsForCordova/Classes/SocketAdapter.m | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/ios/SocketsForCordova/Classes/SocketAdapter.m b/src/ios/SocketsForCordova/Classes/SocketAdapter.m index 7534ddc..6fb5ec0 100644 --- a/src/ios/SocketsForCordova/Classes/SocketAdapter.m +++ b/src/ios/SocketsForCordova/Classes/SocketAdapter.m @@ -1,6 +1,7 @@ #include #include #include +#include #import "SocketAdapter.h" CFReadStreamRef readStream; @@ -11,6 +12,8 @@ NSOutputStream *outputStream; BOOL wasOpenned = FALSE; +int const WRITE_BUFFER_SIZE = 10 * 1024; + @implementation SocketAdapter - (void)open:(NSString *)host port:(NSNumber*)port { @@ -169,14 +172,27 @@ BOOL wasOpenned = FALSE; } - (void)write:(NSArray *)dataArray { - uint8_t buf[dataArray.count]; - for (int i = 0; i < dataArray.count; i++) { - buf[i] = (unsigned char)[[dataArray objectAtIndex:i] integerValue]; + int numberOfBatches = ceil((float)dataArray.count / (float)WRITE_BUFFER_SIZE); + for (int i = 0; i < (numberOfBatches - 1); i++) { + [self writeSubarray:dataArray offset:i * WRITE_BUFFER_SIZE length:WRITE_BUFFER_SIZE]; } - NSInteger bytesWritten = [outputStream write:buf maxLength:dataArray.count]; + int lastBatchPosition = (numberOfBatches - 1) * WRITE_BUFFER_SIZE; + [self writeSubarray:dataArray offset:lastBatchPosition length:(dataArray.count - lastBatchPosition)]; +} + +- (void)writeSubarray:(NSArray *)dataArray offset:(long)offset length:(long)length { + uint8_t buf[length]; + for (long i = 0; i < length; i++) { + unsigned char byte = (unsigned char)[[dataArray objectAtIndex:(offset + i)] integerValue]; + buf[i] = byte; + } + NSInteger bytesWritten = [outputStream write:buf maxLength:length]; if (bytesWritten == -1) { @throw [NSException exceptionWithName:@"SocketException" reason:[outputStream.streamError localizedDescription] userInfo:nil]; } + if (bytesWritten != length) { + [self writeSubarray:dataArray offset:(offset + bytesWritten) length:(length - bytesWritten)]; + } } - (void)close { @@ -189,4 +205,4 @@ BOOL wasOpenned = FALSE; [self closeInputStream]; } -@end \ No newline at end of file +@end From 3122fe2955ff038374796b3c6e2e118e2dabb62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Obr=C3=A1til?= Date: Wed, 1 Jul 2015 11:50:59 +0200 Subject: [PATCH 3/3] Added BSD License to Readme --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index e953f8e..4a56782 100644 --- a/README.md +++ b/README.md @@ -133,3 +133,26 @@ Closes the connection. `onClose` event handler is called when connection is succ | ----------- |-----------------------------|--------------| | `onSuccess` | `() => void` | Success callback, called after connection is successfully closed. `onClose` event handler is called before that callback. (optional)| | `onError` | `(message: string) => void` | Error callback, called when some error occurs during this procedure. (optional)| + +## BSD License +Copyright (c) 2015, Blocshop s.r.o. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by the Blocshop s.r.o.. +4. Neither the name of the Blocshop s.r.o. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY Blocshop s.r.o. ''AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.