Fixed a memory leak by adding a -dealloc method to HostAddress. (Thanks to Mark Onyschuk)
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 LogTo(TCPVerbose,@"%@ using _currentData %p (%u bytes)", self,_currentData,_currentData.length);
59 [_queue removeObjectAtIndex: 0];
62 const uint8_t* src = _currentData.bytes;
63 src += _currentDataPos;
64 NSInteger len = _currentData.length - _currentDataPos;
65 NSInteger written = [(NSOutputStream*)_stream write: src maxLength: len];
68 else if( written < len ) {
69 LogTo(TCPVerbose,@"%@ wrote %i bytes (of %u) from %p", self,written,len,_currentData);
70 _currentDataPos += written;
72 LogTo(TCPVerbose,@"%@ wrote %i bytes, released %p", self,written,_currentData);
73 setObj(&_currentData,nil);
87 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
89 Redistribution and use in source and binary forms, with or without modification, are permitted
90 provided that the following conditions are met:
92 * Redistributions of source code must retain the above copyright notice, this list of conditions
93 and the following disclaimer.
94 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
95 and the following disclaimer in the documentation and/or other materials provided with the
98 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
99 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
100 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
101 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
102 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
103 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
104 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
105 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.