MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / main

Function main

Applications/IPCTest/main.cpp:115–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113
114int udsListener;
115int main(){
116
117 udsAddr.sun_family = AF_UNIX;
118 strcpy(udsAddr.sun_path, "testsocket");
119
120 udsListener = socket(AF_UNIX, SOCK_STREAM, 0);
121
122 if(bind(udsListener, reinterpret_cast<sockaddr*>(&udsAddr), sizeof(sockaddr_un) ) < 0){
123 printf("Error binding socket to address!\n");
124 return 1;
125 }
126
127 listen(udsListener, 0);
128
129 pthread_create(&t1, nullptr, UDSThread, nullptr);
130
131 int fd = accept(udsListener, nullptr, nullptr);
132
133 char msg[64];
134 for(int i = 0; i < msgCount; i++){
135 clock_gettime(CLOCK_BOOTTIME, &timer[i]);
136
137 send(fd, msg, 64, 0);
138 }
139
140 pthread_join(t1, nullptr);
141
142 svcHandle = syscall(SYS_CREATE_SERVICE, "lemon.testservice", 0, 0, 0, 0);
143 if(svcHandle <= 0){
144 printf("Failed to create service!");
145 return 1;
146 }
147
148 ifHandle = syscall(SYS_CREATE_INTERFACE, svcHandle, "testif", 64, 0, 0);
149 if(svcHandle <= 0){
150 printf("Failed to create interface!");
151 return 1;
152 }
153
154 pthread_create(&t2, nullptr, LemonIPCThread, nullptr);
155
156 long endpHandle = syscall(SYS_INTERFACE_ACCEPT, ifHandle, 0, 0, 0, 0);
157 while(!endpHandle){
158 endpHandle = syscall(SYS_INTERFACE_ACCEPT, ifHandle, 0, 0, 0, 0);
159 }
160
161 if(endpHandle <= 0){
162 printf("Error accepting connection on interface!");
163 return 0;
164 }
165
166 for(int i = 0; i < msgCount; i++){
167 clock_gettime(CLOCK_BOOTTIME, &timer[i]);
168 syscall(SYS_ENDPOINT_QUEUE, endpHandle, 0xDEADBEEF, 64, msg, 0);
169 }
170
171 pthread_join(t2, nullptr);
172

Callers

nothing calls this directly

Calls 1

strcpyFunction · 0.85

Tested by

no test coverage detected