Handle the connection in the run loop.
This commit is contained in:
parent
72bc705800
commit
8f2cdce7b4
3 changed files with 53 additions and 19 deletions
|
@ -245,7 +245,7 @@
|
||||||
- (BOOL)checkCertificateAndGetReason: (OFString**)reason;
|
- (BOOL)checkCertificateAndGetReason: (OFString**)reason;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Starts a loop handling incomming data.
|
* \brief Adds the connection to the run loop.
|
||||||
*/
|
*/
|
||||||
- (void)handleConnection;
|
- (void)handleConnection;
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@
|
||||||
* \param length The length of the buffer. If length is 0, it is assumed that
|
* \param length The length of the buffer. If length is 0, it is assumed that
|
||||||
* the connection was closed.
|
* the connection was closed.
|
||||||
*/
|
*/
|
||||||
- (void)parseBuffer: (const char*)buffer
|
- (void)parseBuffer: (const void*)buffer
|
||||||
length: (size_t)length;
|
length: (size_t)length;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -56,6 +56,8 @@
|
||||||
|
|
||||||
#import <ObjFW/macros.h>
|
#import <ObjFW/macros.h>
|
||||||
|
|
||||||
|
#define BUFFER_LENGTH 512
|
||||||
|
|
||||||
@implementation XMPPConnection
|
@implementation XMPPConnection
|
||||||
+ connection
|
+ connection
|
||||||
{
|
{
|
||||||
|
@ -292,27 +294,21 @@
|
||||||
|
|
||||||
- (void)handleConnection
|
- (void)handleConnection
|
||||||
{
|
{
|
||||||
char buffer[512];
|
char *buffer = [self allocMemoryWithSize: BUFFER_LENGTH];
|
||||||
|
|
||||||
for (;;) {
|
[sock asyncReadIntoBuffer: buffer
|
||||||
size_t length = [sock readIntoBuffer: buffer
|
length: BUFFER_LENGTH
|
||||||
length: 512];
|
target: self
|
||||||
|
selector: @selector(stream:didReadIntoBuffer:length:)];
|
||||||
[self parseBuffer: buffer
|
|
||||||
length: length];
|
|
||||||
|
|
||||||
if (length < 1)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)parseBuffer: (const char*)buffer
|
- (BOOL)XMPP_parseBuffer: (const void*)buffer
|
||||||
length: (size_t)length
|
length: (size_t)length
|
||||||
{
|
{
|
||||||
if (length < 1) {
|
if ([sock isAtEndOfStream]) {
|
||||||
[delegates broadcastSelector: @selector(connectionWasClosed:)
|
[delegates broadcastSelector: @selector(connectionWasClosed:)
|
||||||
withObject: self];
|
withObject: self];
|
||||||
return;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
|
@ -322,8 +318,18 @@
|
||||||
[self XMPP_sendStreamError: @"bad-format"
|
[self XMPP_sendStreamError: @"bad-format"
|
||||||
text: nil];
|
text: nil];
|
||||||
[self close];
|
[self close];
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)parseBuffer: (const void*)buffer
|
||||||
|
length: (size_t)length
|
||||||
|
{
|
||||||
|
[self XMPP_parseBuffer: buffer
|
||||||
|
length: length];
|
||||||
|
|
||||||
[oldParser release];
|
[oldParser release];
|
||||||
[oldElementBuilder release];
|
[oldElementBuilder release];
|
||||||
|
|
||||||
|
@ -331,6 +337,33 @@
|
||||||
oldElementBuilder = nil;
|
oldElementBuilder = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)stream: (OFStream*)stream
|
||||||
|
didReadIntoBuffer: (char*)buffer
|
||||||
|
length: (size_t)length
|
||||||
|
{
|
||||||
|
if (![self XMPP_parseBuffer: buffer
|
||||||
|
length: length])
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
if (oldParser != nil || oldElementBuilder != nil) {
|
||||||
|
[oldParser release];
|
||||||
|
[oldElementBuilder release];
|
||||||
|
|
||||||
|
oldParser = nil;
|
||||||
|
oldElementBuilder = nil;
|
||||||
|
|
||||||
|
[sock asyncReadIntoBuffer: buffer
|
||||||
|
length: BUFFER_LENGTH
|
||||||
|
target: self
|
||||||
|
selector: @selector(stream:
|
||||||
|
didReadIntoBuffer:length:)];
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
- (OFTCPSocket*)socket
|
- (OFTCPSocket*)socket
|
||||||
{
|
{
|
||||||
return [[sock retain] autorelease];
|
return [[sock retain] autorelease];
|
||||||
|
|
|
@ -146,7 +146,8 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
wasBoundToJID: (XMPPJID*)jid
|
wasBoundToJID: (XMPPJID*)jid
|
||||||
{
|
{
|
||||||
of_log(@"Bound to JID: %@", [jid fullJID]);
|
of_log(@"Bound to JID: %@", [jid fullJID]);
|
||||||
of_log(@"Supports SM: %@", [conn_ supportsStreamManagement] ? @"YES" : @"NO");
|
of_log(@"Supports SM: %@",
|
||||||
|
[conn_ supportsStreamManagement] ? @"YES" : @"NO");
|
||||||
|
|
||||||
[roster requestRoster];
|
[roster requestRoster];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue