且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iPhone上的TCP连接上禁用Nagle算法

更新时间:2023-02-06 22:44:12

不保证这会解决您的问题,但如果您想要要禁用Nagle算法,您需要从流中获取本机套接字并调用 setsockopt

No guarantee this will fix your problem, but if you want to disable the Nagle algorithm, you need to get the native socket from the stream and call setsockopt.

CFDataRef nativeSocket = CFWriteStreamCopyProperty(myWriteStream, kCFStreamPropertySocketNativeHandle);
CFSocketNativeHandle *sock = (CFSocketNativeHandle *)CFDataGetBytePtr(nativeSocket);
setsockopt(*sock, IPPROTO_TCP, TCP_NODELAY, &(int){ 1 }, sizeof(int));
CFRelease(nativeSocket);

(对于复合文字技巧。)