1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_OSL_PIPE_DECL_HXX
20 #define INCLUDED_OSL_PIPE_DECL_HXX
23 #include "osl/security.hxx"
24 #include "rtl/ustring.hxx"
30 /** Represents a pipe.
38 /** Does not create a pipe. Use assignment operator to
39 make this a usable pipe.
43 /** Creates an insecure pipe that is accessible for all users.
47 inline Pipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
);
49 /** Creates a secure pipe that access depends on the umask settings.
54 inline Pipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
, const Security
& rSecurity
);
58 inline Pipe(const Pipe
& pipe
);
60 #if defined LIBO_INTERNAL_ONLY
61 inline Pipe(Pipe
&& other
) noexcept
;
64 /** Constructs a Pipe reference without acquiring the handle
66 inline Pipe(oslPipe pipe
, __sal_NoAcquire noacquire
);
68 /** Creates pipe as wrapper around the underlying oslPipe.
71 inline Pipe(oslPipe Pipe
);
73 /** Destructor. Destroys the underlying oslPipe.
77 inline bool SAL_CALL
is() const;
79 /** Creates an insecure pipe that is accessible for all users
80 with the given attributes.
81 If the pipe was already created, the old one will be discarded.
85 @return True if socket was successfully created.
87 inline bool create(const ::rtl::OUString
& strName
, oslPipeOptions Options
,
88 const Security
& rSec
);
90 /** Creates a secure that access rights depend on the umask settings
91 with the given attributes.
93 If socket was already created, the old one will be discarded.
96 @return True if socket was successfully created.
98 inline bool create(const ::rtl::OUString
& strName
, oslPipeOptions Options
= osl_Pipe_OPEN
);
100 /** releases the underlying handle
102 inline void SAL_CALL
clear();
104 /** Assignment operator. If pipe was already created, the old one will
107 inline Pipe
& SAL_CALL
operator=(const Pipe
& pipe
);
109 #if defined LIBO_INTERNAL_ONLY
110 inline Pipe
& operator=(Pipe
&& other
) noexcept
;
113 /** Assignment operator. If pipe was already created, the old one will
116 inline Pipe
& SAL_CALL
operator=(const oslPipe pipe
);
118 /** Checks if the pipe is valid.
119 @return True if the object represents a valid pipe.
121 inline bool SAL_CALL
isValid() const;
123 inline bool SAL_CALL
operator==(const Pipe
& rPipe
) const;
127 inline void SAL_CALL
close();
129 /** Accept connection on an existing pipe
131 inline oslPipeError SAL_CALL
accept(StreamPipe
& Connection
);
133 /** Delivers a constant describing the last error for the pipe system.
134 @return ENONE if no error occurred, invalid_PipeError if
135 an unknown (unmapped) error occurred, otherwise an enum describing the
138 inline oslPipeError SAL_CALL
getError() const;
140 inline oslPipe SAL_CALL
getHandle() const;
143 /** A pipe to send or receive a stream of data.
145 class StreamPipe
: public Pipe
148 /** Creates an unattached pipe. You must attach the pipe to an oslPipe
149 e.g. by using the operator=(oslPipe), before you can use the stream-
150 functionality of the object.
154 /** Creates pipe as wrapper around the underlying oslPipe.
158 inline StreamPipe(oslPipe Pipe
);
162 @param[in] strName Pipe name
163 @param[in] Options Pipe options
165 inline StreamPipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
= osl_Pipe_OPEN
);
169 @param[in] strName Pipe name
170 @param[in] Options Pipe options
171 @param[in] rSec Security for the pipe
173 inline StreamPipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
, const Security
& rSec
);
175 /** Constructs a Pipe reference without acquiring the handle
177 inline StreamPipe(oslPipe pipe
, __sal_NoAcquire noacquire
);
179 /** Attaches the oslPipe to this object. If the object
180 already was attached to an oslPipe, the old one will
181 be closed and destroyed.
183 @param[in] Pipe Pipe to attach to this object
185 inline StreamPipe
& SAL_CALL
operator=(oslPipe Pipe
);
187 /** Assignment operator
189 inline StreamPipe
& SAL_CALL
operator=(const Pipe
& pipe
);
191 /** Tries to receives BytesToRead data from the connected pipe,
193 @param[out] pBuffer Points to a buffer that will be filled with the received
195 @param[in] BytesToRead The number of bytes to read. pBuffer must have at least
198 @return the number of received bytes.
200 inline sal_Int32 SAL_CALL
recv(void* pBuffer
, sal_Int32 BytesToRead
) const;
202 /** Tries to sends BytesToSend data from the connected pipe.
204 @param[in] pBuffer Points to a buffer that contains the send-data.
205 @param[in] BytesToSend The number of bytes to send. pBuffer must have at least
208 @return the number of transferred bytes.
210 inline sal_Int32 SAL_CALL
send(const void* pBuffer
, sal_Int32 BytesToSend
) const;
212 /** Retrieves n bytes from the stream and copies them into pBuffer.
213 The method avoids incomplete reads due to packet boundaries.
215 @param[in] pBuffer receives the read data.
216 @param[in] n the number of bytes to read. pBuffer must be large enough
219 @return the number of read bytes. The number will only be smaller than
220 n if an exceptional condition (e.g. connection closed) occurs.
222 inline sal_Int32 SAL_CALL
read(void* pBuffer
, sal_Int32 n
) const;
224 /** Writes n bytes from pBuffer to the stream. The method avoids
225 incomplete writes due to packet boundaries.
227 @param[in] pBuffer contains the data to be written.
228 @param[in] n the number of bytes to write.
230 @return the number of written bytes. The number will only be smaller than
231 n if an exceptional condition (e.g. connection closed) occurs.
233 sal_Int32 SAL_CALL
write(const void* pBuffer
, sal_Int32 n
) const;
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */