Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1394)

Unified Diff: net/socket/unix_domain_server_socket_posix.h

Issue 376323002: Refactor unix domain socket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved UnixDomainListenSocket to net::deprecated namespace. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..06fb8d32c47bc4b0e700fa70f51d3f2ab80aa36d
--- /dev/null
+++ b/net/socket/unix_domain_server_socket_posix.h
@@ -0,0 +1,69 @@
+// 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 <sys/types.h>
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/base/net_export.h"
+#include "net/socket/server_socket.h"
+#include "net/socket/socket_descriptor.h"
+
+namespace net {
+
+class SocketLibevent;
+
+// Unix Domain Server Socket Implementation. Supports abstract namespaces on
+// Linux and Android.
+class NET_EXPORT UnixDomainServerSocket : public ServerSocket {
+ 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();
+
+ // Gets UID and GID of peer to check permissions.
+ static bool GetPeerIds(SocketDescriptor socket_fd,
+ uid_t* user_id,
+ gid_t* group_id);
+
+ // 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;
+
+ private:
+ void AcceptCompleted(scoped_ptr<StreamSocket>* socket,
+ const CompletionCallback& callback,
+ int rv);
+ bool AuthenticateAndGetStreamSocket(scoped_ptr<StreamSocket>* socket);
+
+ scoped_ptr<SocketLibevent> listen_socket_;
+ const AuthCallback auth_callback_;
+ const bool use_abstract_namespace_;
+
+ scoped_ptr<SocketLibevent> accept_socket_;
+
+ DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocket);
+};
+
+} // namespace net
+
+#endif // NET_SOCKET_UNIX_DOMAIN_SOCKET_POSIX_H_
« no previous file with comments | « net/socket/unix_domain_listen_socket_posix_unittest.cc ('k') | net/socket/unix_domain_server_socket_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698