Got it to build on iPhone. (Haven't tried running it yet.)
5 // Created by Jens Alfke on 5/10/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
10 #import "TCP_Internal.h"
16 @implementation TCPWriter
22 [_currentData release];
35 return _currentData || _queue.count > 0;
39 - (void) writeData: (NSData*)data
42 _queue = [[NSMutableArray alloc] init];
43 [_queue addObject: data];
44 if( _queue.count==1 && ((NSOutputStream*)_stream).hasSpaceAvailable )
51 if( ! _currentData ) {
52 if( _queue.count==0 ) {
53 [self queueIsEmpty]; // this may call -writeData, which will call _canWrite again
56 _currentData = [[_queue objectAtIndex: 0] retain];
58 [_queue removeObjectAtIndex: 0];
61 const uint8_t* src = _currentData.bytes;
62 src += _currentDataPos;
63 NSInteger len = _currentData.length - _currentDataPos;
64 NSInteger written = [(NSOutputStream*)_stream write: src maxLength: len];
67 else if( written < len ) {
68 LogTo(TCPVerbose,@"%@ wrote %i bytes (of %u)", self,written,len);
69 _currentDataPos += written;
71 LogTo(TCPVerbose,@"%@ wrote %i bytes", self,written);
72 setObj(&_currentData,nil);
86 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
88 Redistribution and use in source and binary forms, with or without modification, are permitted
89 provided that the following conditions are met:
91 * Redistributions of source code must retain the above copyright notice, this list of conditions
92 and the following disclaimer.
93 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
94 and the following disclaimer in the documentation and/or other materials provided with the
97 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
98 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
99 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
100 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
101 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
102 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
103 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
104 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.