CFNetwork 仍然传递 CFStreamErrors 即使​​它已被弃用?

发布于 2024-08-21 12:47:53 字数 1501 浏览 5 评论 0原文

我正在编写一些代码,其中包含一些 CFNetwork 内容,以便在 Objective-C 中进行 DNS 解析。

一切都很好并且工作正常,但我有几个问题:

CFHost 异步解析的回调函数原型正在传递对 CFStreamError 结构的引用,即使文档说 < code>CFStreamError 已弃用,应使用 CFReadStreamCopyError 代替,它将返回 CFError 结构。

回调函数是这样声明的:

typedef void (CFHostClientCallBack) (
    CFHostRef theHost,
    CFHostInfoType typeInfo,
    const CFStreamError *error,
    void *info);

对于使用未弃用的 API 的回调,似乎没有任何替代方案。

我认为弃用 API 的目的是引入新的 API 来取代旧的 API?如果这是真的,为什么没有使用 CFReadStreamCopyError 函数的替代回调?

我遇到的主要问题是 CFStreamErrors 确实不伦不类...我能做些什么来将 CFStreamError 变成 CFError 吗?


只是为了澄清几点:

我不相信我在这一点上误读了文档。 CFHosts 异步解析系统中使用的回调方法会传入 CFStreamError。虽然 CFStreamError 本身可能不会被弃用,但返回它们的函数,即 CFReadStreamGetErrorCFWriteStreamGetError 已被弃用。该文档建议使用 CFReadStreamCopyErrorCFWriteStreamCopyError ,它们返回 CFError 而不是 CFStreamError

我将这段代码封装在 Objective-C 中,并大量使用 Foundation 对象。因此,CFError 对我来说比 CFStreamError 有用得多,因为它与 NSErrorCFStreamErrors 免费桥接code> 不包含与 CFError 一样多的有用信息。此外,我什至没有直接处理 CFStream,那么为什么我必须处理它的特定错误结构呢?最后,我想最终在包装类的委托回调中返回一个 NSError

另外,我知道弃用并不立即意味着该方法消失了,但如果某些东西被标记为弃用,那么提供替代方案是有意义的(至少对我来说)。否则,已弃用的方法/函数/类等仍在使用,并且在有东西取代它之前没有意义弃用它?

I'm writing some code that is wrapping up some CFNetwork stuff to do DNS resolution in Objective-C.

Everything is fine and it's working, but I have a few questions:

The callback function prototype for CFHost's asynchronous resolution is passing references to CFStreamError structures even though the documentation says CFStreamError is deprecated and CFReadStreamCopyError should be used instead, which will return a CFError struct.

The callback function is declared as such:

typedef void (CFHostClientCallBack) (
    CFHostRef theHost,
    CFHostInfoType typeInfo,
    const CFStreamError *error,
    void *info);

There doesn't seem to be any alternative to this callback that uses non-deprecated APIs.

I thought the point of deprecating API's was that new ones were introduced that supersede the older ones? If this is true, why isn't there an alternative callback to this one that makes use of the CFReadStreamCopyError function?

The main problem I'm having that CFStreamErrors are really nondescript... Is there anything I can do to turn a CFStreamError into a CFError?


Just to clarify a few points:

I don't believe I've misread the documentation on this point. the callback method used in CFHosts asynchronous resolution system passes in a CFStreamError. While CFStreamError itself may not be deprecated, the functions that return them, namely CFReadStreamGetError and CFWriteStreamGetError are deprecated. The documentation suggests using CFReadStreamCopyError and CFWriteStreamCopyError which return CFError instead of CFStreamError.

I am wrapping this code in Objective-C and I'm making a lot of use of Foundation objects. as such, CFError is a lot more useful to me than CFStreamError is because it's toll-free bridged with NSError and CFStreamErrors don't contain nearly as much useful information as a CFError does. Further, I'm not even dealing with a CFStream directly, so why should I have to deal with its specific error struct? Finally, I want to ultimately return an NSError in a delegate call back in my wrapper class.

Also, I know that deprecation doesn't instantly mean the method is gone, but if something is marked as deprecated, it would make sense (to me at least) to provide an alternative. Otherwise, the deprecated method/function/class etc, is still being used and there's no point in deprecating it until something supersedes it?

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

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

发布评论

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

评论(2

他夏了夏天 2024-08-28 12:47:53

CFStreamError 结构实际上并未被弃用。从文档来看,它将出现在下一个版本中(因为他们不赞成返回它的方法)。然而,目前看来您仍然需要处理结构本身,因为尚未进行替换回调。

我意识到这不是您正在寻找的答案类型,但是 CFStreamError 实际上还没有完全弃用,因此您无法替代它的所有用途。

The CFStreamError struct is not actually deprecated. From the documentation, it looks like it will be in the next release (since they're deprecating methods that return it). For now, however, it looks like you will still have to deal with the struct itself, as no replacement callback has been made.

I realize this isn't the type of answer you were looking for, but the CFStreamError really hasn't been fully deprecated yet, so you won't have replacements for all uses of it.

南冥有猫 2024-08-28 12:47:53

已弃用意味着它计划过时。这适用于苹果的软件工程师以及第三方软件开发人员。

另外,您误读了文档。该结构由函数返回 CFReadStreamGetError。该文档建议使用新的 API 函数,而不是建议使用新的错误结构。

Deprecated means it is planned to become obsolete. This is meant for Apple's software engineers as well as third-party software developers.

Also, you are misreading the documentation. The struct is returned by the function CFReadStreamGetError. The documentation is suggesting new API functions to use, not a new error struct to use.

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