<commit_before>// Copyright (c) 2009 - Decho Corp.

#include "mordor/common/pch.h"

#include "handle.h"

#include "mordor/common/exception.h"

HandleStream::HandleStream()
: m_ioManager(NULL),
  m_pos(0),
  m_hFile(INVALID_HANDLE_VALUE),
  m_own(false)
{}

void
HandleStream::init(HANDLE hFile, bool own)
{
    ASSERT(hFile != NULL);
    ASSERT(hFile != INVALID_HANDLE_VALUE);
    m_hFile = hFile;
    m_own = own;
}

void
HandleStream::init(IOManagerIOCP *ioManager, HANDLE hFile, bool own)
{
    init(hFile, own);
    m_ioManager = ioManager;
}

HandleStream::HandleStream(HANDLE hFile, bool own)
: m_ioManager(NULL), m_hFile(hFile), m_own(own)
{
    ASSERT(m_hFile != NULL);
    ASSERT(m_hFile != INVALID_HANDLE_VALUE);
}

HandleStream::HandleStream(IOManagerIOCP &ioManager, HANDLE hFile, bool own)
: m_ioManager(&ioManager), m_pos(0), m_hFile(hFile), m_own(own)
{
    ASSERT(m_hFile != NULL);
    ASSERT(m_hFile != INVALID_HANDLE_VALUE);
    try {
        m_ioManager->registerFile(m_hFile);
    } catch(...) {
        if (own) {
            CloseHandle(m_hFile);
        }
        throw;
    }
}

HandleStream::~HandleStream()
{
    close();
}

void
HandleStream::close(CloseType type)
{
    ASSERT(type == BOTH);
    if (m_hFile != INVALID_HANDLE_VALUE && m_own) {
        if (!CloseHandle(m_hFile)) {
            throwExceptionFromLastError("CloseHandle");
        }
        m_hFile = INVALID_HANDLE_VALUE;
    }
}

size_t
HandleStream::read(Buffer &b, size_t len)
{<commit_msg>Don't throw exception in HandleStream destructor.<commit_after>// Copyright (c) 2009 - Decho Corp.

#include "mordor/common/pch.h"

#include "handle.h"

#include "mordor/common/exception.h"

HandleStream::HandleStream()
: m_ioManager(NULL),
  m_pos(0),
  m_hFile(INVALID_HANDLE_VALUE),
  m_own(false)
{}

void
HandleStream::init(HANDLE hFile, bool own)
{
    ASSERT(hFile != NULL);
    ASSERT(hFile != INVALID_HANDLE_VALUE);
    m_hFile = hFile;
    m_own = own;
}

void
HandleStream::init(IOManagerIOCP *ioManager, HANDLE hFile, bool own)
{
    init(hFile, own);
    m_ioManager = ioManager;
}

HandleStream::HandleStream(HANDLE hFile, bool own)
: m_ioManager(NULL), m_hFile(hFile), m_own(own)
{
    ASSERT(m_hFile != NULL);
    ASSERT(m_hFile != INVALID_HANDLE_VALUE);
}

HandleStream::HandleStream(IOManagerIOCP &ioManager, HANDLE hFile, bool own)
: m_ioManager(&ioManager), m_pos(0), m_hFile(hFile), m_own(own)
{
    ASSERT(m_hFile != NULL);
    ASSERT(m_hFile != INVALID_HANDLE_VALUE);
    try {
        m_ioManager->registerFile(m_hFile);
    } catch(...) {
        if (own) {
            CloseHandle(m_hFile);
        }
        throw;
    }
}

HandleStream::~HandleStream()
{
    if (m_hFile != INVALID_HANDLE_VALUE && m_own) {
        CloseHandle(m_hFile);
    }
}

void
HandleStream::close(CloseType type)
{
    ASSERT(type == BOTH);
    if (m_hFile != INVALID_HANDLE_VALUE && m_own) {
        if (!CloseHandle(m_hFile)) {
            throwExceptionFromLastError("CloseHandle");
        }
        m_hFile = INVALID_HANDLE_VALUE;
    }
}

size_t
HandleStream::read(Buffer &b, size_t len)
{
{'fraction_non_alphanumeric': 0.13882581900746027, 'fraction_numerical': 0.003892312682452157, 'mean_word_length': 3.7083969465648856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3723894', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1156, 'n_words': 197}