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

Side by Side Diff: net/socket/unix_domain_listen_socket_posix.h

Issue 376323002: Refactor unix domain socket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 NET_SOCKET_UNIX_DOMAIN_LISTEN_SOCKET_POSIX_H_
6 #define NET_SOCKET_UNIX_DOMAIN_LISTEN_SOCKET_POSIX_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "build/build_config.h"
15 #include "net/base/net_export.h"
16 #include "net/socket/stream_listen_socket.h"
17 #include "net/socket/unix_domain_server_socket_posix.h"
18
19 #if defined(OS_ANDROID) || defined(OS_LINUX)
20 // Feature only supported on Linux currently. This lets the Unix Domain Socket
21 // not be backed by the file system.
22 #define SOCKET_ABSTRACT_NAMESPACE_SUPPORTED
23 #endif
24
25 namespace net {
26
27 // Unix Domain Socket Implementation. Supports abstract namespaces on Linux.
28 class NET_EXPORT UnixDomainListenSocket : public StreamListenSocket {
29 public:
30 typedef UnixDomainServerSocket::AuthCallback AuthCallback;
31
32 virtual ~UnixDomainListenSocket();
33
34 // Note that the returned UnixDomainListenSocket instance does not take
35 // ownership of |del|.
36 static scoped_ptr<UnixDomainListenSocket> CreateAndListen(
37 const std::string& path,
38 StreamListenSocket::Delegate* del,
39 const AuthCallback& auth_callback);
40
41 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED)
42 // Same as above except that the created socket uses the abstract namespace
43 // which is a Linux-only feature. If |fallback_path| is not empty,
44 // make the second attempt with the provided fallback name.
45 static scoped_ptr<UnixDomainListenSocket>
46 CreateAndListenWithAbstractNamespace(
47 const std::string& path,
48 const std::string& fallback_path,
49 StreamListenSocket::Delegate* del,
50 const AuthCallback& auth_callback);
51 #endif
52
53 private:
54 UnixDomainListenSocket(SocketDescriptor s,
55 StreamListenSocket::Delegate* del,
56 const AuthCallback& auth_callback);
57
58 static scoped_ptr<UnixDomainListenSocket> CreateAndListenInternal(
59 const std::string& path,
60 const std::string& fallback_path,
61 StreamListenSocket::Delegate* del,
62 const AuthCallback& auth_callback,
63 bool use_abstract_namespace);
64
65 // StreamListenSocket:
66 virtual void Accept() OVERRIDE;
67
68 AuthCallback auth_callback_;
69
70 DISALLOW_COPY_AND_ASSIGN(UnixDomainListenSocket);
71 };
72
73 // Factory that can be used to instantiate UnixDomainListenSocket.
74 class NET_EXPORT UnixDomainListenSocketFactory
75 : public StreamListenSocketFactory {
76 public:
77 // Note that this class does not take ownership of the provided delegate.
78 UnixDomainListenSocketFactory(
79 const std::string& path,
80 const UnixDomainListenSocket::AuthCallback& auth_callback);
81 virtual ~UnixDomainListenSocketFactory();
82
83 // StreamListenSocketFactory:
84 virtual scoped_ptr<StreamListenSocket> CreateAndListen(
85 StreamListenSocket::Delegate* delegate) const OVERRIDE;
86
87 protected:
88 const std::string path_;
89 const UnixDomainListenSocket::AuthCallback auth_callback_;
90
91 private:
92 DISALLOW_COPY_AND_ASSIGN(UnixDomainListenSocketFactory);
93 };
94
95 #if defined(SOCKET_ABSTRACT_NAMESPACE_SUPPORTED)
96 // Use this factory to instantiate UnixDomainListenSocket using the abstract
97 // namespace feature (only supported on Linux).
98 class NET_EXPORT UnixDomainListenSocketWithAbstractNamespaceFactory
99 : public UnixDomainListenSocketFactory {
100 public:
101 UnixDomainListenSocketWithAbstractNamespaceFactory(
102 const std::string& path,
103 const std::string& fallback_path,
104 const UnixDomainListenSocket::AuthCallback& auth_callback);
105 virtual ~UnixDomainListenSocketWithAbstractNamespaceFactory();
106
107 // UnixDomainListenSocketFactory:
108 virtual scoped_ptr<StreamListenSocket> CreateAndListen(
109 StreamListenSocket::Delegate* delegate) const OVERRIDE;
110
111 private:
112 std::string fallback_path_;
113
114 DISALLOW_COPY_AND_ASSIGN(UnixDomainListenSocketWithAbstractNamespaceFactory);
115 };
116 #endif
117
118 } // namespace net
119
120 #endif // NET_SOCKET_UNIX_DOMAIN_LISTEN_SOCKET_POSIX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698