Add -[asyncConnectAndHandle].
This commit is contained in:
parent
00a064a4a5
commit
4978c42916
3 changed files with 76 additions and 6 deletions
|
@ -261,6 +261,12 @@
|
||||||
*/
|
*/
|
||||||
- (void)handleConnection;
|
- (void)handleConnection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Asynchronously connects to the server and adds the connection to the
|
||||||
|
* run loop.
|
||||||
|
*/
|
||||||
|
- (void)asyncConnectAndHandle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Parses the specified buffer.
|
* \brief Parses the specified buffer.
|
||||||
*
|
*
|
||||||
|
|
|
@ -58,6 +58,64 @@
|
||||||
|
|
||||||
#define BUFFER_LENGTH 512
|
#define BUFFER_LENGTH 512
|
||||||
|
|
||||||
|
@interface XMPPConnection_ConnectThread: OFThread
|
||||||
|
{
|
||||||
|
OFThread *sourceThread;
|
||||||
|
XMPPConnection *connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
- initWithSourceThread: (OFThread*)sourceThread
|
||||||
|
connection: (XMPPConnection*)connection;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation XMPPConnection_ConnectThread
|
||||||
|
- initWithSourceThread: (OFThread*)sourceThread_
|
||||||
|
connection: (XMPPConnection*)connection_
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
@try {
|
||||||
|
sourceThread = [sourceThread_ retain];
|
||||||
|
connection = [connection_ retain];
|
||||||
|
} @catch (id e) {
|
||||||
|
[self release];
|
||||||
|
@throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
[sourceThread release];
|
||||||
|
[connection release];
|
||||||
|
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)didConnect
|
||||||
|
{
|
||||||
|
[self join];
|
||||||
|
|
||||||
|
[connection handleConnection];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)main
|
||||||
|
{
|
||||||
|
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
[connection connect];
|
||||||
|
|
||||||
|
[self performSelector: @selector(didConnect)
|
||||||
|
onThread: sourceThread
|
||||||
|
waitUntilDone: NO];
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation XMPPConnection
|
@implementation XMPPConnection
|
||||||
+ connection
|
+ connection
|
||||||
{
|
{
|
||||||
|
@ -308,6 +366,17 @@
|
||||||
exception:)];
|
exception:)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)asyncConnectAndHandle
|
||||||
|
{
|
||||||
|
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
[[[[XMPPConnection_ConnectThread alloc]
|
||||||
|
initWithSourceThread: [OFThread currentThread]
|
||||||
|
connection: self] autorelease] start];
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)XMPP_parseBuffer: (const void*)buffer
|
- (BOOL)XMPP_parseBuffer: (const void*)buffer
|
||||||
length: (size_t)length
|
length: (size_t)length
|
||||||
{
|
{
|
||||||
|
|
|
@ -117,12 +117,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
[conn setPassword: [arguments objectAtIndex: 2]];
|
[conn setPassword: [arguments objectAtIndex: 2]];
|
||||||
[conn setResource: @"ObjXMPP"];
|
[conn setResource: @"ObjXMPP"];
|
||||||
|
|
||||||
@try {
|
[conn asyncConnectAndHandle];
|
||||||
[conn connect];
|
|
||||||
[conn handleConnection];
|
|
||||||
} @catch (id e) {
|
|
||||||
of_log(@"%@", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (void)connection: (XMPPConnection*)conn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue