Loc*_*eyu 6 sockets unix-socket ios ios-extensions
我有一些逻辑可以通过创建Unix域套接字来工作,并且在普通应用程序中运行时没有任何问题.但是,当我为app扩展运行时,我从bind()获得了一个带有errno = 48("Address in in use")的-1.
NSArray *applicationSupportDirectoryPaths =
NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES);
int fd = socket(AF_UNIX, SOCK_STREAM, 0); // returns a non-zero value
NSString *loc = [applicationSupportDirectoryPaths[0] stringByAppendingPathComponent:@"usd"];
struct sockaddr_un addr;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX ;
strncpy(addr.sun_path, [loc UTF8String], sizeof(addr.sun_path)-1);
int bindres = bind(fd, (struct sockaddr*)&addr, sizeof(addr)); // returns -1, error is 48
Run Code Online (Sandbox Code Playgroud)
库目录返回的位置是:
/var/mobile/Containers/Data/PluginKitPlugin/A8110BA2-5AE7-42C1-84DA-2A9B303C7277/Library/
Run Code Online (Sandbox Code Playgroud)
我认为这是失败的原因是因为这是一个特殊的位置,与应用程序的库目录相比.
如果有人有任何想法为什么会发生这种情况或任何变通方法,我很感激.
更新:我尝试了缓存目录(NSCachesDirectory),但现在我得到了错误3(没有这样的过程).
归档时间: |
|
查看次数: |
572 次 |
最近记录: |