| 263 | } |
| 264 | |
| 265 | U32 KUnixSocketObject::readNative(U8* buffer, U32 len) { |
| 266 | std::shared_ptr<KUnixSocketObject> con = this->connection.lock(); |
| 267 | if (!this->inClosed && !con) |
| 268 | return -K_EPIPE; |
| 269 | con = nullptr; // don't hold a strong reference to this, if we are blocking then it would prevent the con object from being destroyed when its process is closed |
| 270 | BOXEDWINE_CRITICAL_SECTION_WITH_CONDITION(this->lockCond); |
| 271 | while (this->recvBuffer.size_used()==0) { |
| 272 | if (this->inClosed) { |
| 273 | return 0; |
| 274 | } |
| 275 | if (!this->blocking) { |
| 276 | return -K_EWOULDBLOCK; |
| 277 | } |
| 278 | BOXEDWINE_CONDITION_WAIT(this->lockCond); |
| 279 | #ifdef BOXEDWINE_MULTI_THREADED |
| 280 | KThread* thread = KThread::currentThread(); |
| 281 | // audio thread will call this function without a thread |
| 282 | if (thread) { |
| 283 | if (thread->terminating) { |
| 284 | return -K_EINTR; |
| 285 | } |
| 286 | if (thread->startSignal) { |
| 287 | thread->startSignal = false; |
| 288 | return -K_CONTINUE; |
| 289 | } |
| 290 | } |
| 291 | #endif |
| 292 | } |
| 293 | //printf("readNative: %0.8X size=%d capacity=%d writeLen=%d", (int)&this->recvBuffer, (int)this->recvBuffer.size(), (int)this->recvBuffer.capacity(), len); |
| 294 | if (len > this->recvBuffer.size_used()) { |
| 295 | len = (U32)this->recvBuffer.size_used(); |
| 296 | } |
| 297 | this->recvBuffer.get(buffer, len); |
| 298 | if (con) { |
| 299 | BOXEDWINE_CONDITION_SIGNAL_ALL(this->lockCond); |
| 300 | } |
| 301 | //printf(" readNative: %0.8X size=%d capacity=%d writeLen=%d", (int)&this->recvBuffer, (int)this->recvBuffer.size(), (int)this->recvBuffer.capacity(), len); |
| 302 | return len; |
| 303 | } |
| 304 | |
| 305 | U32 KUnixSocketObject::read(KThread* thread, U32 buffer, U32 len) { |
| 306 | return read(thread, buffer, len, 0); |