| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_UDP_UDP_SOCKET_LIBEVENT_H_ | 5 #ifndef NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
| 6 #define NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 6 #define NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // Read from the socket. | 54 // Read from the socket. |
| 55 // Only usable from the client-side of a UDP socket, after the socket | 55 // Only usable from the client-side of a UDP socket, after the socket |
| 56 // has been connected. | 56 // has been connected. |
| 57 int Read(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); | 57 int Read(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); |
| 58 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 58 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 59 | 59 |
| 60 // Write to the socket. | 60 // Write to the socket. |
| 61 // Only usable from the client-side of a UDP socket, after the socket | 61 // Only usable from the client-side of a UDP socket, after the socket |
| 62 // has been connected. | 62 // has been connected. |
| 63 int Write(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); | 63 int Write(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); |
| 64 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 64 | 65 |
| 65 // Read from a socket and receive sender address information. | 66 // Read from a socket and receive sender address information. |
| 66 // |buf| is the buffer to read data into. | 67 // |buf| is the buffer to read data into. |
| 67 // |buf_len| is the maximum amount of data to read. | 68 // |buf_len| is the maximum amount of data to read. |
| 68 // |address| is a buffer provided by the caller for receiving the sender | 69 // |address| is a buffer provided by the caller for receiving the sender |
| 69 // address information about the received data. This buffer must be kept | 70 // address information about the received data. This buffer must be kept |
| 70 // alive by the caller until the callback is placed. | 71 // alive by the caller until the callback is placed. |
| 71 // |address_length| is a ptr to the length of the |address| buffer. This | 72 // |address_length| is a ptr to the length of the |address| buffer. This |
| 72 // is an input parameter containing the maximum size |address| can hold | 73 // is an input parameter containing the maximum size |address| can hold |
| 73 // and also an output parameter for the size of |address| upon completion. | 74 // and also an output parameter for the size of |address| upon completion. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 134 |
| 134 class WriteWatcher : public MessageLoopForIO::Watcher { | 135 class WriteWatcher : public MessageLoopForIO::Watcher { |
| 135 public: | 136 public: |
| 136 explicit WriteWatcher(UDPSocketLibevent* socket) : socket_(socket) {} | 137 explicit WriteWatcher(UDPSocketLibevent* socket) : socket_(socket) {} |
| 137 | 138 |
| 138 // MessageLoopForIO::Watcher methods | 139 // MessageLoopForIO::Watcher methods |
| 139 | 140 |
| 140 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {} | 141 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {} |
| 141 | 142 |
| 142 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { | 143 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { |
| 143 if (socket_->write_callback_) | 144 if (socket_->old_write_callback_) |
| 144 socket_->DidCompleteWrite(); | 145 socket_->DidCompleteWrite(); |
| 145 } | 146 } |
| 146 | 147 |
| 147 private: | 148 private: |
| 148 UDPSocketLibevent* const socket_; | 149 UDPSocketLibevent* const socket_; |
| 149 | 150 |
| 150 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); | 151 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); |
| 151 }; | 152 }; |
| 152 | 153 |
| 153 void DoReadCallback(int rv); | 154 void DoReadCallback(int rv); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 166 // Returns the OS error code (or 0 on success). | 167 // Returns the OS error code (or 0 on success). |
| 167 int CreateSocket(const IPEndPoint& address); | 168 int CreateSocket(const IPEndPoint& address); |
| 168 | 169 |
| 169 // Same as SendTo(), except that address is passed by pointer | 170 // Same as SendTo(), except that address is passed by pointer |
| 170 // instead of by reference. It is called from Write() with |address| | 171 // instead of by reference. It is called from Write() with |address| |
| 171 // set to NULL. | 172 // set to NULL. |
| 172 int SendToOrWrite(IOBuffer* buf, | 173 int SendToOrWrite(IOBuffer* buf, |
| 173 int buf_len, | 174 int buf_len, |
| 174 const IPEndPoint* address, | 175 const IPEndPoint* address, |
| 175 OldCompletionCallback* callback); | 176 OldCompletionCallback* callback); |
| 177 int SendToOrWrite(IOBuffer* buf, |
| 178 int buf_len, |
| 179 const IPEndPoint* address, |
| 180 const CompletionCallback& callback); |
| 176 | 181 |
| 177 int InternalConnect(const IPEndPoint& address); | 182 int InternalConnect(const IPEndPoint& address); |
| 178 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 183 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
| 179 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 184 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
| 180 | 185 |
| 181 int DoBind(const IPEndPoint& address); | 186 int DoBind(const IPEndPoint& address); |
| 182 int RandomBind(const IPEndPoint& address); | 187 int RandomBind(const IPEndPoint& address); |
| 183 | 188 |
| 184 int socket_; | 189 int socket_; |
| 185 | 190 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 211 // The buffer used by InternalWrite() to retry Write requests | 216 // The buffer used by InternalWrite() to retry Write requests |
| 212 scoped_refptr<IOBuffer> write_buf_; | 217 scoped_refptr<IOBuffer> write_buf_; |
| 213 int write_buf_len_; | 218 int write_buf_len_; |
| 214 scoped_ptr<IPEndPoint> send_to_address_; | 219 scoped_ptr<IPEndPoint> send_to_address_; |
| 215 | 220 |
| 216 // External callback; called when read is complete. | 221 // External callback; called when read is complete. |
| 217 OldCompletionCallback* old_read_callback_; | 222 OldCompletionCallback* old_read_callback_; |
| 218 CompletionCallback read_callback_; | 223 CompletionCallback read_callback_; |
| 219 | 224 |
| 220 // External callback; called when write is complete. | 225 // External callback; called when write is complete. |
| 221 OldCompletionCallback* write_callback_; | 226 OldCompletionCallback* old_write_callback_; |
| 227 CompletionCallback write_callback_; |
| 222 | 228 |
| 223 BoundNetLog net_log_; | 229 BoundNetLog net_log_; |
| 224 | 230 |
| 225 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); | 231 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |
| 226 }; | 232 }; |
| 227 | 233 |
| 228 } // namespace net | 234 } // namespace net |
| 229 | 235 |
| 230 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ | 236 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
| OLD | NEW |