Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/io/source/connector/ctr_pipe.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <sal/config.h>
21
22
#include <com/sun/star/io/IOException.hpp>
23
24
#include "connector.hxx"
25
#include <osl/pipe.hxx>
26
#include <utility>
27
28
using namespace ::osl;
29
using namespace ::com::sun::star::uno;
30
using namespace ::com::sun::star::io;
31
using namespace ::com::sun::star::connection;
32
33
34
namespace stoc_connector {
35
36
    PipeConnection::PipeConnection( OUString sConnectionDescription ) :
37
0
        m_nStatus( 0 ),
38
0
        m_sDescription(std::move( sConnectionDescription ))
39
0
    {
40
        // make it unique
41
0
        m_sDescription += ",uniqueValue=";
42
0
        m_sDescription += OUString::number(
43
0
            sal::static_int_cast< sal_Int64 >(
44
0
                reinterpret_cast< sal_IntPtr >(&m_pipe)) );
45
0
    }
46
47
    PipeConnection::~PipeConnection()
48
0
    {
49
0
    }
50
51
    sal_Int32 PipeConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead )
52
0
    {
53
0
        if( m_nStatus )
54
0
        {
55
0
            throw IOException(u"pipe already closed"_ustr);
56
0
        }
57
0
        if( aReadBytes.getLength() != nBytesToRead )
58
0
        {
59
0
            aReadBytes.realloc( nBytesToRead );
60
0
        }
61
0
        return m_pipe.read( aReadBytes.getArray()  , aReadBytes.getLength() );
62
63
0
    }
64
65
    void PipeConnection::write( const Sequence < sal_Int8 > &seq )
66
0
    {
67
0
        if( m_nStatus )
68
0
        {
69
0
            throw IOException(u"pipe already closed"_ustr);
70
0
        }
71
0
        if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() )
72
0
        {
73
0
            throw IOException(u"short write"_ustr);
74
0
        }
75
0
    }
76
77
    void PipeConnection::flush( )
78
0
    {
79
80
0
    }
81
82
    void PipeConnection::close()
83
0
    {
84
        // ensure that close is called only once
85
0
        if(1 == osl_atomic_increment( (&m_nStatus) ) )
86
0
        {
87
0
            m_pipe.close();
88
0
        }
89
0
    }
90
91
    OUString PipeConnection::getDescription()
92
0
    {
93
0
        return m_sDescription;
94
0
    }
95
96
}
97
98
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */