]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/fdmover.h
2d6a5b244c3a0f48808accc7933c1288433adbd3
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // fdmover - send/receive file descriptors over a UNIX domain socket connection
22 // An FdMover object is a very specialized Socket:
23 // It must be bound to a UNIX domain address
31 using namespace UnixPlusPlus
;
35 namespace IPPlusPlus
{
38 // an ordered list of file descriptors
39 typedef std::vector
<FileDesc
> FdVector
;
43 // An FdMover - a specialized Socket for transferring file descriptors
44 // across UNIX domain sockets.
46 class FdMover
: public Socket
{
48 class Element
: public cmsghdr
{
50 void *operator new (size_t base
, size_t more
);
51 void operator delete (void *addr
, size_t size
);
54 Element(int level
, int type
);
56 template <class T
> T
&payload() { return *reinterpret_cast<T
*>(CMSG_DATA(this)); }
57 size_t payloadSize() const { return cmsg_len
- ((caddr_t
)CMSG_DATA(this) - (caddr_t
)this); }
60 class Message
: public msghdr
{
62 Message(const void *data
, size_t length
);
63 void set(Element
*elem
);
64 Element
*element() const { return (Element
*)msg_control
; }
65 Element
*next(Element
*elem
) const { return (Element
*)CMSG_NXTHDR(this, elem
); }
73 FdMover(Socket s
) : Socket(s
) { }
75 size_t send(const void *data
, size_t length
, const FdVector
&fds
);
76 size_t receive(void *data
, size_t length
, FdVector
&fds
);
83 } // end namespace IPPlusPlus
84 } // end namespace Security