]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/fdmover.h
2 * Copyright (c) 2000-2001,2003-2004,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // fdmover - send/receive file descriptors over a UNIX domain socket connection
28 // An FdMover object is a very specialized Socket:
29 // It must be bound to a UNIX domain address
37 using namespace UnixPlusPlus
;
41 namespace IPPlusPlus
{
44 // an ordered list of file descriptors
45 typedef std::vector
<FileDesc
> FdVector
;
49 // An FdMover - a specialized Socket for transferring file descriptors
50 // across UNIX domain sockets.
52 class FdMover
: public Socket
{
54 class Element
: public cmsghdr
{
56 void *operator new (size_t base
, ssize_t more
);
57 void operator delete (void *addr
, ssize_t size
);
58 void operator delete (void *addr
, size_t size
);
61 Element(int level
, int type
);
63 template <class T
> T
&payload() { return *reinterpret_cast<T
*>(CMSG_DATA(this)); }
64 size_t payloadSize() const { return cmsg_len
- ((caddr_t
)CMSG_DATA(this) - (caddr_t
)this); }
67 class Message
: public msghdr
{
69 Message(const void *data
, size_t length
);
70 void set(Element
*elem
);
71 Element
*element() const { return (Element
*)msg_control
; }
72 Element
*next(Element
*elem
) const { return (Element
*)CMSG_NXTHDR(this, elem
); }
80 FdMover(Socket s
) : Socket(s
) { }
82 size_t send(const void *data
, size_t length
, const FdVector
&fds
);
83 size_t receive(void *data
, size_t length
, FdVector
&fds
);
90 } // end namespace IPPlusPlus
91 } // end namespace Security