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