| 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/base/tcp_client_socket.h" | 5 #include "net/base/tcp_client_socket.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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 char c; | 154 char c; |
| 155 int rv = recv(socket_, &c, 1, MSG_PEEK); | 155 int rv = recv(socket_, &c, 1, MSG_PEEK); |
| 156 if (rv == 0) | 156 if (rv == 0) |
| 157 return false; | 157 return false; |
| 158 if (rv == -1 && errno != EAGAIN && errno != EWOULDBLOCK) | 158 if (rv == -1 && errno != EAGAIN && errno != EWOULDBLOCK) |
| 159 return false; | 159 return false; |
| 160 | 160 |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 | 163 |
| 164 bool TCPClientSocket::IsConnectedAndIdle() const { |
| 165 if (socket_ == kInvalidSocket || waiting_connect_) |
| 166 return false; |
| 167 |
| 168 // Check if connection is alive and we haven't received any data |
| 169 // unexpectedly. |
| 170 char c; |
| 171 int rv = recv(socket_, &c, 1, MSG_PEEK); |
| 172 if (rv >= 0) |
| 173 return false; |
| 174 if (errno != EAGAIN && errno != EWOULDBLOCK) |
| 175 return false; |
| 176 |
| 177 return true; |
| 178 } |
| 179 |
| 164 int TCPClientSocket::Read(char* buf, | 180 int TCPClientSocket::Read(char* buf, |
| 165 int buf_len, | 181 int buf_len, |
| 166 CompletionCallback* callback) { | 182 CompletionCallback* callback) { |
| 167 DCHECK(socket_ != kInvalidSocket); | 183 DCHECK(socket_ != kInvalidSocket); |
| 168 DCHECK(!waiting_connect_); | 184 DCHECK(!waiting_connect_); |
| 169 DCHECK(!callback_); | 185 DCHECK(!callback_); |
| 170 // Synchronous operation not supported | 186 // Synchronous operation not supported |
| 171 DCHECK(callback); | 187 DCHECK(callback); |
| 172 DCHECK(buf_len > 0); | 188 DCHECK(buf_len > 0); |
| 173 | 189 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 DidCompleteWrite(); | 369 DidCompleteWrite(); |
| 354 } | 370 } |
| 355 } | 371 } |
| 356 | 372 |
| 357 int TCPClientSocket::GetPeerName(struct sockaddr *name, socklen_t *namelen) { | 373 int TCPClientSocket::GetPeerName(struct sockaddr *name, socklen_t *namelen) { |
| 358 return ::getpeername(socket_, name, namelen); | 374 return ::getpeername(socket_, name, namelen); |
| 359 } | 375 } |
| 360 | 376 |
| 361 } // namespace net | 377 } // namespace net |
| 362 | 378 |
| OLD | NEW |