如何在iPhone上增加TCP“接收窗口”

时间:2012-05-13 20:16:23

标签: objective-c c sockets tcp

我似乎只能接收8k字节的最大流大小。在那之后它疯狂了。我怎么能放大这个? THX

    host = gethostbyname("xxx"); 

    memcpy(&(sin.sin_addr), host->h_addr, host->h_length);
    sin.sin_family = host->h_addrtype;
    sin.sin_port = htons(4000);

    s = socket(AF_INET, SOCK_STREAM, 0);
    hConnect = connect(s, (struct sockaddr*)&sin, sizeof(sin));


    char buffer[8000];// tried setting higher,  doesn't change anything
    memset(buffer, '\0', 8000);
    recv(s, buffer, sizeof(buffer), 0); // <------8k max,  need 64k

1 个答案:

答案 0 :(得分:1)

这是读取64KiB的代码:

char* buffer = malloc(65536);
int len = 0;
while (len < 65536)
{
    int rc = recv(s, buffer + len, 65536 - len, 0);
    if (rc == 0)
        break; // connection closed
    else if (rc > 0)
        len += rc;
    else if (errno != EINTR)
    {
        // handle error
        break;
    }
}