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

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

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

Powered by Google App Engine
This is Rietveld 408576698