OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/socket/tcp_client_socket_libevent.h" | 5 #include "net/socket/tcp_client_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 <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 return MapPosixError(errno); | 255 return MapPosixError(errno); |
256 } | 256 } |
257 | 257 |
258 | 258 |
259 write_buf_ = buf; | 259 write_buf_ = buf; |
260 write_buf_len_ = buf_len; | 260 write_buf_len_ = buf_len; |
261 write_callback_ = callback; | 261 write_callback_ = callback; |
262 return ERR_IO_PENDING; | 262 return ERR_IO_PENDING; |
263 } | 263 } |
264 | 264 |
| 265 bool TCPClientSocketLibevent::SetReceiveBufferSize(int32 size) { |
| 266 int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, |
| 267 reinterpret_cast<const char*>(&size), |
| 268 sizeof(size)); |
| 269 DCHECK(!rv) << "Could not set socket receive buffer size: " << errno; |
| 270 return rv == 0; |
| 271 } |
| 272 |
| 273 bool TCPClientSocketLibevent::SetSendBufferSize(int32 size) { |
| 274 int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, |
| 275 reinterpret_cast<const char*>(&size), |
| 276 sizeof(size)); |
| 277 DCHECK(!rv) << "Could not set socket send buffer size: " << errno; |
| 278 return rv == 0; |
| 279 } |
| 280 |
| 281 |
265 int TCPClientSocketLibevent::CreateSocket(const addrinfo* ai) { | 282 int TCPClientSocketLibevent::CreateSocket(const addrinfo* ai) { |
266 socket_ = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); | 283 socket_ = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); |
267 if (socket_ == kInvalidSocket) | 284 if (socket_ == kInvalidSocket) |
268 return MapPosixError(errno); | 285 return MapPosixError(errno); |
269 | 286 |
270 if (SetNonBlocking(socket_)) | 287 if (SetNonBlocking(socket_)) |
271 return MapPosixError(errno); | 288 return MapPosixError(errno); |
272 | 289 |
273 return OK; | 290 return OK; |
274 } | 291 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 DoWriteCallback(result); | 392 DoWriteCallback(result); |
376 } | 393 } |
377 } | 394 } |
378 | 395 |
379 int TCPClientSocketLibevent::GetPeerName(struct sockaddr *name, | 396 int TCPClientSocketLibevent::GetPeerName(struct sockaddr *name, |
380 socklen_t *namelen) { | 397 socklen_t *namelen) { |
381 return ::getpeername(socket_, name, namelen); | 398 return ::getpeername(socket_, name, namelen); |
382 } | 399 } |
383 | 400 |
384 } // namespace net | 401 } // namespace net |
OLD | NEW |