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 29 matching lines...) Expand all Loading... |
40 #include "public/platform/WebSocketStreamError.h" | 40 #include "public/platform/WebSocketStreamError.h" |
41 #include "public/platform/WebSocketStreamHandle.h" | 41 #include "public/platform/WebSocketStreamHandle.h" |
42 #include "wtf/PassOwnPtr.h" | 42 #include "wtf/PassOwnPtr.h" |
43 | 43 |
44 namespace WebCore { | 44 namespace WebCore { |
45 | 45 |
46 static const unsigned bufferSize = 100 * 1024 * 1024; | 46 static const unsigned bufferSize = 100 * 1024 * 1024; |
47 | 47 |
48 SocketStreamHandleInternal::SocketStreamHandleInternal(SocketStreamHandle* handl
e) | 48 SocketStreamHandleInternal::SocketStreamHandleInternal(SocketStreamHandle* handl
e) |
49 : m_handle(handle) | 49 : m_handle(handle) |
| 50 , m_socket(adoptPtr(blink::Platform::current()->createSocketStreamHandle())) |
50 , m_maxPendingSendAllowed(0) | 51 , m_maxPendingSendAllowed(0) |
51 , m_pendingAmountSent(0) | 52 , m_pendingAmountSent(0) |
52 { | 53 { |
53 } | 54 } |
54 | 55 |
55 SocketStreamHandleInternal::~SocketStreamHandleInternal() | 56 SocketStreamHandleInternal::~SocketStreamHandleInternal() |
56 { | 57 { |
57 m_handle = 0; | 58 m_handle = 0; |
58 } | 59 } |
59 | 60 |
60 void SocketStreamHandleInternal::connect(const KURL& url) | 61 void SocketStreamHandleInternal::connect(const KURL& url) |
61 { | 62 { |
62 m_socket = adoptPtr(blink::Platform::current()->createSocketStreamHandle()); | |
63 WTF_LOG(Network, "SocketStreamHandleInternal %p connect()", this); | 63 WTF_LOG(Network, "SocketStreamHandleInternal %p connect()", this); |
| 64 |
64 ASSERT(m_socket); | 65 ASSERT(m_socket); |
65 ASSERT(m_handle); | |
66 if (m_handle->m_client) | |
67 m_handle->m_client->willOpenSocketStream(m_handle); | |
68 m_socket->connect(url, this); | 66 m_socket->connect(url, this); |
69 } | 67 } |
70 | 68 |
71 int SocketStreamHandleInternal::send(const char* data, int len) | 69 int SocketStreamHandleInternal::send(const char* data, int len) |
72 { | 70 { |
73 WTF_LOG(Network, "SocketStreamHandleInternal %p send() len=%d", this, len); | 71 WTF_LOG(Network, "SocketStreamHandleInternal %p send() len=%d", this, len); |
74 // FIXME: |m_socket| should not be null here, but it seems that there is the | 72 // FIXME: |m_socket| should not be null here, but it seems that there is the |
75 // case. We should figure out such a path and fix it rather than checking | 73 // case. We should figure out such a path and fix it rather than checking |
76 // null here. | 74 // null here. |
77 if (!m_socket) { | 75 if (!m_socket) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 WTF_LOG(Network, "SocketStreamHandleInternal %p didFail()", this); | 154 WTF_LOG(Network, "SocketStreamHandleInternal %p didFail()", this); |
157 if (m_handle && m_socket) { | 155 if (m_handle && m_socket) { |
158 ASSERT(socketHandle == m_socket.get()); | 156 ASSERT(socketHandle == m_socket.get()); |
159 if (m_handle->m_client) | 157 if (m_handle->m_client) |
160 m_handle->m_client->didFailSocketStream(m_handle, *(PassRefPtr<Socke
tStreamError>(err))); | 158 m_handle->m_client->didFailSocketStream(m_handle, *(PassRefPtr<Socke
tStreamError>(err))); |
161 } | 159 } |
162 } | 160 } |
163 | 161 |
164 // SocketStreamHandle ---------------------------------------------------------- | 162 // SocketStreamHandle ---------------------------------------------------------- |
165 | 163 |
166 SocketStreamHandle::SocketStreamHandle(const KURL& url, SocketStreamHandleClient
* client) | 164 SocketStreamHandle::SocketStreamHandle(SocketStreamHandleClient* client) |
167 : m_url(url) | 165 : m_client(client) |
168 , m_client(client) | |
169 , m_state(Connecting) | 166 , m_state(Connecting) |
170 { | 167 { |
171 m_internal = SocketStreamHandleInternal::create(this); | 168 m_internal = SocketStreamHandleInternal::create(this); |
172 m_internal->connect(m_url); | 169 } |
| 170 |
| 171 void SocketStreamHandle::connect(const KURL& url) |
| 172 { |
| 173 m_internal->connect(url); |
173 } | 174 } |
174 | 175 |
175 SocketStreamHandle::~SocketStreamHandle() | 176 SocketStreamHandle::~SocketStreamHandle() |
176 { | 177 { |
177 setClient(0); | 178 setClient(0); |
178 m_internal.clear(); | 179 m_internal.clear(); |
179 } | 180 } |
180 | 181 |
181 SocketStreamHandle::SocketStreamState SocketStreamHandle::state() const | 182 SocketStreamHandle::SocketStreamState SocketStreamHandle::state() const |
182 { | 183 { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 return m_internal->send(buf, len); | 272 return m_internal->send(buf, len); |
272 } | 273 } |
273 | 274 |
274 void SocketStreamHandle::closeInternal() | 275 void SocketStreamHandle::closeInternal() |
275 { | 276 { |
276 if (m_internal) | 277 if (m_internal) |
277 m_internal->close(); | 278 m_internal->close(); |
278 } | 279 } |
279 | 280 |
280 } // namespace WebCore | 281 } // namespace WebCore |
OLD | NEW |