Closed martinh closed 12 years ago
Now you can do stuff like this:
(class SockTest is NSObject
(- (void)parse:(id)data is
(set string (((NSString alloc) initWithData:data encoding:NSUTF8StringEncoding) autorelease))
(NSLog "got data: #{string}"))
; stream delegate method
(- (void)stream:(id)stream handleEvent:(int)event is
(NSLog "got event #{event}")
(case event
(NSStreamEventHasBytesAvailable (self parse:(stream data)))
(NSStreamEventHasSpaceAvailable (stream shutdownWrite))
(NSStreamEventErrorOccurred (stream close))
(NSStreamEventEndEncountered (stream close)))) )
(set $stream (ViBufferedStream streamWithHost:"www.google.com" port:"80"))
(set $delegate (SockTest new))
($stream setDelegate:$delegate)
($stream writeString:"GET / HTTP/1.0\r\n\r\n")
($stream schedule)
(NSLog "scheduled stream")
So when I wrote my close functions for NSStreams I did:
[stream removeFromRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
Is this not necessary or is it something that should probably be added to ViBufferedStream's close function?
Never mind, just spotted the comment about CFSocketInvalidate pulling things out of the run loop.
Ok, so I just switched out the NS*Stream stuff in vico-ensime for ViBufferedStream and everything is running smooth as butter. Looks great!
This improves socket support in
ViBufferedStream
.