1// Copyright (c) 2009 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef BASE_UNIX_DOMAIN_SOCKET_POSIX_H_ 6#define BASE_UNIX_DOMAIN_SOCKET_POSIX_H_ 7 8#include <stdint.h> 9#include <sys/types.h> 10#include <vector> 11 12class Pickle; 13 14namespace base { 15 16// Use sendmsg to write the given msg and include a vector 17// of file descriptors. Returns true iff successful. 18bool SendMsg(int fd, const void* msg, size_t length, 19 std::vector<int>& fds); 20// Use recvmsg to read a message and an array of file descriptors. Returns 21// -1 on failure. Note: will read, at most, 16 descriptors. 22ssize_t RecvMsg(int fd, void* msg, size_t length, std::vector<int>* fds); 23// Perform a sendmsg/recvmsg pair. 24// 1. This process creates a UNIX DGRAM socketpair. 25// 2. This proces writes a request to |fd| with an SCM_RIGHTS control message 26// containing on end of the fresh socket pair. 27// 3. This process blocks reading from the other end of the fresh socketpair. 28// 4. The target process receives the request, processes it and writes the 29// reply to the end of the socketpair contained in the request. 30// 5. This process wakes up and continues. 31// 32// fd: descriptor to send the request on 33// reply: buffer for the reply 34// reply_len: size of |reply| 35// result_fd: (may be NULL) the file descriptor returned in the reply (if any) 36// request: the bytes to send in the request 37ssize_t SendRecvMsg(int fd, uint8_t* reply, unsigned reply_len, int* result_fd, 38 const Pickle& request); 39 40} // namespace base 41 42#endif // BASE_UNIX_DOMAIN_SOCKET_POSIX_H_ 43