<commit_before>//
// Copyright (c) 2018 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation.  All rights reserved.
// See LICENSE file in the project root for full license information.
//

#include <ssl.h> 
#include "mbedtls.h"

int  ssl_write_internal( int sd, const char* Data, size_t req_len)
{
    (void)sd;
    (void)Data;
    (void)req_len;

    mbedtls_ssl_context *pSsl = (mbedtls_ssl_context*)SOCKET_DRIVER.GetSocketSslData(sd);
    int ret;

    // Loop until all data has been sent or error
    size_t req_offset = 0;
    do {
        ret = mbedtls_ssl_write( pSsl, (const unsigned char *)(Data + req_offset), req_len - req_offset);
        if (ret > 0)
            req_offset += static_cast<size_t>(ret);
    }
    while( req_offset < req_len &&
           (ret > 0 ||
           ret == MBEDTLS_ERR_SSL_WANT_WRITE ||
           ret == MBEDTLS_ERR_SSL_WANT_READ) );

    if (ret < 0) {
        //mbedtls_printf("mbedtls_ssl_write() returned -0x%04X\n", -ret);
        return 0;
    } 

    return req_len;
}<commit_msg>Fix mbed TLS implementation of ssl_write_internal<commit_after>//
// Copyright (c) 2018 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation.  All rights reserved.
// See LICENSE file in the project root for full license information.
//

#include <ssl.h> 
#include "mbedtls.h"

int  ssl_write_internal( int sd, const char* data, size_t req_len)
{
    mbedTLS_NFContext* context= (mbedTLS_NFContext*)SOCKET_DRIVER.GetSocketSslData(sd);
    mbedtls_ssl_context *ssl = context->ssl;

    int ret;

    // Loop until all data has been sent or error
    size_t req_offset = 0;
    do {
        ret = mbedtls_ssl_write( ssl, (const unsigned char *)(data + req_offset), req_len - req_offset);
        if (ret > 0)
            req_offset += static_cast<size_t>(ret);
    }
    while( req_offset < req_len &&
           (ret > 0 ||
           ret == MBEDTLS_ERR_SSL_WANT_WRITE ||
           ret == MBEDTLS_ERR_SSL_WANT_READ) );

    if (ret < 0) {
        //mbedtls_printf("mbedtls_ssl_write() returned -0x%04X\n", -ret);
        return 0;
    } 

    return req_len;
}
{'fraction_non_alphanumeric': 0.11023622047244094, 'fraction_numerical': 0.0111162575266327, 'mean_word_length': 2.796133567662566, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1457938', 'n_tokens_mistral': 767, 'n_tokens_neox': 728, 'n_words': 197}