| 159 | } |
| 160 | |
| 161 | U32 ksocketpair(KThread* thread, U32 af, U32 type, U32 protocol, U32 socks, U32 flags) { |
| 162 | FD fd1 = 0; |
| 163 | FD fd2 = 0; |
| 164 | KFileDescriptorPtr f1; |
| 165 | KFileDescriptorPtr f2; |
| 166 | std::shared_ptr<KUnixSocketObject> s1; |
| 167 | std::shared_ptr<KUnixSocketObject> s2; |
| 168 | KMemory* memory = thread->memory; |
| 169 | |
| 170 | BOXEDWINE_CRITICAL_SECTION_WITH_MUTEX(thread->process->fdsMutex); |
| 171 | |
| 172 | if (af!=K_AF_UNIX) { |
| 173 | kwarn_fmt("socketpair with adress family %d not implemented", af); |
| 174 | return -1; |
| 175 | } |
| 176 | if (type!=K_SOCK_DGRAM && type!=K_SOCK_STREAM) { |
| 177 | kwarn_fmt("socketpair with type %d not implemented", type); |
| 178 | return -1; |
| 179 | } |
| 180 | fd1 = ksocket(af, type, protocol); |
| 181 | fd2 = ksocket(af, type, protocol); |
| 182 | f1 = thread->process->getFileDescriptor(fd1); |
| 183 | f2 = thread->process->getFileDescriptor(fd2); |
| 184 | s1 = std::dynamic_pointer_cast<KUnixSocketObject>(f1->kobject); |
| 185 | s2 = std::dynamic_pointer_cast<KUnixSocketObject>(f2->kobject); |
| 186 | |
| 187 | s1->connection = s2; |
| 188 | s2->connection = s1; |
| 189 | s1->connected = true; |
| 190 | s2->connected = true; |
| 191 | f1->accessFlags = K_O_RDWR; |
| 192 | f2->accessFlags = K_O_RDWR; |
| 193 | memory->writed(socks, fd1); |
| 194 | memory->writed(socks + 4, fd2); |
| 195 | |
| 196 | if ((flags & K_O_CLOEXEC)!=0) { |
| 197 | thread->process->fcntrl(thread, fd1, K_F_SETFD, FD_CLOEXEC); |
| 198 | thread->process->fcntrl(thread, fd2, K_F_SETFD, FD_CLOEXEC); |
| 199 | } |
| 200 | if ((flags & K_O_NONBLOCK)!=0) { |
| 201 | thread->process->fcntrl(thread, fd1, K_F_SETFL, K_O_NONBLOCK); |
| 202 | thread->process->fcntrl(thread, fd2, K_F_SETFL, K_O_NONBLOCK); |
| 203 | } |
| 204 | if (flags & ~(K_O_CLOEXEC|K_O_NONBLOCK)) { |
| 205 | kwarn_fmt("Unknow flags sent to pipe2: %X", flags); |
| 206 | } |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | U32 ksend(KThread* thread, U32 socket, U32 buffer, U32 len, U32 flags) { |
| 211 | KFileDescriptorPtr fd = thread->process->getFileDescriptor(socket); |
no test coverage detected