Changeset 3093
- Timestamp:
- 12/27/05 01:51:20 (3 years ago)
- Files:
-
- branches/cocoa-networking/Chat Core.xcodeproj/project.pbxproj (modified) (4 diffs)
- branches/cocoa-networking/Chat Core/InterThreadMessaging.h (added)
- branches/cocoa-networking/Chat Core/InterThreadMessaging.m (added)
- branches/cocoa-networking/Chat Core/MVChatConnection.m (modified) (1 diff)
- branches/cocoa-networking/Chat Core/MVIRCChatConnection.h (modified) (1 diff)
- branches/cocoa-networking/Chat Core/MVIRCChatConnection.m (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/cocoa-networking/Chat Core.xcodeproj/project.pbxproj
r3081 r3093 45 45 1CD020B505759347000F93B4 /* NSStringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1CD020B305759347000F93B4 /* NSStringAdditions.m */; }; 46 46 1CD020C0057593F9000F93B4 /* NSColorAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1CD020BD057593A9000F93B4 /* NSColorAdditions.m */; }; 47 1CD6296709611B9100BD1DD2 /* InterThreadMessaging.m in Sources */ = {isa = PBXBuildFile; fileRef = 1CD6290D096118B900BD1DD2 /* InterThreadMessaging.m */; }; 47 48 1CDDD9AD0718BD2E00FE11C3 /* MVChatRoom.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C5CC07A06FFCB0B0006C5B1 /* MVChatRoom.h */; settings = {ATTRIBUTES = (Public, ); }; }; 48 49 1CE4630F095ECCFE00AB7732 /* MVChatUserPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CE4630E095ECCFE00AB7732 /* MVChatUserPrivate.h */; }; … … 323 324 1CD020BC057593A9000F93B4 /* NSColorAdditions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = NSColorAdditions.h; path = Additions/NSColorAdditions.h; sourceTree = "<group>"; }; 324 325 1CD020BD057593A9000F93B4 /* NSColorAdditions.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = NSColorAdditions.m; path = Additions/NSColorAdditions.m; sourceTree = "<group>"; }; 326 1CD6290C096118B900BD1DD2 /* InterThreadMessaging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = InterThreadMessaging.h; path = "Chat Core/InterThreadMessaging.h"; sourceTree = "<group>"; }; 327 1CD6290D096118B900BD1DD2 /* InterThreadMessaging.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InterThreadMessaging.m; path = "Chat Core/InterThreadMessaging.m"; sourceTree = "<group>"; }; 325 328 1CE4630E095ECCFE00AB7732 /* MVChatUserPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MVChatUserPrivate.h; path = "Chat Core/MVChatUserPrivate.h"; sourceTree = "<group>"; }; 326 329 1CE4631D095ECD7300AB7732 /* MVChatRoomPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MVChatRoomPrivate.h; path = "Chat Core/MVChatRoomPrivate.h"; sourceTree = "<group>"; }; … … 738 741 1CEEB164095BE36700166A54 /* AsyncSocket.m */, 739 742 1CEEB163095BE36700166A54 /* AsyncSocket.h */, 743 1CD6290D096118B900BD1DD2 /* InterThreadMessaging.m */, 744 1CD6290C096118B900BD1DD2 /* InterThreadMessaging.h */, 740 745 ); 741 746 name = "Sources & Headers"; … … 974 979 1C7C776A07DBBA4500FB5F83 /* NSScriptCommandAdditions.m in Sources */, 975 980 1CEEB166095BE36700166A54 /* AsyncSocket.m in Sources */, 981 1CD6296709611B9100BD1DD2 /* InterThreadMessaging.m in Sources */, 976 982 ); 977 983 runOnlyForDeploymentPostprocessing = 0; branches/cocoa-networking/Chat Core/MVChatConnection.m
r3088 r3093 759 759 760 760 - (void) _didDisconnect { 761 BOOL wasConnected = ( _status == MVChatConnectionConnectedStatus || _status == MVChatConnectionSuspendedStatus );761 BOOL wasConnected = ( _status == MVChatConnectionConnectedStatus || _status == MVChatConnectionSuspendedStatus || _status == MVChatConnectionServerDisconnectedStatus ); 762 762 763 763 [[self localUser] _setStatus:MVChatUserOfflineStatus]; branches/cocoa-networking/Chat Core/MVIRCChatConnection.h
r3084 r3093 7 7 @private 8 8 AsyncSocket *_chatConnection; 9 NSThread *_connectionThread; 9 10 NSMutableDictionary *_knownUsers; 10 11 NSString *_server; branches/cocoa-networking/Chat Core/MVIRCChatConnection.m
r3088 r3093 1 #import <sched.h> 2 1 3 #import "MVIRCChatConnection.h" 2 4 #import "MVIRCChatRoom.h" … … 5 7 6 8 #import "AsyncSocket.h" 9 #import "InterThreadMessaging.h" 7 10 #import "MVChatPluginManager.h" 8 11 #import "NSAttributedStringAdditions.h" … … 717 720 [self disconnect]; 718 721 722 [_chatConnection release]; 719 723 [_knownUsers release]; 724 [_proxyUsername release]; 725 [_proxyPassword release]; 726 727 _chatConnection = nil; 728 _connectionThread = nil; 720 729 _knownUsers = nil; 721 722 [_proxyUsername release];723 730 _proxyUsername = nil; 724 725 [_proxyPassword release];726 731 _proxyPassword = nil; 727 732 … … 764 769 [self _willConnect]; // call early so other code has a chance to change our info 765 770 766 if( ! [_chatConnection connectToHost:[self server] onPort:[self serverPort] error:NULL] ) 767 [self _didNotConnect]; 771 if( ! _connectionThread ) { 772 [NSThread prepareForInterThreadMessages]; 773 [NSThread detachNewThreadSelector:@selector( _ircRunloop ) toTarget:self withObject:nil]; 774 while( ! _connectionThread ) sched_yield(); 775 } 776 777 [self performSelector:@selector( _connect ) inThread:_connectionThread]; 768 778 769 779 /* … … 795 805 } 796 806 797 [_chatConnection disconnectAfterWriting]; 807 _status = MVChatConnectionDisconnectedStatus; 808 [_chatConnection performSelector:@selector( disconnectAfterWriting ) inThread:_connectionThread]; 798 809 } 799 810 … … 988 999 [data appendBytes:"\x0D\x0A" length:2]; 989 1000 990 [ _chatConnection writeData:data withTimeout:-1. tag:0];1001 [self performSelector:@selector( _writeDataToServer: ) withObject:data inThread:_connectionThread]; 991 1002 992 1003 [[NSNotificationCenter defaultCenter] postNotificationName:MVChatConnectionGotRawMessageNotification object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:string, @"message", [NSNumber numberWithBool:YES], @"outbound", nil]]; … … 1123 1134 1124 1135 @implementation MVIRCChatConnection (MVIRCChatConnectionPrivate) 1125 - (oneway void) _connectionRunloop { 1136 - (void) _connect { 1137 [_chatConnection disconnect]; 1138 if( ! [_chatConnection connectToHost:[self server] onPort:[self serverPort] error:NULL] ) 1139 [self _didNotConnect]; 1140 } 1141 1142 - (oneway void) _ircRunloop { 1143 NSAutoreleasePool *pool = [[NSAutoreleasePool allocWithZone:nil] init]; 1144 1145 _connectionThread = [NSThread currentThread]; 1146 [NSThread prepareForInterThreadMessages]; 1147 1148 // BOOL active = YES; 1149 // while( active && ( _status == MVChatConnectionConnectedStatus || _status == MVChatConnectionConnectingStatus ) ) 1150 // active = [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; 1126 1151 [[NSRunLoop currentRunLoop] run]; 1152 1153 _connectionThread = nil; 1154 1155 [pool release]; 1156 } 1157 1158 - (void) _didDisconnect { 1159 if( ABS( [_lastConnectAttempt timeIntervalSinceNow] ) > 300. ) 1160 [self performSelector:@selector( connect ) withObject:nil afterDelay:5.]; 1161 [self scheduleReconnectAttemptEvery:30.]; 1162 [super _didDisconnect]; 1127 1163 } 1128 1164 … … 1130 1166 NSLog(@"willDisconnectWithError: %@", error ); 1131 1167 _status = MVChatConnectionServerDisconnectedStatus; 1132 if( ABS( [_lastConnectAttempt timeIntervalSinceNow] ) > 300. )1133 [self performSelector:@selector( connect ) withObject:nil afterDelay:5.];1134 [self scheduleReconnectAttemptEvery:30.];1135 1168 } 1136 1169 1137 1170 - (void) socketDidDisconnect:(AsyncSocket *) sock { 1138 if( _status != MVChatConnectionServerDisconnectedStatus )1139 _status = MVChatConnectionDisconnectedStatus;1140 1141 1171 id old = _localUser; 1142 1172 _localUser = nil; 1143 1173 [old release]; 1144 1174 1145 [self _didDisconnect];1175 [self performSelectorOnMainThread:@selector( _didDisconnect ) withObject:nil waitUntilDone:NO]; 1146 1176 } 1147 1177 … … 1155 1185 [old release]; 1156 1186 1157 [self _didConnect];1187 [self performSelectorOnMainThread:@selector( _didConnect ) withObject:nil waitUntilDone:NO]; 1158 1188 [self _readNextMessageFromServer]; 1159 1189 } … … 1291 1321 1292 1322 [self _readNextMessageFromServer]; 1323 } 1324 1325 - (void) _writeDataToServer:(NSData *) data { 1326 [_chatConnection writeData:data withTimeout:-1. tag:0]; 1293 1327 } 1294 1328 … … 1510 1544 if( ! [self nicknamePassword] ) { 1511 1545 [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionNeedNicknamePasswordNotification object:self userInfo:nil]; 1512 } else [self sendRawMessageWithFormat:@"PRIVMSG %@ :IDENTIFY %@", [self nickname], [self nicknamePassword]];1546 } else [self sendRawMessageWithFormat:@"PRIVMSG NickServ :IDENTIFY %@", [self nicknamePassword]]; 1513 1547 } else if( [msg rangeOfString:@"Password accepted"].location != NSNotFound ) { 1514 1548 [[self localUser] _setIdentified:YES];
