Commit 2536059dd91812a35c729bfad7d9d2965cc701c4
- Diff rendering mode:
- inline
- side by side
core/scripting/jssocket.cpp
(20 / 2)
|   | |||
| 103 | 103 | + e.what(), lsError); | |
| 104 | 104 | } | |
| 105 | 105 | } | |
| 106 | //JS_GC(m_pContext->getJSContext()); | ||
| 106 | JS_GC(m_pContext->getJSContext()); | ||
| 107 | 107 | } | |
| 108 | 108 | ||
| 109 | 109 | ScriptContext& getContext() const { | |
| … | … | ||
| 134 | 134 | } | |
| 135 | 135 | ||
| 136 | 136 | protected: | |
| 137 | void blockingCallback() { | ||
| 138 | m_pAttachedObject.reset(new ScriptContextAttachedObject(&getContext())); | ||
| 139 | } | ||
| 140 | |||
| 141 | void leavingBlockingCallback() { | ||
| 142 | m_pAttachedObject.reset(); | ||
| 143 | } | ||
| 144 | protected: | ||
| 137 | 145 | SocketScriptContextExtension& m_Extension; | |
| 138 | 146 | private: | |
| 139 | 147 | void ensureIOServiceAvailable() { | |
| … | … | ||
| 156 | 156 | boost::shared_ptr<ScriptObject> m_pCallbackObject; | |
| 157 | 157 | boost::shared_ptr<ScriptFunctionRooter> m_pFunctionRooter; | |
| 158 | 158 | jsval m_CallbackFunction; | |
| 159 | boost::shared_ptr<ScriptContextAttachedObject> m_pAttachedObject; | ||
| 159 | 160 | }; // SocketHelper | |
| 160 | 161 | ||
| 161 | 162 | class SocketHelperInstance : public SocketHelper, | |
| … | … | ||
| 191 | 191 | this, | |
| 192 | 192 | boost::asio::placeholders::error, | |
| 193 | 193 | ++iterator)); | |
| 194 | blockingCallback(); | ||
| 194 | 195 | startIOThread(); | |
| 195 | 196 | } | |
| 196 | 197 | ||
| … | … | ||
| 206 | 206 | this, | |
| 207 | 207 | boost::asio::placeholders::error, | |
| 208 | 208 | boost::asio::placeholders::bytes_transferred)); | |
| 209 | blockingCallback(); | ||
| 209 | 210 | startIOThread(); | |
| 210 | 211 | } | |
| 211 | 212 | ||
| 212 | 213 | void close() { | |
| 213 | 214 | m_pSocket->close(); | |
| 215 | leavingBlockingCallback(); | ||
| 214 | 216 | } | |
| 215 | 217 | ||
| 216 | 218 | void receive(const int _numberOfBytes) { | |
| … | … | ||
| 226 | 226 | this, | |
| 227 | 227 | boost::asio::placeholders::error, | |
| 228 | 228 | boost::asio::placeholders::bytes_transferred)); | |
| 229 | blockingCallback(); | ||
| 229 | 230 | startIOThread(); | |
| 230 | 231 | } | |
| 231 | 232 | ||
| … | … | ||
| 253 | 253 | if(m_pSocket == NULL && m_pAcceptor != NULL) { | |
| 254 | 254 | createSocket(); | |
| 255 | 255 | m_pAcceptor->async_accept(*m_pSocket, boost::bind(&SocketHelperInstance::acceptCallback, this, boost::asio::placeholders::error)); | |
| 256 | blockingCallback(); | ||
| 256 | 257 | startIOThread(); | |
| 257 | 258 | } else { | |
| 258 | 259 | Logger::getInstance()->log("SocketHelperInstance::accept: Please call bind first", lsFatal); | |
| … | … | ||
| 265 | 265 | tcp::resolver::iterator endpoint_iterator) { | |
| 266 | 266 | Logger::getInstance()->log("*** Connection callback"); | |
| 267 | 267 | AssertLocked lock(&getContext()); | |
| 268 | leavingBlockingCallback(); | ||
| 268 | 269 | //JS_SetContextThread(getContext().getJSContext()); | |
| 269 | 270 | JSRequest req(getContext().getJSContext()); | |
| 270 | 271 | if (!error) { | |
| … | … | ||
| 288 | 288 | void sendCallback(const boost::system::error_code& error, std::size_t bytesTransfered) { | |
| 289 | 289 | Logger::getInstance()->log("*** Send callback"); | |
| 290 | 290 | AssertLocked lock(&getContext()); | |
| 291 | leavingBlockingCallback(); | ||
| 291 | 292 | //JS_SetContextThread(getContext().getJSContext()); | |
| 292 | 293 | JSRequest req(getContext().getJSContext()); | |
| 293 | 294 | if(!error) { | |
| … | … | ||
| 311 | 311 | JSRequest req(getContext().getJSContext()); | |
| 312 | 312 | if(!error) { | |
| 313 | 313 | if(bytesTransfered == m_BytesToRead) { | |
| 314 | leavingBlockingCallback(); | ||
| 314 | 315 | std::string result(m_DataBuffer, m_BytesToRead); | |
| 315 | 316 | callDataCallback(result); | |
| 316 | 317 | m_BytesToRead = 0; | |
| 317 | 318 | } | |
| 318 | 319 | } else { | |
| 320 | leavingBlockingCallback(); | ||
| 319 | 321 | Logger::getInstance()->log("SocketHelperInstance::readCallback: error: " + error.message()); | |
| 320 | 322 | callDataCallback(""); | |
| 321 | 323 | } | |
| … | … | ||
| 327 | 327 | ||
| 328 | 328 | void acceptCallback(const boost::system::error_code& error) { | |
| 329 | 329 | AssertLocked lock(&getContext()); | |
| 330 | leavingBlockingCallback(); | ||
| 330 | 331 | //JS_SetContextThread(getContext().getJSContext()); | |
| 331 | 332 | JSRequest req(getContext().getJSContext()); | |
| 332 | 333 | if(!error) { | |
| … | … | ||
| 436 | 436 | boost::bind(&SocketHelperSendOneShot::handle_write, this, | |
| 437 | 437 | boost::asio::placeholders::error)); | |
| 438 | 438 | } | |
| 439 | void req(); | ||
| 440 | 439 | ||
| 441 | 440 | private: | |
| 442 | 441 | void handle_connect(const boost::system::error_code& error, |

