MCPcopy Create free account
hub / github.com/axboe/liburing / main

Function main

examples/ucontext-cp.c:177–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177int main(int argc, char *argv[])
178{
179 struct io_uring ring;
180 int i, req_count, ret;
181 int success = 0, failure = 0;
182
183 if (argc < 3) {
184 fprintf(stderr, "%s: infile1 outfile1 [infile2 outfile2 [...]]\n", argv[0]);
185 return 1;
186 }
187
188 ret = io_uring_queue_init(QD, &ring, 0);
189 if (ret < 0) {
190 fprintf(stderr, "queue_init: %s\n", strerror(-ret));
191 return -1;
192 }
193
194 req_count = (argc - 1) / 2;
195 printf("copying %d files...\n", req_count);
196
197 for (i = 1; i < argc; i += 2) {
198 int infd, outfd;
199
200 async_context *pctx = malloc(sizeof(*pctx));
201
202 if (!pctx || setup_context(pctx, &ring))
203 return 1;
204
205 infd = open(argv[i], O_RDONLY);
206 if (infd < 0) {
207 perror("open infile");
208 return 1;
209 }
210 outfd = open(argv[i + 1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
211 if (outfd < 0) {
212 perror("open outfile");
213 return 1;
214 }
215
216 arguments_bundle *pbundle = malloc(sizeof(*pbundle));
217 pbundle->pctx = pctx;
218 pbundle->psuccess = &success;
219 pbundle->pfailure = &failure;
220 pbundle->infd = infd;
221 pbundle->outfd = outfd;
222
223 makecontext(&pctx->ctx_fnew, (void (*)(void)) copy_file_wrapper, 1, pbundle);
224
225 if (swapcontext(&pctx->ctx_main, &pctx->ctx_fnew)) {
226 perror("swapcontext");
227 return 1;
228 }
229 }
230
231 /* event loop */
232 while (success + failure < req_count) {
233 struct io_uring_cqe *cqe;
234

Callers

nothing calls this directly

Calls 5

io_uring_queue_initFunction · 0.85
io_uring_submit_and_waitFunction · 0.85
io_uring_cqe_get_dataFunction · 0.85
io_uring_queue_exitFunction · 0.85
setup_contextFunction · 0.70

Tested by

no test coverage detected