页: 1 O_EXLOCK approach, Packped into an NSFileHandle for Lip (-initWithFileDescriptor:
). 与此类似(未测试;未完成):
写作:
int fd = open([path UTF8String], O_TRUNC|O_EXLOCK);
if (fd >= 0)
{
NSFileHandle *fh = [[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc:YES];
[fh writeData:xmlData]; // Creating xmlData left as exercise for the reader
[fh release];
}
else // Error stuff
阅读:
int fd = open([path UTF8String], O_RDONLY|O_SHLOCK);
if (fd >= 0)
{
NSFileHandle *fh = [[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc:YES];
NSData *xmlData = [fh readDataToEndOfFile];
[fh release];
}
else // Error stuff
当然,这将会阻碍,因此,你需要使用O_NONBLOCK,或将其置于一个非倡议的深处,这样,德国马克的 app就 t。
你与O_EXLOCK再次看到的问题是什么?