OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 BASE_ASYNC_SOCKET_IO_HANDLER_H_ | 5 #ifndef BASE_ASYNC_SOCKET_IO_HANDLER_H_ |
6 #define BASE_ASYNC_SOCKET_IO_HANDLER_H_ | 6 #define BASE_ASYNC_SOCKET_IO_HANDLER_H_ |
7 | 7 |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/sync_socket.h" | 9 #include "base/sync_socket.h" |
10 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/non_thread_safe.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 // Attempts to read from the socket. The return value will be |false| | 70 // Attempts to read from the socket. The return value will be |false| |
71 // if an error occurred and |true| if data was read or a pending read | 71 // if an error occurred and |true| if data was read or a pending read |
72 // was issued. Regardless of async or sync operation, the | 72 // was issued. Regardless of async or sync operation, the |
73 // ReadCompleteCallback (see above) will be called when data is available. | 73 // ReadCompleteCallback (see above) will be called when data is available. |
74 bool Read(char* buffer, int buffer_len); | 74 bool Read(char* buffer, int buffer_len); |
75 | 75 |
76 private: | 76 private: |
77 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
78 // Implementation of IOHandler on Windows. | 78 // Implementation of IOHandler on Windows. |
79 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 79 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
80 DWORD bytes_transfered, | 80 DWORD bytes_transfered, |
81 DWORD error) OVERRIDE; | 81 DWORD error) override; |
82 #elif defined(OS_POSIX) | 82 #elif defined(OS_POSIX) |
83 // Implementation of base::MessageLoopForIO::Watcher. | 83 // Implementation of base::MessageLoopForIO::Watcher. |
84 virtual void OnFileCanWriteWithoutBlocking(int socket) OVERRIDE {} | 84 void OnFileCanWriteWithoutBlocking(int socket) override {} |
85 virtual void OnFileCanReadWithoutBlocking(int socket) OVERRIDE; | 85 void OnFileCanReadWithoutBlocking(int socket) override; |
86 | 86 |
87 void EnsureWatchingSocket(); | 87 void EnsureWatchingSocket(); |
88 #endif | 88 #endif |
89 | 89 |
90 base::SyncSocket::Handle socket_; | 90 base::SyncSocket::Handle socket_; |
91 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
92 base::MessageLoopForIO::IOContext* context_; | 92 base::MessageLoopForIO::IOContext* context_; |
93 bool is_pending_; | 93 bool is_pending_; |
94 #elif defined(OS_POSIX) | 94 #elif defined(OS_POSIX) |
95 base::MessageLoopForIO::FileDescriptorWatcher socket_watcher_; | 95 base::MessageLoopForIO::FileDescriptorWatcher socket_watcher_; |
96 // |pending_buffer_| and |pending_buffer_len_| are valid only between | 96 // |pending_buffer_| and |pending_buffer_len_| are valid only between |
97 // Read() and OnFileCanReadWithoutBlocking(). | 97 // Read() and OnFileCanReadWithoutBlocking(). |
98 char* pending_buffer_; | 98 char* pending_buffer_; |
99 int pending_buffer_len_; | 99 int pending_buffer_len_; |
100 // |true| iff the message loop is watching the socket for IO events. | 100 // |true| iff the message loop is watching the socket for IO events. |
101 bool is_watching_; | 101 bool is_watching_; |
102 #endif | 102 #endif |
103 ReadCompleteCallback read_complete_; | 103 ReadCompleteCallback read_complete_; |
104 | 104 |
105 DISALLOW_COPY_AND_ASSIGN(AsyncSocketIoHandler); | 105 DISALLOW_COPY_AND_ASSIGN(AsyncSocketIoHandler); |
106 }; | 106 }; |
107 | 107 |
108 } // namespace base. | 108 } // namespace base. |
109 | 109 |
110 #endif // BASE_ASYNC_SOCKET_IO_HANDLER_H_ | 110 #endif // BASE_ASYNC_SOCKET_IO_HANDLER_H_ |
OLD | NEW |