@@ -163,6 +163,13 @@ - (NSComparisonResult)serverNameCompare:(NSString *)string;
163163@end
164164
165165
166+ @interface MMChannel : NSObject {
167+ CFSocketRef socket;
168+ CFRunLoopSourceRef runLoopSource;
169+ }
170+
171+ - (id )initWithIndex : (int )idx fileDescriptor : (int )fd ;
172+ @end
166173
167174
168175@interface MMBackend (Private)
@@ -234,6 +241,7 @@ - (id)init
234241 connectionNameDict = [[NSMutableDictionary alloc ] init ];
235242 clientProxyDict = [[NSMutableDictionary alloc ] init ];
236243 serverReplyDict = [[NSMutableDictionary alloc ] init ];
244+ channelDict = [[NSMutableDictionary alloc ] init ];
237245
238246 NSBundle *mainBundle = [NSBundle mainBundle ];
239247 NSString *path = [mainBundle pathForResource: @" Colors" ofType: @" plist" ];
@@ -265,6 +273,7 @@ - (void)dealloc
265273 gui_mch_free_font (oldWideFont); oldWideFont = NOFONT;
266274 [blinkTimer release ]; blinkTimer = nil ;
267275 [alternateServerName release ]; alternateServerName = nil ;
276+ [channelDict release ]; channelDict = nil ;
268277 [serverReplyDict release ]; serverReplyDict = nil ;
269278 [clientProxyDict release ]; clientProxyDict = nil ;
270279 [connectionNameDict release ]; connectionNameDict = nil ;
@@ -1675,49 +1684,21 @@ - (void)setImState:(BOOL)activated
16751684 [self flushQueue: YES ];
16761685}
16771686
1678- static void netbeansReadCallback (CFSocketRef s,
1679- CFSocketCallBackType callbackType,
1680- CFDataRef address,
1681- const void *data,
1682- void *info)
1687+ - (void )addChannel : (int )idx fileDescriptor : (int )fd
16831688{
1684- // NetBeans socket is readable.
1685- [[MMBackend sharedInstance ] messageFromNetbeans ];
1686- }
1689+ if (fd == -1 )
1690+ return ;
16871691
1688- - ( void ) messageFromNetbeans
1689- {
1690- [inputQueue addObject: [ NSNumber numberWithInt: NetBeansMsgID] ];
1691- [inputQueue addObject: [ NSNull null ] ];
1692+ NSNumber *key = [ NSNumber numberWithInt: idx];
1693+ MMChannel *channel =
1694+ [[[MMChannel alloc ] initWithIndex: idx fileDescriptor: fd] autorelease ];
1695+ [channelDict setObject: channel forKey: key ];
16921696}
16931697
1694- - (void )setNetbeansSocket : (int )socket
1698+ - (void )removeChannel : (int )idx
16951699{
1696- if (netbeansSocket) {
1697- CFRelease (netbeansSocket);
1698- netbeansSocket = NULL ;
1699- }
1700-
1701- if (netbeansRunLoopSource) {
1702- CFRunLoopSourceInvalidate (netbeansRunLoopSource);
1703- netbeansRunLoopSource = NULL ;
1704- }
1705-
1706- if (socket == -1 )
1707- return ;
1708-
1709- // Tell CFRunLoop that we are interested in NetBeans socket input.
1710- netbeansSocket = CFSocketCreateWithNative (kCFAllocatorDefault ,
1711- socket,
1712- kCFSocketReadCallBack ,
1713- &netbeansReadCallback,
1714- NULL );
1715- netbeansRunLoopSource = CFSocketCreateRunLoopSource (NULL ,
1716- netbeansSocket,
1717- 0 );
1718- CFRunLoopAddSource (CFRunLoopGetCurrent (),
1719- netbeansRunLoopSource,
1720- kCFRunLoopCommonModes );
1700+ NSNumber *key = [NSNumber numberWithInt: idx];
1701+ [channelDict removeObjectForKey: key];
17211702}
17221703
17231704#ifdef FEAT_BEVAL
@@ -2075,10 +2056,6 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
20752056 [self handleOpenWithArguments: [NSDictionary dictionaryWithData: data]];
20762057 } else if (FindReplaceMsgID == msgid) {
20772058 [self handleFindReplace: [NSDictionary dictionaryWithData: data]];
2078- } else if (NetBeansMsgID == msgid) {
2079- #ifdef FEAT_NETBEANS_INTG
2080- netbeans_read ();
2081- #endif
20822059 } else if (ZoomMsgID == msgid) {
20832060 if (!data) return ;
20842061 const void *bytes = [data bytes ];
@@ -3435,3 +3412,51 @@ - (char_u *)vimStringSave
34353412}
34363413
34373414@end // NSString (VimStrings)
3415+
3416+
3417+
3418+ @implementation MMChannel
3419+
3420+ - (void )dealloc
3421+ {
3422+ CFRunLoopSourceInvalidate (runLoopSource);
3423+ CFRelease (runLoopSource);
3424+ CFRelease (socket);
3425+ [super dealloc ];
3426+ }
3427+
3428+ static void socketReadCallback (CFSocketRef s,
3429+ CFSocketCallBackType callbackType,
3430+ CFDataRef address,
3431+ const void *data,
3432+ void *info)
3433+ {
3434+ #ifdef FEAT_CHANNEL
3435+ int idx = (int )(intptr_t )info;
3436+ channel_read (idx);
3437+ #endif
3438+ }
3439+
3440+ - (id )initWithIndex : (int )idx fileDescriptor : (int )fd
3441+ {
3442+ self = [super init ];
3443+ if (!self) return nil ;
3444+
3445+ // Tell CFRunLoop that we are interested in channel socket input.
3446+ CFSocketContext ctx = {0 , (void *)(intptr_t )idx, NULL , NULL , NULL };
3447+ socket = CFSocketCreateWithNative (kCFAllocatorDefault ,
3448+ fd,
3449+ kCFSocketReadCallBack ,
3450+ &socketReadCallback,
3451+ &ctx);
3452+ runLoopSource = CFSocketCreateRunLoopSource (NULL ,
3453+ socket,
3454+ 0 );
3455+ CFRunLoopAddSource (CFRunLoopGetCurrent (),
3456+ runLoopSource,
3457+ kCFRunLoopCommonModes );
3458+
3459+ return self;
3460+ }
3461+
3462+ @end
0 commit comments