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 "base/memory_debug.h" | 7 #include "base/memory_debug.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/trace_event.h" | 9 #include "base/trace_event.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 char c; | 150 char c; |
151 int rv = recv(socket_, &c, 1, MSG_PEEK); | 151 int rv = recv(socket_, &c, 1, MSG_PEEK); |
152 if (rv == 0) | 152 if (rv == 0) |
153 return false; | 153 return false; |
154 if (rv == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) | 154 if (rv == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) |
155 return false; | 155 return false; |
156 | 156 |
157 return true; | 157 return true; |
158 } | 158 } |
159 | 159 |
| 160 bool TCPClientSocket::IsConnectedAndIdle() const { |
| 161 if (socket_ == INVALID_SOCKET || wait_state_ == WAITING_CONNECT) |
| 162 return false; |
| 163 |
| 164 // Check if connection is alive and we haven't received any data |
| 165 // unexpectedly. |
| 166 char c; |
| 167 int rv = recv(socket_, &c, 1, MSG_PEEK); |
| 168 if (rv >= 0) |
| 169 return false; |
| 170 if (WSAGetLastError() != WSAEWOULDBLOCK) |
| 171 return false; |
| 172 |
| 173 return true; |
| 174 } |
| 175 |
160 int TCPClientSocket::Read(char* buf, | 176 int TCPClientSocket::Read(char* buf, |
161 int buf_len, | 177 int buf_len, |
162 CompletionCallback* callback) { | 178 CompletionCallback* callback) { |
163 DCHECK(socket_ != INVALID_SOCKET); | 179 DCHECK(socket_ != INVALID_SOCKET); |
164 DCHECK(wait_state_ == NOT_WAITING); | 180 DCHECK(wait_state_ == NOT_WAITING); |
165 DCHECK(!callback_); | 181 DCHECK(!callback_); |
166 | 182 |
167 buffer_.len = buf_len; | 183 buffer_.len = buf_len; |
168 buffer_.buf = buf; | 184 buffer_.buf = buf; |
169 | 185 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 void TCPClientSocket::WaitForAndResetEvent() { | 379 void TCPClientSocket::WaitForAndResetEvent() { |
364 // TODO(wtc): Remove the CHECKs after enough testing. | 380 // TODO(wtc): Remove the CHECKs after enough testing. |
365 DWORD wait_rv = WaitForSingleObject(overlapped_.hEvent, INFINITE); | 381 DWORD wait_rv = WaitForSingleObject(overlapped_.hEvent, INFINITE); |
366 CHECK(wait_rv == WAIT_OBJECT_0); | 382 CHECK(wait_rv == WAIT_OBJECT_0); |
367 BOOL ok = WSAResetEvent(overlapped_.hEvent); | 383 BOOL ok = WSAResetEvent(overlapped_.hEvent); |
368 CHECK(ok); | 384 CHECK(ok); |
369 } | 385 } |
370 | 386 |
371 } // namespace net | 387 } // namespace net |
372 | 388 |
OLD | NEW |