]> git.saurik.com Git - apple/libdispatch.git/blob - testing/mig/server.c
libdispatch-84.5.5.tar.gz
[apple/libdispatch.git] / testing / mig / server.c
1 #include <mach/mach.h>
2 #include <mach/mach_error.h>
3 #include <servers/bootstrap.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdbool.h>
8 #include <assert.h>
9 #include <dispatch/dispatch.h>
10
11 #include "hello_logger.h"
12 #include "hello_loggerServer.h"
13
14 static mach_port_t checkin_or_register(char *bname);
15
16 int main(void)
17 {
18 mach_port_t mp = checkin_or_register(HELLO_LOGGER_BOOTSTRAP_NAME);
19 dispatch_source_t ds = dispatch_source_mig_new(mp, do_hello_logger_subsystem.maxsize, hello_logger_server, NULL, NULL, NULL);
20
21 assert(ds);
22
23 dispatch_main();
24
25 exit(EXIT_SUCCESS);
26 }
27
28 kern_return_t
29 do_example(mach_port_t test_port __attribute__((unused)), string_t somestring)
30 {
31 fprintf(stdout, "%s\n", somestring);
32
33 return KERN_SUCCESS;
34 }
35
36 mach_port_t
37 checkin_or_register(char *bname)
38 {
39 kern_return_t kr;
40 mach_port_t mp;
41
42 /* If we're started by launchd or the old mach_init */
43 kr = bootstrap_check_in(bootstrap_port, bname, &mp);
44 if (kr == KERN_SUCCESS)
45 return mp;
46
47 abort();
48 }