Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
fling.h
Go to the documentation of this file.
1 // Copyright 2013 Sharvil Nanavati
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // FLING: Exchanging file descriptors over sockets
16 //
17 // This is a little library for sending file descriptors over a socket
18 // between processes. The reason for doing that (as opposed to using
19 // filenames to share the files) is so (a) no files remain in the
20 // filesystem after all the processes terminate, (b) to make sure that
21 // there are no name collisions and (c) to be able to control who has
22 // access to the data.
23 //
24 // Most of the code is from https://github.com/sharvil/flingfd
25 
26 #include <errno.h>
27 #include <sys/socket.h>
28 #include <sys/types.h>
29 #include <sys/un.h>
30 #include <unistd.h>
31 
32 // This is neccessary for Mac OS X, see http://www.apuebook.com/faqs2e.html
33 // (10).
34 #if !defined(CMSG_SPACE) && !defined(CMSG_LEN)
35 #define CMSG_SPACE(len) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(len))
36 #define CMSG_LEN(len) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + (len))
37 #endif
38 
39 void init_msg(struct msghdr* msg, struct iovec* iov, char* buf, size_t buf_len);
40 
41 // Send a file descriptor over a unix domain socket.
42 //
43 // @param conn Unix domain socket to send the file descriptor over.
44 // @param fd File descriptor to send over.
45 // @return Status code which is < 0 on failure.
46 int send_fd(int conn, int fd);
47 
48 // Receive a file descriptor over a unix domain socket.
49 //
50 // @param conn Unix domain socket to receive the file descriptor from.
51 // @return File descriptor or a value < 0 on failure.
52 int recv_fd(int conn);
int recv_fd(int conn)
int send_fd(int conn, int fd)
void init_msg(struct msghdr *msg, struct iovec *iov, char *buf, size_t buf_len)