Changeset 5831 for WiredAdditions/trunk
- Timestamp:
- 08/29/08 16:55:56 (3 months ago)
- Files:
-
- WiredAdditions/trunk/WiredNetworking/WISocket.h (modified) (4 diffs)
- WiredAdditions/trunk/WiredNetworking/WISocket.m (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
WiredAdditions/trunk/WiredNetworking/WISocket.h
r5804 r5831 57 57 58 58 59 enum _WISocketEvent { 60 WISocketEventNone = (0 << 0), 61 WISocketEventHasBytesAvailable = (1 << 0) 62 }; 63 typedef enum _WISocketEvent WISocketEvent; 64 65 66 @protocol WISocketDelegate; 59 67 @class WIAddress, WIError; 60 68 61 69 @interface WISocket : WIObject { 70 id <WISocketDelegate> delegate; 71 62 72 wi_socket_t *_socket; 63 73 … … 65 75 66 76 NSMutableString *_buffer; 77 78 NSUInteger _sources; 79 CFSocketRef _socketRef; 80 CFRunLoopSourceRef _sourceRef; 67 81 } 68 82 … … 84 98 - (NSString *)certificateHostname; 85 99 100 - (void)setDelegate:(id <WISocketDelegate>)delegate; 101 - (id <WISocketDelegate>)delegate; 86 102 - (void)setPort:(NSUInteger)port; 87 103 - (NSUInteger)port; … … 104 120 - (NSString *)readStringUpToString:(NSString *)separator encoding:(NSStringEncoding)encoding timeout:(NSTimeInterval)timeout error:(WIError **)error; 105 121 122 - (void)scheduleInRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)mode; 123 - (void)removeFromRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)mode; 124 106 125 @end 126 127 128 @protocol WISocketDelegate <NSObject> 129 130 - (void)socket:(WISocket *)socket handleEvent:(WISocketEvent)event; 131 132 @end WiredAdditions/trunk/WiredNetworking/WISocket.m
r5804 r5831 35 35 36 36 37 static void _WISocketCallback(CFSocketRef, CFSocketCallBackType, CFDataRef, const void *, void *); 38 39 static void _WISocketCallback(CFSocketRef socketRef, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info) { 40 WISocket *socket = info; 41 42 if(callbackType == kCFSocketReadCallBack) 43 [[socket delegate] socket:socket handleEvent:WISocketEventHasBytesAvailable]; 44 } 45 46 47 37 48 @interface WISocketTLS(Private) 38 49 … … 266 277 267 278 #pragma mark - 279 280 - (void)setDelegate:(id <WISocketDelegate>)newDelegate { 281 delegate = newDelegate; 282 } 283 284 285 286 - (id <WISocketDelegate>)delegate { 287 return delegate; 288 } 289 290 268 291 269 292 - (void)setPort:(NSUInteger)port { … … 536 559 } 537 560 561 562 563 - (void)scheduleInRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)mode { 564 CFSocketContext context; 565 566 if(!_sourceRef) { 567 context.version = 0; 568 context.info = self; 569 context.retain = NULL; 570 context.release = NULL; 571 context.copyDescription = NULL; 572 573 _socketRef = CFSocketCreateWithNative(NULL, 574 wi_socket_descriptor(_socket), 575 kCFSocketReadCallBack, 576 _WISocketCallback, 577 &context); 578 579 _sourceRef = CFSocketCreateRunLoopSource(NULL, _socketRef, 0); 580 } 581 582 if(!CFRunLoopContainsSource([runLoop getCFRunLoop], _sourceRef, (CFStringRef) mode)) { 583 CFRunLoopAddSource([runLoop getCFRunLoop], _sourceRef, (CFStringRef) mode); 584 585 _sources++; 586 } 587 } 588 589 590 591 - (void)removeFromRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)mode { 592 if(CFRunLoopContainsSource([runLoop getCFRunLoop], _sourceRef, (CFStringRef) mode)) { 593 CFRunLoopRemoveSource([runLoop getCFRunLoop], _sourceRef, (CFStringRef) mode); 594 595 _sources--; 596 } 597 598 if(_sources == 0) { 599 if(_sourceRef) { 600 CFRelease(_sourceRef); 601 _sourceRef = NULL; 602 } 603 604 if(_socketRef) { 605 CFRelease(_socketRef); 606 _socketRef = NULL; 607 } 608 } 609 } 610 538 611 @end
