| Index: net/socket/unix_domain_server_socket_posix.h
|
| diff --git a/net/socket/unix_domain_server_socket_posix.h b/net/socket/unix_domain_server_socket_posix.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e47590e7e1613cf1216199e0190140277dcf8503
|
| --- /dev/null
|
| +++ b/net/socket/unix_domain_server_socket_posix.h
|
| @@ -0,0 +1,74 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_
|
| +#define NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "net/base/net_export.h"
|
| +#include "net/socket/server_socket.h"
|
| +#include "net/socket/socket_descriptor.h"
|
| +
|
| +namespace net {
|
| +
|
| +// Unix Domain Server Socket Implementation. Supports abstract namespaces on
|
| +// Linux.
|
| +class NET_EXPORT UnixDomainServerSocket
|
| + : public ServerSocket,
|
| + public base::MessageLoopForIO::Watcher {
|
| + public:
|
| + // Callback that returns whether the already connected client, identified by
|
| + // its process |user_id| and |group_id|, is allowed to keep the connection
|
| + // open. Note that the socket is closed immediately in case the callback
|
| + // returns false.
|
| + typedef base::Callback<bool (uid_t user_id, gid_t group_id)> AuthCallback;
|
| +
|
| + UnixDomainServerSocket(const AuthCallback& auth_callack,
|
| + bool use_abstract_namespace);
|
| + virtual ~UnixDomainServerSocket();
|
| +
|
| + // ServerSocket implementation.
|
| + virtual int Listen(const IPEndPoint& address, int backlog) OVERRIDE;
|
| + virtual int ListenWithAddressAndPort(const std::string& unix_domain_path,
|
| + int port_unused,
|
| + int backlog) OVERRIDE;
|
| + virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
|
| + virtual int Accept(scoped_ptr<StreamSocket>* socket,
|
| + const CompletionCallback& callback) OVERRIDE;
|
| +
|
| + // base::MessageLoopForIO::Watcher methods.
|
| + virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
|
| + virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
|
| +
|
| + // Creates a socket and bind to |socket_path|.
|
| + // Only for android or for linux, |use_abstract_namespace| can be true.
|
| + // Otherwise, returns ERR_ADDRESS_INVALID.
|
| + static int CreateAndBind(const std::string& socket_path,
|
| + bool use_abstract_namespace,
|
| + SocketDescriptor* socket_fd);
|
| + // Gets UID and GID of peer to check permissions.
|
| + static bool GetPeerIds(SocketDescriptor socket_fd,
|
| + uid_t* user_id,
|
| + gid_t* group_id);
|
| + private:
|
| + void Close();
|
| + int DoAccept(scoped_ptr<StreamSocket>* socket);
|
| + void DidCompleteAccept();
|
| +
|
| + SocketDescriptor socket_fd_;
|
| + const AuthCallback auth_callback_;
|
| + const bool use_abstract_namespace_;
|
| +
|
| + base::MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_;
|
| + scoped_ptr<StreamSocket>* accept_socket_;
|
| + CompletionCallback accept_callback_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocket);
|
| +};
|
| +
|
| +} // namespace net
|
| +
|
| +#endif // NET_SOCKET_UNIX_DOMAIN_SOCKET_POSIX_H_
|
|
|