Commit 436e32f9676e522c42ca49d6ae17b48a3d4dd751
- Diff rendering mode:
- inline
- side by side
core/scripting/jssocket.cpp
(12 / 12)
|   | |||
| 134 | 134 | } | |
| 135 | 135 | ||
| 136 | 136 | protected: | |
| 137 | void blockingCallback() { | ||
| 137 | void startBlockingCall() { | ||
| 138 | 138 | m_pAttachedObject.reset(new ScriptContextAttachedObject(&getContext())); | |
| 139 | 139 | } | |
| 140 | 140 | ||
| 141 | void leavingBlockingCallback() { | ||
| 141 | void endBlockingCall() { | ||
| 142 | 142 | m_pAttachedObject.reset(); | |
| 143 | 143 | } | |
| 144 | 144 | protected: | |
| … | … | ||
| 191 | 191 | this, | |
| 192 | 192 | boost::asio::placeholders::error, | |
| 193 | 193 | ++iterator)); | |
| 194 | blockingCallback(); | ||
| 194 | startBlockingCall(); | ||
| 195 | 195 | startIOThread(); | |
| 196 | 196 | } | |
| 197 | 197 | ||
| … | … | ||
| 206 | 206 | this, | |
| 207 | 207 | boost::asio::placeholders::error, | |
| 208 | 208 | boost::asio::placeholders::bytes_transferred)); | |
| 209 | blockingCallback(); | ||
| 209 | startBlockingCall(); | ||
| 210 | 210 | startIOThread(); | |
| 211 | 211 | } | |
| 212 | 212 | ||
| 213 | 213 | void close() { | |
| 214 | 214 | m_pSocket->close(); | |
| 215 | leavingBlockingCallback(); | ||
| 215 | endBlockingCall(); | ||
| 216 | 216 | } | |
| 217 | 217 | ||
| 218 | 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 | startBlockingCall(); | ||
| 230 | 230 | startIOThread(); | |
| 231 | 231 | } | |
| 232 | 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 | startBlockingCall(); | ||
| 257 | 257 | startIOThread(); | |
| 258 | 258 | } else { | |
| 259 | 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 | endBlockingCall(); | ||
| 269 | 269 | //JS_SetContextThread(getContext().getJSContext()); | |
| 270 | 270 | JSRequest req(getContext().getJSContext()); | |
| 271 | 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 | endBlockingCall(); | ||
| 292 | 292 | //JS_SetContextThread(getContext().getJSContext()); | |
| 293 | 293 | JSRequest req(getContext().getJSContext()); | |
| 294 | 294 | if(!error) { | |
| … | … | ||
| 311 | 311 | JSRequest req(getContext().getJSContext()); | |
| 312 | 312 | if(!error) { | |
| 313 | 313 | if(bytesTransfered == m_BytesToRead) { | |
| 314 | leavingBlockingCallback(); | ||
| 314 | endBlockingCall(); | ||
| 315 | 315 | std::string result(m_DataBuffer, m_BytesToRead); | |
| 316 | 316 | callDataCallback(result); | |
| 317 | 317 | m_BytesToRead = 0; | |
| 318 | 318 | } | |
| 319 | 319 | } else { | |
| 320 | leavingBlockingCallback(); | ||
| 320 | endBlockingCall(); | ||
| 321 | 321 | Logger::getInstance()->log("SocketHelperInstance::readCallback: error: " + error.message()); | |
| 322 | 322 | callDataCallback(""); | |
| 323 | 323 | } | |
| … | … | ||
| 327 | 327 | ||
| 328 | 328 | void acceptCallback(const boost::system::error_code& error) { | |
| 329 | 329 | AssertLocked lock(&getContext()); | |
| 330 | leavingBlockingCallback(); | ||
| 330 | endBlockingCall(); | ||
| 331 | 331 | //JS_SetContextThread(getContext().getJSContext()); | |
| 332 | 332 | JSRequest req(getContext().getJSContext()); | |
| 333 | 333 | if(!error) { |

