Update V8 to version 4.7.24.
[chromium-blink-merge.git] / ipc / unix_domain_socket_util.h
blob5752364fa10c049f595b85437e159355c1f37a5e
1 // Copyright 2013 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.
5 #ifndef IPC_UNIX_DOMAIN_SOCKET_UTIL_H_
6 #define IPC_UNIX_DOMAIN_SOCKET_UTIL_H_
8 #include <sys/types.h>
10 #include <string>
12 #include "ipc/ipc_export.h"
14 namespace base {
15 class FilePath;
16 } // namespace base
18 namespace IPC {
20 // Creates a UNIX-domain socket at |socket_name| and bind()s it, then listen()s
21 // on it. If successful, |server_listen_fd| will be set to the new file
22 // descriptor, and the function will return true. Otherwise returns false.
24 // This function also effectively performs `mkdir -p` on the dirname of
25 // |socket_name| to ensure that all the directories up to |socket_name| exist.
26 // As a result of which this function must be run on a thread that allows
27 // blocking I/O, e.g. the FILE thread in Chrome's browser process.
28 IPC_EXPORT bool CreateServerUnixDomainSocket(const base::FilePath& socket_name,
29 int* server_listen_fd);
31 // Opens a UNIX-domain socket at |socket_name| and connect()s to it. If
32 // successful, |client_socket| will be set to the new file descriptor, and the
33 // function will return true. Otherwise returns false.
34 IPC_EXPORT bool CreateClientUnixDomainSocket(const base::FilePath& socket_name,
35 int* client_socket);
37 // Gets the effective user ID of the other end of the UNIX-domain socket
38 // specified by |fd|. If successful, sets |peer_euid| to the uid, and returns
39 // true. Otherwise returns false.
40 IPC_EXPORT bool GetPeerEuid(int fd, uid_t* peer_euid);
42 // Checks that the process on the other end of the UNIX domain socket
43 // represented by |peer_fd| shares the same EUID as this process.
44 IPC_EXPORT bool IsPeerAuthorized(int peer_fd);
46 // Accepts a client attempting to connect to |server_listen_fd|, storing the
47 // new file descriptor for the connection in |server_socket|.
49 // Returns false if |server_listen_fd| encounters an unrecoverable error.
50 // Returns true if it's valid to keep listening on |server_listen_fd|. In this
51 // case, it's possible that a connection wasn't successfully established; then,
52 // |server_socket| will be set to -1.
53 IPC_EXPORT bool ServerAcceptConnection(int server_listen_fd,
54 int* server_socket);
56 // The maximum length of the name of a socket for MODE_NAMED_SERVER or
57 // MODE_NAMED_CLIENT if you want to pass in your own socket.
58 // The standard size on linux is 108, mac is 104. To maintain consistency
59 // across platforms we standardize on the smaller value.
60 static const size_t kMaxSocketNameLength = 104;
62 } // namespace IPC
64 #endif // IPC_UNIX_DOMAIN_SOCKET_UTIL_H_