components/webclient/src/webclient.c
int webclient_write(struct webclient_session *session, const unsigned char *buffer, size_t length)
{
    int bytes_write = 0;
    int total_write = 0;
    int left = length;

    if (!session)
    {
        return WEBCLIENT_ERROR;
    }

    if (session->socket < 0)
    {
        return -WEBCLIENT_DISCONNECT;
    }

    if (length == 0)
    {
        return 0;
    }
    //LOGI(TAG, "%s, %d, length = %d\n", __FUNCTION__, __LINE__, length);

    /* send all of data on the buffer. */
    do
    {
        //LOGI(TAG, "%s, line = %d\n", __FUNCTION__, __LINE__);
        bytes_write = webclient_send(session, buffer + total_write, left, 0);
        //LOGI(TAG, "%s, line = %d, bytes_write = %d, errno = %d\n", __FUNCTION__, __LINE__, bytes_write, errno);
        if (bytes_write <= 0)
        {
#ifdef WEBCLIENT_USING_TLS
            if (session->tls_session && bytes_write == MBEDTLS_ERR_SSL_WANT_WRITE)
                continue;
#endif
            if (errno == EWOULDBLOCK || errno == EAGAIN)
            {
                /* send timeout */
                if (total_write)
                {
                    return total_write;
                }
                continue;
                /* TODO: whether return the TIMEOUT
                 * return -WEBCLIENT_TIMEOUT; */
            }
            else
            {
                closesocket(session->socket);
                session->socket = -1;

                if (total_write == 0)
                {
                    return -WEBCLIENT_DISCONNECT;
                }
                break;
            }
        }

        left -= bytes_write;
        total_write += bytes_write;
    } while (left);

    return total_write;
}
/**
 *  write data to http server.
 *
 * @param session http session
 * @param buffer write buffer
 * @param length write buffer size
 *
 * @return <0: write data error
 *         =0: http server disconnect
 *         >0: successfully write data length
 */
write data to http server.
@param session http session
@param buffer write buffer
@param length write buffer size

@return <0: write data error
=0: http server disconnect
>0: successfully write data length
write data to http server . @param session http session @param buffer write buffer @param length write buffer size @return <0 : write data error = 0 : http server disconnect > 0 : successfully write data length
int webclient_write(struct webclient_session *session, const unsigned char *buffer, size_t length)
{
    int bytes_write = 0;
    int total_write = 0;
    int left = length;
    if (!session)
    {
        return WEBCLIENT_ERROR;
    }
    if (session->socket < 0)
    {
        return -WEBCLIENT_DISCONNECT;
    }
    if (length == 0)
    {
        return 0;
    }
    do
    {
        bytes_write = webclient_send(session, buffer + total_write, left, 0);
        if (bytes_write <= 0)
        {
#ifdef WEBCLIENT_USING_TLS
            if (session->tls_session && bytes_write == MBEDTLS_ERR_SSL_WANT_WRITE)
                continue;
#endif
            if (errno == EWOULDBLOCK || errno == EAGAIN)
            {
                if (total_write)
                {
                    return total_write;
                }
                continue;
            }
            else
            {
                closesocket(session->socket);
                session->socket = -1;
                if (total_write == 0)
                {
                    return -WEBCLIENT_DISCONNECT;
                }
                break;
            }
        }
        left -= bytes_write;
        total_write += bytes_write;
    } while (left);
    return total_write;
}
int webclient_write ( struct webclient_session * session , const unsigned char * buffer , size_t length ) { int bytes_write = 0 ; int total_write = 0 ; int left = length ; if ( ! session ) { return WEBCLIENT_ERROR ; } if ( session -> socket < 0 ) { return - WEBCLIENT_DISCONNECT ; } if ( length == 0 ) { return 0 ; } do { bytes_write = webclient_send ( session , buffer + total_write , left , 0 ) ; if ( bytes_write <= 0 ) { #ifdef WEBCLIENT_USING_TLS if ( session -> tls_session && bytes_write == MBEDTLS_ERR_SSL_WANT_WRITE ) continue ; #endif if ( errno == EWOULDBLOCK || errno == EAGAIN ) { if ( total_write ) { return total_write ; } continue ; } else { closesocket ( session -> socket ) ; session -> socket = -1 ; if ( total_write == 0 ) { return - WEBCLIENT_DISCONNECT ; } break ; } } left -= bytes_write ; total_write += bytes_write ; } while ( left ) ; return total_write ; }
write data to http server.
write data to http server .
//LOGI(TAG, "%s, %d, length = %d\n", __FUNCTION__, __LINE__, length); /* send all of data on the buffer. */ //LOGI(TAG, "%s, line = %d\n", __FUNCTION__, __LINE__); //LOGI(TAG, "%s, line = %d, bytes_write = %d, errno = %d\n", __FUNCTION__, __LINE__, bytes_write, errno); /* send timeout */ /* TODO: whether return the TIMEOUT
                 * return -WEBCLIENT_TIMEOUT; */