| 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> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 15 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 16 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
| 17 #include "net/socket/socket_descriptor.h" | 18 #include "net/socket/socket_descriptor.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 class IOBuffer; | 22 class IOBuffer; |
| 22 struct SockaddrStorage; | 23 struct SockaddrStorage; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 bool IsConnected() const; | 53 bool IsConnected() const; |
| 53 bool IsConnectedAndIdle() const; | 54 bool IsConnectedAndIdle() const; |
| 54 | 55 |
| 55 // Multiple outstanding requests of the same type are not supported. | 56 // Multiple outstanding requests of the same type are not supported. |
| 56 // Full duplex mode (reading and writing at the same time) is supported. | 57 // Full duplex mode (reading and writing at the same time) is supported. |
| 57 // On error which is not ERR_IO_PENDING, sets errno and returns a net error | 58 // On error which is not ERR_IO_PENDING, sets errno and returns a net error |
| 58 // code. On ERR_IO_PENDING, |callback| is called with a net error code, not | 59 // code. On ERR_IO_PENDING, |callback| is called with a net error code, not |
| 59 // errno, though errno is set if read or write events happen with error. | 60 // errno, though errno is set if read or write events happen with error. |
| 60 // TODO(byungchul): Need more robust way to pass system errno. | 61 // TODO(byungchul): Need more robust way to pass system errno. |
| 61 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 62 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 63 |
| 64 // Reads as much data as possible into |buf| without blocking. If read is to |
| 65 // be retried later, |callback| will be invoked when data is ready for |
| 66 // reading. |
| 67 // See socket.h for more information. |
| 68 int ReadIfReady(IOBuffer* buf, |
| 69 int buf_len, |
| 70 const CompletionCallback& callback); |
| 62 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 71 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 63 | 72 |
| 64 // Waits for next write event. This is called by TCPSocketPosix for TCP | 73 // Waits for next write event. This is called by TCPSocketPosix for TCP |
| 65 // fastopen after sending first data. Returns ERR_IO_PENDING if it starts | 74 // fastopen after sending first data. Returns ERR_IO_PENDING if it starts |
| 66 // waiting for write event successfully. Otherwise, returns a net error code. | 75 // waiting for write event successfully. Otherwise, returns a net error code. |
| 67 // It must not be called after Write() because Write() calls it internally. | 76 // It must not be called after Write() because Write() calls it internally. |
| 68 int WaitForWrite(IOBuffer* buf, int buf_len, | 77 int WaitForWrite(IOBuffer* buf, int buf_len, |
| 69 const CompletionCallback& callback); | 78 const CompletionCallback& callback); |
| 70 | 79 |
| 71 int GetLocalAddress(SockaddrStorage* address) const; | 80 int GetLocalAddress(SockaddrStorage* address) const; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 88 void OnFileCanReadWithoutBlocking(int fd) override; | 97 void OnFileCanReadWithoutBlocking(int fd) override; |
| 89 void OnFileCanWriteWithoutBlocking(int fd) override; | 98 void OnFileCanWriteWithoutBlocking(int fd) override; |
| 90 | 99 |
| 91 int DoAccept(std::unique_ptr<SocketPosix>* socket); | 100 int DoAccept(std::unique_ptr<SocketPosix>* socket); |
| 92 void AcceptCompleted(); | 101 void AcceptCompleted(); |
| 93 | 102 |
| 94 int DoConnect(); | 103 int DoConnect(); |
| 95 void ConnectCompleted(); | 104 void ConnectCompleted(); |
| 96 | 105 |
| 97 int DoRead(IOBuffer* buf, int buf_len); | 106 int DoRead(IOBuffer* buf, int buf_len); |
| 107 void RetryRead(int rv); |
| 98 void ReadCompleted(); | 108 void ReadCompleted(); |
| 99 | 109 |
| 100 int DoWrite(IOBuffer* buf, int buf_len); | 110 int DoWrite(IOBuffer* buf, int buf_len); |
| 101 void WriteCompleted(); | 111 void WriteCompleted(); |
| 102 | 112 |
| 103 void StopWatchingAndCleanUp(); | 113 void StopWatchingAndCleanUp(); |
| 104 | 114 |
| 105 SocketDescriptor socket_fd_; | 115 SocketDescriptor socket_fd_; |
| 106 | 116 |
| 107 base::MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_; | 117 base::MessageLoopForIO::FileDescriptorWatcher accept_socket_watcher_; |
| 108 std::unique_ptr<SocketPosix>* accept_socket_; | 118 std::unique_ptr<SocketPosix>* accept_socket_; |
| 109 CompletionCallback accept_callback_; | 119 CompletionCallback accept_callback_; |
| 110 | 120 |
| 111 base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; | 121 base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; |
| 122 |
| 123 // Non-null when a Read() is in progress. |
| 112 scoped_refptr<IOBuffer> read_buf_; | 124 scoped_refptr<IOBuffer> read_buf_; |
| 113 int read_buf_len_; | 125 int read_buf_len_; |
| 114 // External callback; called when read is complete. | |
| 115 CompletionCallback read_callback_; | 126 CompletionCallback read_callback_; |
| 116 | 127 |
| 128 // Non-null when a ReadIfReady() is in progress. |
| 129 CompletionCallback read_if_ready_callback_; |
| 130 |
| 117 base::MessageLoopForIO::FileDescriptorWatcher write_socket_watcher_; | 131 base::MessageLoopForIO::FileDescriptorWatcher write_socket_watcher_; |
| 118 scoped_refptr<IOBuffer> write_buf_; | 132 scoped_refptr<IOBuffer> write_buf_; |
| 119 int write_buf_len_; | 133 int write_buf_len_; |
| 120 // External callback; called when write or connect is complete. | 134 // External callback; called when write or connect is complete. |
| 121 CompletionCallback write_callback_; | 135 CompletionCallback write_callback_; |
| 122 | 136 |
| 123 // A connect operation is pending. In this case, |write_callback_| needs to be | 137 // A connect operation is pending. In this case, |write_callback_| needs to be |
| 124 // called when connect is complete. | 138 // called when connect is complete. |
| 125 bool waiting_connect_; | 139 bool waiting_connect_; |
| 126 | 140 |
| 127 std::unique_ptr<SockaddrStorage> peer_address_; | 141 std::unique_ptr<SockaddrStorage> peer_address_; |
| 128 | 142 |
| 129 base::ThreadChecker thread_checker_; | 143 base::ThreadChecker thread_checker_; |
| 130 | 144 |
| 145 base::WeakPtrFactory<SocketPosix> weak_factory_; |
| 146 |
| 131 DISALLOW_COPY_AND_ASSIGN(SocketPosix); | 147 DISALLOW_COPY_AND_ASSIGN(SocketPosix); |
| 132 }; | 148 }; |
| 133 | 149 |
| 134 } // namespace net | 150 } // namespace net |
| 135 | 151 |
| 136 #endif // NET_SOCKET_SOCKET_POSIX_H_ | 152 #endif // NET_SOCKET_SOCKET_POSIX_H_ |
| OLD | NEW |