MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / ksocketpair

Function ksocketpair

source/kernel/ksocket.cpp:161–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161U32 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
210U32 ksend(KThread* thread, U32 socket, U32 buffer, U32 len, U32 flags) {
211 KFileDescriptorPtr fd = thread->process->getFileDescriptor(socket);

Callers 5

openDisplayMethod · 0.85
syscall_pipeFunction · 0.85
syscall_socketcallFunction · 0.85
syscall_pipe2Function · 0.85
syscall_socketpairFunction · 0.85

Calls 5

kwarn_fmtFunction · 0.85
ksocketFunction · 0.85
getFileDescriptorMethod · 0.80
fcntrlMethod · 0.80
writedMethod · 0.45

Tested by

no test coverage detected