OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 MOJO_SHELL_DOMAIN_SOCKET_UNIX_DOMAIN_CLIENT_SOCKET_POSIX_H_ | |
6 #define MOJO_SHELL_DOMAIN_SOCKET_UNIX_DOMAIN_CLIENT_SOCKET_POSIX_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "mojo/shell/domain_socket/completion_callback.h" | |
14 #include "mojo/shell/domain_socket/socket_descriptor.h" | |
15 | |
16 namespace mojo { | |
17 namespace shell { | |
18 | |
19 class SocketLibevent; | |
20 struct SockaddrStorage; | |
21 | |
22 // A client socket that uses unix domain socket as the transport layer. | |
23 class UnixDomainClientSocket { | |
24 public: | |
25 // Builds a client socket with |socket_path|. The caller should call Connect() | |
26 // to connect to a server socket. | |
27 UnixDomainClientSocket(const std::string& socket_path, | |
28 bool use_abstract_namespace); | |
29 // Builds a client socket with socket libevent which is already connected. | |
30 // UnixDomainServerSocket uses this after it accepts a connection. | |
31 explicit UnixDomainClientSocket(scoped_ptr<SocketLibevent> socket); | |
32 | |
33 ~UnixDomainClientSocket(); | |
34 | |
35 // Fills |address| with |socket_path| and its length. For Android or Linux | |
36 // platform, this supports abstract namespaces. | |
37 static bool FillAddress(const std::string& socket_path, | |
38 bool use_abstract_namespace, | |
39 SockaddrStorage* address); | |
40 | |
41 int Connect(const CompletionCallback& callback); | |
42 void Disconnect(); | |
43 bool IsConnected() const; | |
44 bool IsConnectedAndIdle() const; | |
45 | |
46 // Releases ownership of underlying SocketDescriptor to caller. | |
47 // Internal state is reset so that this object can be used again. | |
48 // Socket must be connected in order to release it. | |
49 SocketDescriptor ReleaseConnectedSocket(); | |
50 | |
51 private: | |
52 const std::string socket_path_; | |
53 const bool use_abstract_namespace_; | |
54 scoped_ptr<SocketLibevent> socket_; | |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(UnixDomainClientSocket); | |
57 }; | |
58 | |
59 } // namespace shell | |
60 } // namespace mojo | |
61 | |
62 #endif // MOJO_SHELL_DOMAIN_SOCKET_UNIX_DOMAIN_CLIENT_SOCKET_POSIX_H_ | |
OLD | NEW |