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.
39 /** Does not create a pipe. Use assignment operator to
40 make this a useable pipe.
44 /** Creates an insecure pipe that is accessible for all users.
48 inline Pipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
);
50 /** Creates a secure pipe that access depends on the umask settings.
55 inline Pipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
,const Security
& rSecurity
);
59 inline Pipe(const Pipe
& pipe
);
61 #if defined LIBO_INTERNAL_ONLY
62 inline Pipe(Pipe
&& other
);
65 /** Constructs a Pipe reference without acquiring the handle
67 inline Pipe( oslPipe pipe
, __sal_NoAcquire noacquire
);
69 /** Creates pipe as wrapper around the underlying oslPipe.
72 inline Pipe(oslPipe Pipe
);
74 /** Destructor. Destroys the underlying oslPipe.
78 inline bool SAL_CALL
is() const;
80 /** Creates an insecure pipe that is accessible for all users
81 with the given attributes.
82 If the pipe was already created, the old one will be discarded.
86 @return True if socket was successfully created.
88 inline bool create( const ::rtl::OUString
& strName
,
89 oslPipeOptions Options
, const Security
&rSec
);
91 /** Creates a secure that access rights depend on the umask settings
92 with the given attributes.
94 If socket was already created, the old one will be discarded.
97 @return True if socket was successfully created.
99 inline bool create( const ::rtl::OUString
& strName
, oslPipeOptions Options
= osl_Pipe_OPEN
);
101 /** releases the underlying handle
103 inline void SAL_CALL
clear();
105 /** Assignment operator. If pipe was already created, the old one will
108 inline Pipe
& SAL_CALL
operator= (const Pipe
& pipe
);
110 #if defined LIBO_INTERNAL_ONLY
111 inline Pipe
& operator =(Pipe
&& other
);
114 /** Assignment operator. If pipe was already created, the old one will
117 inline Pipe
& SAL_CALL
operator= (const oslPipe pipe
);
119 /** Checks if the pipe is valid.
120 @return True if the object represents a valid pipe.
122 inline bool SAL_CALL
isValid() const;
124 inline bool SAL_CALL
operator==( const Pipe
& rPipe
) const;
128 inline void SAL_CALL
close();
130 /** Accept connection on an existing pipe
132 inline oslPipeError SAL_CALL
accept(StreamPipe
& Connection
);
135 /** Delivers a constant describing the last error for the pipe system.
136 @return ENONE if no error occurred, invalid_PipeError if
137 an unknown (unmapped) error occurred, otherwise an enum describing the
140 inline oslPipeError SAL_CALL
getError() const;
142 inline oslPipe SAL_CALL
getHandle() const;
145 /** A pipe to send or receive a stream of data.
147 class StreamPipe
: public Pipe
151 /** Creates an unattached pipe. You must attach the pipe to an oslPipe
152 e.g. by using the operator=(oslPipe), before you can use the stream-
153 functionality of the object.
157 /** Creates pipe as wrapper around the underlying oslPipe.
160 inline StreamPipe(oslPipe Pipe
);
162 /** Copy constructor.
165 inline StreamPipe(const StreamPipe
& Pipe
);
171 inline StreamPipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
= osl_Pipe_OPEN
);
178 inline StreamPipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
, const Security
&rSec
);
180 /** Constructs a Pipe reference without acquiring the handle
182 inline StreamPipe( oslPipe pipe
, __sal_NoAcquire noacquire
);
184 /** Attaches the oslPipe to this object. If the object
185 already was attached to an oslPipe, the old one will
186 be closed and destroyed.
189 inline StreamPipe
& SAL_CALL
operator=(oslPipe Pipe
);
191 /** Assignment operator
193 inline StreamPipe
& SAL_CALL
operator=(const Pipe
& pipe
);
195 /** Tries to receives BytesToRead data from the connected pipe,
197 @param pBuffer [out] Points to a buffer that will be filled with the received
199 @param BytesToRead [in] The number of bytes to read. pBuffer must have at least
201 @return the number of received bytes.
203 inline sal_Int32 SAL_CALL
recv(void* pBuffer
, sal_Int32 BytesToRead
) const;
205 /** Tries to sends BytesToSend data from the connected pipe.
207 @param pBuffer [in] Points to a buffer that contains the send-data.
208 @param BytesToSend [in] The number of bytes to send. pBuffer must have at least
210 @return the number of transferred bytes.
212 inline sal_Int32 SAL_CALL
send(const void* pBuffer
, sal_Int32 BytesToSend
) const;
214 /** Retrieves n bytes from the stream and copies them into pBuffer.
215 The method avoids incomplete reads due to packet boundaries.
216 @param pBuffer receives the read data.
217 @param 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.
226 @param pBuffer contains the data to be written.
227 @param n the number of bytes to write.
228 @return the number of written bytes. The number will only be smaller than
229 n if an exceptional condition (e.g. connection closed) occurs.
231 sal_Int32 SAL_CALL
write(const void* pBuffer
, sal_Int32 n
) const;
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */