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 NET_SOCKET_UNIX_DOMAIN_CLIENT_SOCKET_POSIX_H_ | |
6 #define NET_SOCKET_UNIX_DOMAIN_CLIENT_SOCKET_POSIX_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include <sys/socket.h> | |
11 #include <sys/un.h> | |
12 | |
13 #include "base/basictypes.h" | |
14 #include "base/callback.h" | |
15 #include "base/message_loop/message_loop.h" | |
16 #include "net/base/net_export.h" | |
17 #include "net/socket/socket_descriptor.h" | |
18 #include "net/socket/stream_socket.h" | |
19 | |
20 namespace net { | |
21 | |
22 class NET_EXPORT UnixDomainClientSocket | |
23 : public StreamSocket, | |
24 public base::MessageLoopForIO::Watcher { | |
25 public: | |
26 // Builds a client socket with socket_path. The caller should call Connect() | |
27 // to connect to server sockect. | |
28 UnixDomainClientSocket(const std::string& socket_path, | |
29 bool use_abstract_namespace); | |
30 // Builds a client socket with socket fd which is already connected. | |
31 // UnixDomainServerSocket uses this after it accepts a connection. | |
32 explicit UnixDomainClientSocket(SocketDescriptor socket_fd); | |
33 | |
34 virtual ~UnixDomainClientSocket(); | |
35 | |
36 // Fills |sock_addr| with |socket_path|. For Android or Linux platform, it | |
37 // supports abstract namespace. |socket_addr_len| is in/out parameter as | |
38 // POSIX socket interfaces. | |
39 static bool FillAddress(const std::string& socket_path, | |
40 bool use_abstract_namespace, | |
41 sockaddr_un* socket_addr, | |
42 socklen_t* socket_addr_len); | |
43 | |
44 // StreamSocket implementation. | |
45 virtual int Connect(const CompletionCallback& callback) OVERRIDE; | |
46 virtual void Disconnect() OVERRIDE; | |
47 virtual bool IsConnected() const OVERRIDE; | |
48 virtual bool IsConnectedAndIdle() const OVERRIDE; | |
49 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | |
50 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | |
51 virtual const BoundNetLog& NetLog() const OVERRIDE; | |
52 virtual void SetSubresourceSpeculation() OVERRIDE; | |
53 virtual void SetOmniboxSpeculation() OVERRIDE; | |
54 virtual bool WasEverUsed() const OVERRIDE; | |
55 virtual bool UsingTCPFastOpen() const OVERRIDE; | |
56 virtual bool WasNpnNegotiated() const OVERRIDE; | |
57 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; | |
58 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; | |
59 | |
60 // Socket implementation. | |
61 virtual int Read(IOBuffer* buf, int buf_len, | |
62 const CompletionCallback& callback) OVERRIDE; | |
63 virtual int Write(IOBuffer* buf, int buf_len, | |
64 const CompletionCallback& callback) OVERRIDE; | |
65 virtual int SetReceiveBufferSize(int32 size) OVERRIDE; | |
66 virtual int SetSendBufferSize(int32 size) OVERRIDE; | |
67 | |
68 // base::MessageLoopForIO::Watcher methods. | |
69 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | |
70 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | |
mmenke
2014/06/11 16:05:50
These aren't intended to be used by consumers, so
byungchul
2014/06/20 08:22:32
Done.
| |
71 | |
72 private: | |
73 int DoConnect(); | |
74 void DidCompleteConnect(); | |
75 int DoRead(IOBuffer* buf, int buf_len); | |
76 void DidCompleteRead(); | |
77 int DoWrite(IOBuffer* buf, int buf_len); | |
78 void DidCompleteWrite(); | |
79 | |
80 const std::string socket_path_; | |
81 const bool use_abstract_namespace_; | |
82 SocketDescriptor socket_fd_; | |
83 BoundNetLog netlog_; | |
84 bool waiting_connect_; | |
85 | |
86 base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; | |
87 IOBuffer* read_buf_; | |
88 int read_buf_len_; | |
89 CompletionCallback read_callback_; | |
90 | |
91 base::MessageLoopForIO::FileDescriptorWatcher write_socket_watcher_; | |
92 IOBuffer* write_buf_; | |
93 int write_buf_len_; | |
94 CompletionCallback write_callback_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(UnixDomainClientSocket); | |
97 }; | |
98 | |
99 } // namespace net | |
100 | |
101 #endif // NET_SOCKET_UNIX_DOMAIN_CLIENT_SOCKET_POSIX_H_ | |
OLD | NEW |