当使用流调度时,Runloop 不会被触发

发布于 2024-11-16 09:00:18 字数 1351 浏览 2 评论 0原文

我目前正在为我的项目开发一个 FTP 客户端。我已经使用运行循环安排了 readstream/writeStream 从硬盘读取文件/将文件写入硬盘并将其发送到服务器。上传和下载文件后,我从运行循环中取消安排流。我第一次发送文件时效果很好。当我第二次尝试发送文件时。流是通过运行循环创建和调度的。但运行循环不会触发。我不知道。任何人都可以帮助我

下载的代码

以下是我用来安排和取消安排上传

readStream=CFReadStreamCreateWithFile(kCFAllocatorDefault, fileURL);
writeStream=CFWriteStreamCreateWithFTPURL(kCFAllocatorDefault,(CFURLRef ) ftpURL);
BOOL readStreamOpened=CFReadStreamOpen(readStream);
BOOL clientCallBackSet=CFWriteStreamSetClient(writeStream, kNetworkEvents, MyUploadCallBack, &callBackContext);

CFWriteStreamScheduleWithRunLoop(writeStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFReadStreamUnscheduleFromRunLoop(syncStructure->readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);

readStream=CFReadStreamCreateWithFTPURL(kCFAllocatorDefault,(CFURLRef)ftpURL);
writeStream=CFWriteStreamCreateWithFile(kCFAllocatorDefault,fileURL);
Boolean writeStreamOpened=CFWriteStreamOpen(writeStream);
BOOL status= CFReadStreamSetClient(readStream, kNetworkEvents,MyDownloadCallBack,& callBackContext);
CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFWriteStreamUnscheduleFromRunLoop(syncStructure->writeStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);

任何人都可以帮助我吗?我已经绞尽脑汁两天了。

I'm currently doing a FTP client for my project. I've scheduled the readstream/writeStream with the runloop to read the file from the harddisk/write the file to the harddisk and send it to the server. After uploading and downloading the file I unschedule the stream from the runloop. This works fine for the first time I send the file. The second time when i try to send the file. Streams are getting created and scheduled with the run loop. But run loop doesnt fire. I don know. Can anyone please help me out

Below are the codes that I used to schedule and unschedule

For uploading

readStream=CFReadStreamCreateWithFile(kCFAllocatorDefault, fileURL);
writeStream=CFWriteStreamCreateWithFTPURL(kCFAllocatorDefault,(CFURLRef ) ftpURL);
BOOL readStreamOpened=CFReadStreamOpen(readStream);
BOOL clientCallBackSet=CFWriteStreamSetClient(writeStream, kNetworkEvents, MyUploadCallBack, &callBackContext);

CFWriteStreamScheduleWithRunLoop(writeStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFReadStreamUnscheduleFromRunLoop(syncStructure->readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);

Downloading:

readStream=CFReadStreamCreateWithFTPURL(kCFAllocatorDefault,(CFURLRef)ftpURL);
writeStream=CFWriteStreamCreateWithFile(kCFAllocatorDefault,fileURL);
Boolean writeStreamOpened=CFWriteStreamOpen(writeStream);
BOOL status= CFReadStreamSetClient(readStream, kNetworkEvents,MyDownloadCallBack,& callBackContext);
CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFWriteStreamUnscheduleFromRunLoop(syncStructure->writeStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);

Can anyone please help me. I`m cracking my head for 2 days.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高冷爸爸 2024-11-23 09:00:18

几天后,我解决了这个问题。我使用参考指南中提到的轮询方法检查了代码。当我这样做时,我注意到问题出在我的 ftp 服务器中的超时设置。服务器超时后,它不接受任何连接,因此我的运行循环正在等待调用回调函数

After a couple of days, I solved the problem. I checked the code using the method of polling mentioned in the reference guide. When I did that I noticed the problem was with the timeout setting in my ftp server. After the servers time out, It didnt accept any connection hence my runloop was waiting to call the callback function

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文