0

我似乎只能接收 8k 字节的最大流大小。在那之后就废了。我怎样才能放大这个?谢谢

    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
4

1 回答 1

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;
    }
}
于 2012-05-13T20:39:15.910 回答