Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: net/udp/udp_socket_libevent.h

Issue 8801005: base::Bind: Convert Socket::Read. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/udp/udp_client_socket.cc ('k') | net/udp/udp_socket_libevent.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 int GetLocalAddress(IPEndPoint* address) const; 48 int GetLocalAddress(IPEndPoint* address) const;
49 49
50 // IO: 50 // IO:
51 // Multiple outstanding read requests are not supported. 51 // Multiple outstanding read requests are not supported.
52 // Full duplex mode (reading and writing at the same time) is supported 52 // Full duplex mode (reading and writing at the same time) is supported
53 53
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 59
59 // Write to the socket. 60 // Write to the socket.
60 // 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
61 // has been connected. 62 // has been connected.
62 int Write(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); 63 int Write(IOBuffer* buf, int buf_len, OldCompletionCallback* callback);
63 64
64 // Read from a socket and receive sender address information. 65 // Read from a socket and receive sender address information.
65 // |buf| is the buffer to read data into. 66 // |buf| is the buffer to read data into.
66 // |buf_len| is the maximum amount of data to read. 67 // |buf_len| is the maximum amount of data to read.
67 // |address| is a buffer provided by the caller for receiving the sender 68 // |address| is a buffer provided by the caller for receiving the sender
68 // address information about the received data. This buffer must be kept 69 // address information about the received data. This buffer must be kept
69 // alive by the caller until the callback is placed. 70 // alive by the caller until the callback is placed.
70 // |address_length| is a ptr to the length of the |address| buffer. This 71 // |address_length| is a ptr to the length of the |address| buffer. This
71 // is an input parameter containing the maximum size |address| can hold 72 // is an input parameter containing the maximum size |address| can hold
72 // and also an output parameter for the size of |address| upon completion. 73 // and also an output parameter for the size of |address| upon completion.
73 // |callback| the callback on completion of the Recv. 74 // |callback| the callback on completion of the Recv.
74 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. 75 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress.
75 // If ERR_IO_PENDING is returned, the caller must keep |buf|, |address|, 76 // If ERR_IO_PENDING is returned, the caller must keep |buf|, |address|,
76 // and |address_length| alive until the callback is called. 77 // and |address_length| alive until the callback is called.
77 int RecvFrom(IOBuffer* buf, 78 int RecvFrom(IOBuffer* buf,
78 int buf_len, 79 int buf_len,
79 IPEndPoint* address, 80 IPEndPoint* address,
80 OldCompletionCallback* callback); 81 OldCompletionCallback* callback);
82 int RecvFrom(IOBuffer* buf,
83 int buf_len,
84 IPEndPoint* address,
85 const CompletionCallback& callback);
81 86
82 // Send to a socket with a particular destination. 87 // Send to a socket with a particular destination.
83 // |buf| is the buffer to send 88 // |buf| is the buffer to send
84 // |buf_len| is the number of bytes to send 89 // |buf_len| is the number of bytes to send
85 // |address| is the recipient address. 90 // |address| is the recipient address.
86 // |address_length| is the size of the recipient address 91 // |address_length| is the size of the recipient address
87 // |callback| is the user callback function to call on complete. 92 // |callback| is the user callback function to call on complete.
88 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. 93 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress.
89 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address| 94 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address|
90 // alive until the callback is called. 95 // alive until the callback is called.
(...skipping 16 matching lines...) Expand all
107 private: 112 private:
108 static const int kInvalidSocket = -1; 113 static const int kInvalidSocket = -1;
109 114
110 class ReadWatcher : public MessageLoopForIO::Watcher { 115 class ReadWatcher : public MessageLoopForIO::Watcher {
111 public: 116 public:
112 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} 117 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {}
113 118
114 // MessageLoopForIO::Watcher methods 119 // MessageLoopForIO::Watcher methods
115 120
116 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { 121 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {
117 if (socket_->read_callback_) 122 if (socket_->old_read_callback_ || !socket_->read_callback_.is_null())
118 socket_->DidCompleteRead(); 123 socket_->DidCompleteRead();
119 } 124 }
120 125
121 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {} 126 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {}
122 127
123 private: 128 private:
124 UDPSocketLibevent* const socket_; 129 UDPSocketLibevent* const socket_;
125 130
126 DISALLOW_COPY_AND_ASSIGN(ReadWatcher); 131 DISALLOW_COPY_AND_ASSIGN(ReadWatcher);
127 }; 132 };
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 scoped_refptr<IOBuffer> read_buf_; 207 scoped_refptr<IOBuffer> read_buf_;
203 int read_buf_len_; 208 int read_buf_len_;
204 IPEndPoint* recv_from_address_; 209 IPEndPoint* recv_from_address_;
205 210
206 // The buffer used by InternalWrite() to retry Write requests 211 // The buffer used by InternalWrite() to retry Write requests
207 scoped_refptr<IOBuffer> write_buf_; 212 scoped_refptr<IOBuffer> write_buf_;
208 int write_buf_len_; 213 int write_buf_len_;
209 scoped_ptr<IPEndPoint> send_to_address_; 214 scoped_ptr<IPEndPoint> send_to_address_;
210 215
211 // External callback; called when read is complete. 216 // External callback; called when read is complete.
212 OldCompletionCallback* read_callback_; 217 OldCompletionCallback* old_read_callback_;
218 CompletionCallback read_callback_;
213 219
214 // External callback; called when write is complete. 220 // External callback; called when write is complete.
215 OldCompletionCallback* write_callback_; 221 OldCompletionCallback* write_callback_;
216 222
217 BoundNetLog net_log_; 223 BoundNetLog net_log_;
218 224
219 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); 225 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent);
220 }; 226 };
221 227
222 } // namespace net 228 } // namespace net
223 229
224 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ 230 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_
OLDNEW
« no previous file with comments | « net/udp/udp_client_socket.cc ('k') | net/udp/udp_socket_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698