Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/udp/udp_socket_libevent.h" | 5 #include "net/udp/udp_socket_libevent.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <netdb.h> | 9 #include <netdb.h> |
| 10 #include <net/if.h> | 10 #include <net/if.h> |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 const CompletionCallback& callback) { | 163 const CompletionCallback& callback) { |
| 164 return RecvFrom(buf, buf_len, NULL, callback); | 164 return RecvFrom(buf, buf_len, NULL, callback); |
| 165 } | 165 } |
| 166 | 166 |
| 167 int UDPSocketLibevent::RecvFrom(IOBuffer* buf, | 167 int UDPSocketLibevent::RecvFrom(IOBuffer* buf, |
| 168 int buf_len, | 168 int buf_len, |
| 169 IPEndPoint* address, | 169 IPEndPoint* address, |
| 170 const CompletionCallback& callback) { | 170 const CompletionCallback& callback) { |
| 171 DCHECK(CalledOnValidThread()); | 171 DCHECK(CalledOnValidThread()); |
| 172 DCHECK_NE(kInvalidSocket, socket_); | 172 DCHECK_NE(kInvalidSocket, socket_); |
| 173 DCHECK(read_callback_.is_null()); | 173 CHECK(read_callback_.is_null()); |
|
wtc
2014/09/24 15:10:07
Ryan: I think it would be better to add a new net
| |
| 174 DCHECK(!recv_from_address_); | 174 DCHECK(!recv_from_address_); |
| 175 DCHECK(!callback.is_null()); // Synchronous operation not supported | 175 DCHECK(!callback.is_null()); // Synchronous operation not supported |
| 176 DCHECK_GT(buf_len, 0); | 176 DCHECK_GT(buf_len, 0); |
| 177 | 177 |
| 178 int nread = InternalRecvFrom(buf, buf_len, address); | 178 int nread = InternalRecvFrom(buf, buf_len, address); |
| 179 if (nread != ERR_IO_PENDING) | 179 if (nread != ERR_IO_PENDING) |
| 180 return nread; | 180 return nread; |
| 181 | 181 |
| 182 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( | 182 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 183 socket_, true, base::MessageLoopForIO::WATCH_READ, | 183 socket_, true, base::MessageLoopForIO::WATCH_READ, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 207 const CompletionCallback& callback) { | 207 const CompletionCallback& callback) { |
| 208 return SendToOrWrite(buf, buf_len, &address, callback); | 208 return SendToOrWrite(buf, buf_len, &address, callback); |
| 209 } | 209 } |
| 210 | 210 |
| 211 int UDPSocketLibevent::SendToOrWrite(IOBuffer* buf, | 211 int UDPSocketLibevent::SendToOrWrite(IOBuffer* buf, |
| 212 int buf_len, | 212 int buf_len, |
| 213 const IPEndPoint* address, | 213 const IPEndPoint* address, |
| 214 const CompletionCallback& callback) { | 214 const CompletionCallback& callback) { |
| 215 DCHECK(CalledOnValidThread()); | 215 DCHECK(CalledOnValidThread()); |
| 216 DCHECK_NE(kInvalidSocket, socket_); | 216 DCHECK_NE(kInvalidSocket, socket_); |
| 217 DCHECK(write_callback_.is_null()); | 217 CHECK(write_callback_.is_null()); |
| 218 DCHECK(!callback.is_null()); // Synchronous operation not supported | 218 DCHECK(!callback.is_null()); // Synchronous operation not supported |
| 219 DCHECK_GT(buf_len, 0); | 219 DCHECK_GT(buf_len, 0); |
| 220 | 220 |
| 221 int result = InternalSendTo(buf, buf_len, address); | 221 int result = InternalSendTo(buf, buf_len, address); |
| 222 if (result != ERR_IO_PENDING) | 222 if (result != ERR_IO_PENDING) |
| 223 return result; | 223 return result; |
| 224 | 224 |
| 225 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( | 225 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 226 socket_, true, base::MessageLoopForIO::WATCH_WRITE, | 226 socket_, true, base::MessageLoopForIO::WATCH_WRITE, |
| 227 &write_socket_watcher_, &write_watcher_)) { | 227 &write_socket_watcher_, &write_watcher_)) { |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 return MapSystemError(errno); | 767 return MapSystemError(errno); |
| 768 | 768 |
| 769 return OK; | 769 return OK; |
| 770 } | 770 } |
| 771 | 771 |
| 772 void UDPSocketLibevent::DetachFromThread() { | 772 void UDPSocketLibevent::DetachFromThread() { |
| 773 base::NonThreadSafe::DetachFromThread(); | 773 base::NonThreadSafe::DetachFromThread(); |
| 774 } | 774 } |
| 775 | 775 |
| 776 } // namespace net | 776 } // namespace net |
| OLD | NEW |