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 /** Constructs a Pipe reference without acquiring the handle
63 inline Pipe( oslPipe pipe
, __sal_NoAcquire noacquire
);
65 /** Creates pipe as wrapper around the underlying oslPipe.
68 inline Pipe(oslPipe Pipe
);
70 /** Destructor. Destroys the underlying oslPipe.
74 inline bool SAL_CALL
is() const;
76 /** Creates an insecure pipe that is accessible for all users
77 with the given attributes.
78 If the pipe was already created, the old one will be discarded.
82 @return True if socket was successfully created.
84 inline bool create( const ::rtl::OUString
& strName
,
85 oslPipeOptions Options
, const Security
&rSec
);
87 /** Creates a secure that access rights depend on the umask settings
88 with the given attributes.
90 If socket was already created, the old one will be discarded.
93 @return True if socket was successfully created.
95 inline bool create( const ::rtl::OUString
& strName
, oslPipeOptions Options
= osl_Pipe_OPEN
);
97 /** releases the underlying handle
99 inline void SAL_CALL
clear();
101 /** Assignment operator. If pipe was already created, the old one will
104 inline Pipe
& SAL_CALL
operator= (const Pipe
& pipe
);
106 /** Assignment operator. If pipe was already created, the old one will
109 inline Pipe
& SAL_CALL
operator= (const oslPipe pipe
);
111 /** Checks if the pipe is valid.
112 @return True if the object represents a valid pipe.
114 inline bool SAL_CALL
isValid() const;
116 inline bool SAL_CALL
operator==( const Pipe
& rPipe
) const;
120 inline void SAL_CALL
close();
122 /** Accept connection on an existing pipe
124 inline oslPipeError SAL_CALL
accept(StreamPipe
& Connection
);
127 /** Delivers a constant describing the last error for the pipe system.
128 @return ENONE if no error occurred, invalid_PipeError if
129 an unknown (unmapped) error occurred, otherwise an enum describing the
132 inline oslPipeError SAL_CALL
getError() const;
134 inline oslPipe SAL_CALL
getHandle() const;
137 /** A pipe to send or receive a stream of data.
139 class StreamPipe
: public Pipe
143 /** Creates an unattached pipe. You must attach the pipe to an oslPipe
144 e.g. by using the operator=(oslPipe), before you can use the stream-
145 functionality of the object.
149 /** Creates pipe as wrapper around the underlying oslPipe.
152 inline StreamPipe(oslPipe Pipe
);
154 /** Copy constructor.
157 inline StreamPipe(const StreamPipe
& Pipe
);
163 inline StreamPipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
= osl_Pipe_OPEN
);
170 inline StreamPipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
, const Security
&rSec
);
172 /** Constructs a Pipe reference without acquiring the handle
174 inline StreamPipe( oslPipe pipe
, __sal_NoAcquire noacquire
);
176 /** Attaches the oslPipe to this object. If the object
177 already was attached to an oslPipe, the old one will
178 be closed and destroyed.
181 inline StreamPipe
& SAL_CALL
operator=(oslPipe Pipe
);
183 /** Assignment operator
185 inline StreamPipe
& SAL_CALL
operator=(const Pipe
& pipe
);
187 /** Tries to receives BytesToRead data from the connected pipe,
189 @param pBuffer [out] Points to a buffer that will be filled with the received
191 @param BytesToRead [in] The number of bytes to read. pBuffer must have at least
193 @return the number of received bytes.
195 inline sal_Int32 SAL_CALL
recv(void* pBuffer
, sal_Int32 BytesToRead
) const;
197 /** Tries to sends BytesToSend data from the connected pipe.
199 @param pBuffer [in] Points to a buffer that contains the send-data.
200 @param BytesToSend [in] The number of bytes to send. pBuffer must have at least
202 @return the number of transferred bytes.
204 inline sal_Int32 SAL_CALL
send(const void* pBuffer
, sal_Int32 BytesToSend
) const;
206 /** Retrieves n bytes from the stream and copies them into pBuffer.
207 The method avoids incomplete reads due to packet boundaries.
208 @param pBuffer receives the read data.
209 @param n the number of bytes to read. pBuffer must be large enough
211 @return the number of read bytes. The number will only be smaller than
212 n if an exceptional condition (e.g. connection closed) occurs.
214 inline sal_Int32 SAL_CALL
read(void* pBuffer
, sal_Int32 n
) const;
216 /** Writes n bytes from pBuffer to the stream. The method avoids
217 incomplete writes due to packet boundaries.
218 @param pBuffer contains the data to be written.
219 @param n the number of bytes to write.
220 @return the number of written bytes. The number will only be smaller than
221 n if an exceptional condition (e.g. connection closed) occurs.
223 sal_Int32 SAL_CALL
write(const void* pBuffer
, sal_Int32 n
) const;
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */