* Added more documentation.
* Minor API changes.
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];
33 - (id) propertyForKey: (CFStringRef)cfStreamProperty
35 CFTypeRef value = CFWriteStreamCopyProperty((CFWriteStreamRef)_stream,cfStreamProperty);
36 return [(id)CFMakeCollectable(value) autorelease];
39 - (void) setProperty: (id)value forKey: (CFStringRef)cfStreamProperty
41 if( ! CFWriteStreamSetProperty((CFWriteStreamRef)_stream,cfStreamProperty,(CFTypeRef)value) )
42 Warn(@"%@ didn't accept property '%@'", self,cfStreamProperty);
48 return _currentData || _queue.count > 0;
52 - (void) writeData: (NSData*)data
55 _queue = [[NSMutableArray alloc] init];
56 [_queue addObject: data];
57 if( _queue.count==1 && ((NSOutputStream*)_stream).hasSpaceAvailable )
64 if( ! _currentData ) {
65 if( _queue.count==0 ) {
66 [self queueIsEmpty]; // this may call -writeData, which will call _canWrite again
69 _currentData = [[_queue objectAtIndex: 0] retain];
71 [_queue removeObjectAtIndex: 0];
74 const uint8_t* src = _currentData.bytes;
75 src += _currentDataPos;
76 NSInteger len = _currentData.length - _currentDataPos;
77 NSInteger written = [(NSOutputStream*)_stream write: src maxLength: len];
80 else if( written < len ) {
81 LogTo(TCPVerbose,@"%@ wrote %i bytes (of %u)", self,written,len);
82 _currentDataPos += written;
84 LogTo(TCPVerbose,@"%@ wrote %i bytes", self,written);
85 setObj(&_currentData,nil);
99 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
101 Redistribution and use in source and binary forms, with or without modification, are permitted
102 provided that the following conditions are met:
104 * Redistributions of source code must retain the above copyright notice, this list of conditions
105 and the following disclaimer.
106 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
107 and the following disclaimer in the documentation and/or other materials provided with the
110 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
111 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
112 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
113 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
114 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
115 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
116 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
117 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.