Versand großer Daten per socket

Ich bin senden von großen Datenmengen (naja... 1Mb) über die Buchse, aber ich weiß nicht, warum die sende-Aktion blockiert das Programm und endet nie. Kleine sendet läuft perfekt und ich konnte nicht finden, wo ist das problem hier. Kann mir jemand helfen, bitte?

Vielen Dank im Voraus für jede Hilfe können Sie zur Verfügung stellen.

int liResult = 1;
int liConnection = 0;
int liSenderOption = 1;
struct addrinfo laiSenderAddrInfo;
struct addrinfo *laiResultSenderAddrInfo;

memset(&laiSenderAddrInfo,0,sizeof(laiSenderAddrInfo));
laiSenderAddrInfo.ai_socktype = SOCK_STREAM;
laiSenderAddrInfo.ai_flags = AI_PASSIVE;

liResult = getaddrinfo(_sIp.c_str(), _sPort.c_str(), &laiSenderAddrInfo, &laiResultSenderAddrInfo);

if (liResult > -1)
{
    liConnection = socket(laiResultSenderAddrInfo->ai_family, SOCK_STREAM, laiResultSenderAddrInfo->ai_protocol);
    liResult = liConnection;

    if (liConnection > -1)
    {
        setsockopt(liConnection, SOL_SOCKET, SO_REUSEADDR, &liSenderOption, sizeof(liSenderOption));
        liResult = connect(liConnection, laiResultSenderAddrInfo->ai_addr, laiResultSenderAddrInfo->ai_addrlen);
    }
}

size_t lBufferSize = psText->length();
long lBytesSent = 1;
unsigned long lSummedBytesSent = 0;

while (lSummedBytesSent < lBufferSize and lBytesSent > 0)
{
    lBytesSent = send(liConnection, psText->c_str() + lSummedBytesSent, lBufferSize - lSummedBytesSent, MSG_NOSIGNAL);

    if (lBytesSent > 0)
    {
        lSummedBytesSent += lBytesSent;
    }
}
InformationsquelleAutor Marc Romero | 2012-10-16
Schreibe einen Kommentar