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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 181 |
182 SocketStreamHandle::SocketStreamState SocketStreamHandle::state() const | 182 SocketStreamHandle::SocketStreamState SocketStreamHandle::state() const |
183 { | 183 { |
184 return m_state; | 184 return m_state; |
185 } | 185 } |
186 | 186 |
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 // FIXME: This breaks the WebSocket API. The spec says: |
| 192 // "This does not include framing overhead incurred by the protocol..." |
| 193 if (m_client) |
| 194 m_client->didIncreaseBufferedAmount(this, length); |
191 if (!m_buffer.isEmpty()) { | 195 if (!m_buffer.isEmpty()) { |
192 if (m_buffer.size() + length > bufferSize) { | 196 if (m_buffer.size() + length > bufferSize) { |
193 // FIXME: report error to indicate that buffer has no more space. | 197 // FIXME: report error to indicate that buffer has no more space. |
194 return false; | 198 return false; |
195 } | 199 } |
196 m_buffer.append(data, length); | 200 m_buffer.append(data, length); |
197 if (m_client) | |
198 m_client->didUpdateBufferedAmount(this, bufferedAmount()); | |
199 return true; | 201 return true; |
200 } | 202 } |
201 int bytesWritten = 0; | 203 int bytesWritten = 0; |
202 if (m_state == Open) | 204 if (m_state == Open) |
203 bytesWritten = sendInternal(data, length); | 205 bytesWritten = sendInternal(data, length); |
204 if (bytesWritten < 0) | 206 if (bytesWritten < 0) |
205 return false; | 207 return false; |
| 208 if (m_client) |
| 209 m_client->didDecreaseBufferedAmount(this, bytesWritten); |
206 if (m_buffer.size() + length - bytesWritten > bufferSize) { | 210 if (m_buffer.size() + length - bytesWritten > bufferSize) { |
207 // FIXME: report error to indicate that buffer has no more space. | 211 // FIXME: report error to indicate that buffer has no more space. |
208 return false; | 212 return false; |
209 } | 213 } |
210 if (bytesWritten < length) { | 214 if (bytesWritten < length) { |
211 m_buffer.append(data + bytesWritten, length - bytesWritten); | 215 m_buffer.append(data + bytesWritten, length - bytesWritten); |
212 if (m_client) | |
213 m_client->didUpdateBufferedAmount(this, bufferedAmount()); | |
214 } | 216 } |
215 return true; | 217 return true; |
216 } | 218 } |
217 | 219 |
218 void SocketStreamHandle::close() | 220 void SocketStreamHandle::close() |
219 { | 221 { |
220 if (m_state == Closed) | 222 if (m_state == Closed) |
221 return; | 223 return; |
222 m_state = Closing; | 224 m_state = Closing; |
223 if (!m_buffer.isEmpty()) | 225 if (!m_buffer.isEmpty()) |
(...skipping 28 matching lines...) Expand all Loading... |
252 } | 254 } |
253 } | 255 } |
254 bool pending; | 256 bool pending; |
255 do { | 257 do { |
256 int bytesWritten = sendInternal(m_buffer.firstBlockData(), m_buffer.firs
tBlockSize()); | 258 int bytesWritten = sendInternal(m_buffer.firstBlockData(), m_buffer.firs
tBlockSize()); |
257 pending = bytesWritten != static_cast<int>(m_buffer.firstBlockSize()); | 259 pending = bytesWritten != static_cast<int>(m_buffer.firstBlockSize()); |
258 if (bytesWritten <= 0) | 260 if (bytesWritten <= 0) |
259 return false; | 261 return false; |
260 ASSERT(m_buffer.size() - bytesWritten <= bufferSize); | 262 ASSERT(m_buffer.size() - bytesWritten <= bufferSize); |
261 m_buffer.consume(bytesWritten); | 263 m_buffer.consume(bytesWritten); |
| 264 if (m_client) |
| 265 m_client->didDecreaseBufferedAmount(this, bytesWritten); |
262 } while (!pending && !m_buffer.isEmpty()); | 266 } while (!pending && !m_buffer.isEmpty()); |
263 if (m_client) | |
264 m_client->didUpdateBufferedAmount(this, bufferedAmount()); | |
265 return true; | 267 return true; |
266 } | 268 } |
267 | 269 |
268 int SocketStreamHandle::sendInternal(const char* buf, int len) | 270 int SocketStreamHandle::sendInternal(const char* buf, int len) |
269 { | 271 { |
270 if (!m_internal) | 272 if (!m_internal) |
271 return 0; | 273 return 0; |
272 return m_internal->send(buf, len); | 274 return m_internal->send(buf, len); |
273 } | 275 } |
274 | 276 |
275 void SocketStreamHandle::closeInternal() | 277 void SocketStreamHandle::closeInternal() |
276 { | 278 { |
277 if (m_internal) | 279 if (m_internal) |
278 m_internal->close(); | 280 m_internal->close(); |
279 } | 281 } |
280 | 282 |
281 } // namespace WebCore | 283 } // namespace WebCore |
OLD | NEW |