OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2011, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 bool SocketStreamHandle::send(const char* data, int length) | 187 bool SocketStreamHandle::send(const char* data, int length) |
188 { | 188 { |
189 if (m_state == Connecting || m_state == Closing) | 189 if (m_state == Connecting || m_state == Closing) |
190 return false; | 190 return false; |
191 if (!m_buffer.isEmpty()) { | 191 if (!m_buffer.isEmpty()) { |
192 if (m_buffer.size() + length > bufferSize) { | 192 if (m_buffer.size() + length > bufferSize) { |
193 // FIXME: report error to indicate that buffer has no more space. | 193 // FIXME: report error to indicate that buffer has no more space. |
194 return false; | 194 return false; |
195 } | 195 } |
196 m_buffer.append(data, length); | 196 m_buffer.append(data, length); |
| 197 if (m_client) |
| 198 m_client->didUpdateBufferedAmount(this, bufferedAmount()); |
197 return true; | 199 return true; |
198 } | 200 } |
199 int bytesWritten = 0; | 201 int bytesWritten = 0; |
200 if (m_state == Open) | 202 if (m_state == Open) |
201 bytesWritten = sendInternal(data, length); | 203 bytesWritten = sendInternal(data, length); |
202 if (bytesWritten < 0) | 204 if (bytesWritten < 0) |
203 return false; | 205 return false; |
204 if (m_client) | |
205 m_client->didConsumeBufferedAmount(this, bytesWritten); | |
206 if (m_buffer.size() + length - bytesWritten > bufferSize) { | 206 if (m_buffer.size() + length - bytesWritten > bufferSize) { |
207 // FIXME: report error to indicate that buffer has no more space. | 207 // FIXME: report error to indicate that buffer has no more space. |
208 return false; | 208 return false; |
209 } | 209 } |
210 if (bytesWritten < length) { | 210 if (bytesWritten < length) { |
211 m_buffer.append(data + bytesWritten, length - bytesWritten); | 211 m_buffer.append(data + bytesWritten, length - bytesWritten); |
| 212 if (m_client) |
| 213 m_client->didUpdateBufferedAmount(this, bufferedAmount()); |
212 } | 214 } |
213 return true; | 215 return true; |
214 } | 216 } |
215 | 217 |
216 void SocketStreamHandle::close() | 218 void SocketStreamHandle::close() |
217 { | 219 { |
218 if (m_state == Closed) | 220 if (m_state == Closed) |
219 return; | 221 return; |
220 m_state = Closing; | 222 m_state = Closing; |
221 if (!m_buffer.isEmpty()) | 223 if (!m_buffer.isEmpty()) |
(...skipping 28 matching lines...) Expand all Loading... |
250 } | 252 } |
251 } | 253 } |
252 bool pending; | 254 bool pending; |
253 do { | 255 do { |
254 int bytesWritten = sendInternal(m_buffer.firstBlockData(), m_buffer.firs
tBlockSize()); | 256 int bytesWritten = sendInternal(m_buffer.firstBlockData(), m_buffer.firs
tBlockSize()); |
255 pending = bytesWritten != static_cast<int>(m_buffer.firstBlockSize()); | 257 pending = bytesWritten != static_cast<int>(m_buffer.firstBlockSize()); |
256 if (bytesWritten <= 0) | 258 if (bytesWritten <= 0) |
257 return false; | 259 return false; |
258 ASSERT(m_buffer.size() - bytesWritten <= bufferSize); | 260 ASSERT(m_buffer.size() - bytesWritten <= bufferSize); |
259 m_buffer.consume(bytesWritten); | 261 m_buffer.consume(bytesWritten); |
260 if (m_client) | |
261 m_client->didConsumeBufferedAmount(this, bytesWritten); | |
262 } while (!pending && !m_buffer.isEmpty()); | 262 } while (!pending && !m_buffer.isEmpty()); |
| 263 if (m_client) |
| 264 m_client->didUpdateBufferedAmount(this, bufferedAmount()); |
263 return true; | 265 return true; |
264 } | 266 } |
265 | 267 |
266 int SocketStreamHandle::sendInternal(const char* buf, int len) | 268 int SocketStreamHandle::sendInternal(const char* buf, int len) |
267 { | 269 { |
268 if (!m_internal) | 270 if (!m_internal) |
269 return 0; | 271 return 0; |
270 return m_internal->send(buf, len); | 272 return m_internal->send(buf, len); |
271 } | 273 } |
272 | 274 |
273 void SocketStreamHandle::closeInternal() | 275 void SocketStreamHandle::closeInternal() |
274 { | 276 { |
275 if (m_internal) | 277 if (m_internal) |
276 m_internal->close(); | 278 m_internal->close(); |
277 } | 279 } |
278 | 280 |
279 } // namespace WebCore | 281 } // namespace WebCore |
OLD | NEW |