Seems like the title is self descriptive. I want to increase the speed of sending and receiving data in my app and i was told to set tcp_nodelay to true. But i have no idea how to do that with GCDAsyncSocket. Can anyone help me?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I haven't used GCDAsyncSocket, but "GCDAsyncSocket.h" shows that you can get the underlying socket descriptor with the socketFD
method, which must be called only in a performBlock:
call. So the following code might work:
[asyncSocket performBlock:^{
int fd = [asyncSocket socketFD];
int on = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on)) == -1) {
/* handle error */
}
}];
You might have to add
#include <netinet/tcp.h>
#include <netinet/in.h>
to your source file to compile this. As I said, I haven't tried this, but perhaps it helps to point you in the right direction.