三. 执行进展 我发现了一个记忆泄漏问题。 我知道问题在哪里,但不幸的是,我试图解决该问题,但没有成功。 我将努力向各位解释,也许你们的某个人可以帮助这样做。
First I have two classes involved in the issue, the publish class (where publishing the service and socket configuration is done) and the connection (where the socket binding and the streams configuration is done). The main issue is in the connection via native socket. In the publish class the "server" accepts a connection with a callback. The callback has the native-socket information. Then, a connection with native-socket information is created. Next, the socket binding and the streams configuration is done. When those actions are successful the instance of the connection is saved in a mutable array. Thus, the connection is established.
static void AcceptCallback(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) {
Publish *rePoint = (Publish *)info;
if ( type != kCFSocketAcceptCallBack) {
return;
}
CFSocketNativeHandle nativeSocketHandle = *((CFSocketNativeHandle *)data);
NSLog(@"The AcceptCallback was called, a connection request arrived to the server");
[rePoint handleNewNativeSocket:nativeSocketHandle];
}
- (void)handleNewNativeSocket:(CFSocketNativeHandle)nativeSocketHandle{
Connection *connection = [[[Connection alloc] initWithNativeSocketHandle:nativeSocketHandle] autorelease]; // Create the connection
if (connection == nil) {
close(nativeSocketHandle);
return;
}
NSLog(@"The connection from the server was created now try to connect");
if ( ! [connection connect]) {
[connection close];
return;
}
[clients addObject:connection]; //save the connection trying to avoid the deallocation
}
下一步是从客户那里获得信息,因此,根据既定联系信息,可以启动再向下。 但是,当追随者试图利用这一联系时,就会出现错误,他说,这种联系是分配的。 这里的问题是,我不知道联系的地点和时间,不知道联系如何。 我使用了夸张,但经过一些审判后,我看不到更多的信息。
void myReadStreamCallBack (CFReadStreamRef stream, CFStreamEventType eventType, void *info) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Connection *handlerEv = [[(Connection *)info retain] autorelease]; // The error -[Connection retain]: message sent to deallocated instance 0x1f5ef0 (Where 0x1f5ef0 is the reference to the established connection)
[handlerEv readStreamHandleEvent:stream andEvent:eventType];
[pool drain];
}
void myWriteStreamCallBack (CFWriteStreamRef stream, CFStreamEventType eventType, void *info){
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
Connection *handlerEv = [[(Connection *)info retain] autorelease]; //Sometimes the error also happens here, I tried without the pool, but it doesn t help neither.
[handlerEv writeStreamHandleEvent:eventType];
[p drain];
}
令人有些奇怪的是,当我管理着错开(有断点)时,一切都很好,连接没有被分配,接线工作被罚款,服务器能够收到电文。 我将赞赏任何 h!