| 573 | } |
| 574 | |
| 575 | U32 KUnixSocketObject::accept(KThread* thread, const KFileDescriptorPtr& fd, U32 address, U32 len, U32 flags) { |
| 576 | std::shared_ptr<KUnixSocketObject> pendingConnection; |
| 577 | { |
| 578 | BOXEDWINE_CRITICAL_SECTION_WITH_CONDITION(this->lockCond); |
| 579 | while (!this->pendingConnections.size()) { |
| 580 | if (!this->blocking) { |
| 581 | return -K_EWOULDBLOCK; |
| 582 | } |
| 583 | BOXEDWINE_CONDITION_WAIT(this->lockCond); |
| 584 | #ifdef BOXEDWINE_MULTI_THREADED |
| 585 | if (thread->terminating) { |
| 586 | return -K_EINTR; |
| 587 | } |
| 588 | if (thread->startSignal) { |
| 589 | thread->startSignal = false; |
| 590 | return -K_CONTINUE; |
| 591 | } |
| 592 | #endif |
| 593 | } |
| 594 | |
| 595 | pendingConnection = this->pendingConnections.front().lock(); |
| 596 | this->pendingConnections.pop_front(); |
| 597 | } |
| 598 | |
| 599 | |
| 600 | BOXEDWINE_CRITICAL_SECTION_WITH_CONDITION(pendingConnection->lockCond); |
| 601 | std::shared_ptr<KUnixSocketObject> resultSocket = std::make_shared<KUnixSocketObject>(domain, type, protocol); |
| 602 | KFileDescriptorPtr result = thread->process->allocFileDescriptor(resultSocket, K_O_RDWR, 0, -1, 0); |
| 603 | |
| 604 | if (flags & FD_CLOEXEC) { |
| 605 | result->descriptorFlags|=FD_CLOEXEC; |
| 606 | } |
| 607 | if (flags & K_O_NONBLOCK) { |
| 608 | result->kobject->setBlocking(false); |
| 609 | } |
| 610 | |
| 611 | pendingConnection->connection = resultSocket; |
| 612 | //pendingConnection->connected = true; this will be handled when the connecting thread is unblocked |
| 613 | |
| 614 | resultSocket->connected = true; |
| 615 | resultSocket->connection = pendingConnection; // weak reference |
| 616 | |
| 617 | BOXEDWINE_CONDITION_SIGNAL_ALL(pendingConnection->lockCond); |
| 618 | |
| 619 | return result->handle; |
| 620 | } |
| 621 | |
| 622 | U32 KUnixSocketObject::getsockname(KThread* thread, const KFileDescriptorPtr& fd, U32 address, U32 plen) { |
| 623 | KMemory* memory = thread->memory; |
nothing calls this directly
no test coverage detected