| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_SOCKET_SOCKET_POSIX_H_ | 5 #ifndef NET_SOCKET_SOCKET_POSIX_H_ |
| 6 #define NET_SOCKET_SOCKET_POSIX_H_ | 6 #define NET_SOCKET_SOCKET_POSIX_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 14 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 15 #include "net/socket/socket_descriptor.h" | 16 #include "net/socket/socket_descriptor.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 class IOBuffer; | 20 class IOBuffer; |
| 20 class IPEndPoint; | 21 class IPEndPoint; |
| 21 struct SockaddrStorage; | 22 struct SockaddrStorage; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 int Open(int address_family); | 33 int Open(int address_family); |
| 33 // Takes ownership of |socket|. | 34 // Takes ownership of |socket|. |
| 34 int AdoptConnectedSocket(SocketDescriptor socket, | 35 int AdoptConnectedSocket(SocketDescriptor socket, |
| 35 const SockaddrStorage& peer_address); | 36 const SockaddrStorage& peer_address); |
| 36 // Releases ownership of |socket_fd_| to caller. | 37 // Releases ownership of |socket_fd_| to caller. |
| 37 SocketDescriptor ReleaseConnectedSocket(); | 38 SocketDescriptor ReleaseConnectedSocket(); |
| 38 | 39 |
| 39 int Bind(const SockaddrStorage& address); | 40 int Bind(const SockaddrStorage& address); |
| 40 | 41 |
| 41 int Listen(int backlog); | 42 int Listen(int backlog); |
| 42 int Accept(scoped_ptr<SocketPosix>* socket, | 43 int Accept(std::unique_ptr<SocketPosix>* socket, |
| 43 const CompletionCallback& callback); | 44 const CompletionCallback& callback); |
| 44 | 45 |
| 45 // Connects socket. On non-ERR_IO_PENDING error, sets errno and returns a net | 46 // Connects socket. On non-ERR_IO_PENDING error, sets errno and returns a net |
| 46 // error code. On ERR_IO_PENDING, |callback| is called with a net error code, | 47 // error code. On ERR_IO_PENDING, |callback| is called with a net error code, |
| 47 // not errno, though errno is set if connect event happens with error. | 48 // not errno, though errno is set if connect event happens with error. |
| 48 // TODO(byungchul): Need more robust way to pass system errno. | 49 // TODO(byungchul): Need more robust way to pass system errno. |
| 49 int Connect(const SockaddrStorage& address, | 50 int Connect(const SockaddrStorage& address, |
| 50 const CompletionCallback& callback); | 51 const CompletionCallback& callback); |
| 51 bool IsConnected() const; | 52 bool IsConnected() const; |
| 52 bool IsConnectedAndIdle() const; | 53 bool IsConnectedAndIdle() const; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 80 // the old thread. | 81 // the old thread. |
| 81 void DetachFromThread(); | 82 void DetachFromThread(); |
| 82 | 83 |
| 83 SocketDescriptor socket_fd() const { return socket_fd_; } | 84 SocketDescriptor socket_fd() const { return socket_fd_; } |
| 84 | 85 |
| 85 private: | 86 private: |
| 86 // base::MessageLoopForIO::Watcher methods. | 87 // base::MessageLoopForIO::Watcher methods. |
| 87 void OnFileCanReadWithoutBlocking(int fd) override; | 88 void OnFileCanReadWithoutBlocking(int fd) override; |
| 88 void OnFileCanWriteWithoutBlocking(int fd) override; | 89 void OnFileCanWriteWithoutBlocking(int fd) override; |
| 89 | 90 |
| 90 int DoAccept(scoped_ptr<SocketPosix>* socket); | 91 int DoAccept(std::unique_ptr<SocketPosix>* socket); |
| 91 void AcceptCompleted(); | 92 void AcceptCompleted(); |
| 92 | 93 |
| 93 int DoConnect(); | 94 int DoConnect(); |
| 94 void ConnectCompleted(); | 95 void ConnectCompleted(); |
| 95 | 96 |
| 96 int DoRead(IOBuffer* buf, int buf_len); | 97 int DoRead(IOBuffer* buf, int buf_len); |
| 97 void ReadCompleted(); | 98 void ReadCompleted(); |
| 98 | 99 |
| 99 int DoWrite(IOBuffer* buf, int buf_len); | 100 int DoWrite(IOBuffer* buf, int buf_len); |
| 100 void WriteCompleted(); | 101 void WriteCompleted(); |
| 101 | 102 |
| 102 void StopWatchingAndCleanUp(); | 103 void StopWatchingAndCleanUp(); |
| 103 | 104 |
| 104 SocketDescriptor socket_fd_; | 105 SocketDescriptor socket_fd_; |
| 105 | 106 |
| 106 base::MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_; | 107 base::MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_; |
| 107 scoped_ptr<SocketPosix>* accept_socket_; | 108 std::unique_ptr<SocketPosix>* accept_socket_; |
| 108 CompletionCallback accept_callback_; | 109 CompletionCallback accept_callback_; |
| 109 | 110 |
| 110 base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; | 111 base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; |
| 111 scoped_refptr<IOBuffer> read_buf_; | 112 scoped_refptr<IOBuffer> read_buf_; |
| 112 int read_buf_len_; | 113 int read_buf_len_; |
| 113 // External callback; called when read is complete. | 114 // External callback; called when read is complete. |
| 114 CompletionCallback read_callback_; | 115 CompletionCallback read_callback_; |
| 115 | 116 |
| 116 base::MessageLoopForIO::FileDescriptorWatcher write_socket_watcher_; | 117 base::MessageLoopForIO::FileDescriptorWatcher write_socket_watcher_; |
| 117 scoped_refptr<IOBuffer> write_buf_; | 118 scoped_refptr<IOBuffer> write_buf_; |
| 118 int write_buf_len_; | 119 int write_buf_len_; |
| 119 // External callback; called when write or connect is complete. | 120 // External callback; called when write or connect is complete. |
| 120 CompletionCallback write_callback_; | 121 CompletionCallback write_callback_; |
| 121 | 122 |
| 122 // A connect operation is pending. In this case, |write_callback_| needs to be | 123 // A connect operation is pending. In this case, |write_callback_| needs to be |
| 123 // called when connect is complete. | 124 // called when connect is complete. |
| 124 bool waiting_connect_; | 125 bool waiting_connect_; |
| 125 | 126 |
| 126 scoped_ptr<SockaddrStorage> peer_address_; | 127 std::unique_ptr<SockaddrStorage> peer_address_; |
| 127 | 128 |
| 128 base::ThreadChecker thread_checker_; | 129 base::ThreadChecker thread_checker_; |
| 129 | 130 |
| 130 DISALLOW_COPY_AND_ASSIGN(SocketPosix); | 131 DISALLOW_COPY_AND_ASSIGN(SocketPosix); |
| 131 }; | 132 }; |
| 132 | 133 |
| 133 } // namespace net | 134 } // namespace net |
| 134 | 135 |
| 135 #endif // NET_SOCKET_SOCKET_POSIX_H_ | 136 #endif // NET_SOCKET_SOCKET_POSIX_H_ |
| OLD | NEW |