]> git.saurik.com Git - apple/mdnsresponder.git/blob - ServiceRegistration/ioloop.h
mDNSResponder-1096.0.2.tar.gz
[apple/mdnsresponder.git] / ServiceRegistration / ioloop.h
1 /* ioloop.c
2 *
3 * Copyright (c) 2018-2019 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Definitions for simple dispatch implementation.
18 */
19
20 #ifndef __IOLOOP_H
21 #define __IOLOOP_H
22
23 #ifndef __DSO_H
24 typedef struct dso_state dso_state_t;
25 #endif
26
27 typedef union addr addr_t;
28 union addr {
29 struct sockaddr sa;
30 struct sockaddr_in sin;
31 struct sockaddr_in6 sin6;
32 };
33
34 typedef struct message message_t;
35 struct message {
36 addr_t src;
37 int ifindex;
38 size_t length;
39 dns_wire_t wire;
40 };
41
42 typedef struct dso_transport comm_t;
43 typedef struct io io_t;
44 typedef void (*io_callback_t)(io_t *NONNULL io);
45 typedef void (*comm_callback_t)(comm_t *NONNULL comm);
46 typedef void (*send_response_t)(comm_t *NONNULL comm, message_t *NONNULL responding_to, struct iovec *NONNULL iov, int count);
47
48 #define IOLOOP_SECOND 1000LL
49 #define IOLOOP_MINUTE 60 * IOLOOP_SECOND
50 #define IOLOOP_HOUR 60 * IOLOOP_MINUTE
51 #define IOLOOP_DAY 24 * IOLOOP_HOUR
52
53 struct io {
54 io_t *NULLABLE next;
55 io_callback_t NULLABLE read_callback;
56 io_callback_t NULLABLE write_callback;
57 io_callback_t NULLABLE finalize;
58 io_callback_t NULLABLE wakeup;
59 io_callback_t NULLABLE cancel;
60 int sock;
61 int64_t wakeup_time;
62 io_t *NULLABLE cancel_on_close;
63 bool want_read : 1;
64 bool want_write : 1;
65 };
66
67 struct dso_transport {
68 io_t io;
69 char *NONNULL name;
70 void *NULLABLE context;
71 comm_callback_t NULLABLE datagram_callback;
72 comm_callback_t NULLABLE close_callback;
73 send_response_t NULLABLE send_response;
74 comm_callback_t NULLABLE connected;
75 message_t *NULLABLE message;
76 uint8_t *NULLABLE buf;
77 dso_state_t *NULLABLE dso;
78 addr_t address;
79 size_t message_length_len;
80 size_t message_length, message_cur;
81 uint8_t message_length_bytes[2];
82 bool tcp_stream: 1;
83 };
84
85 extern int64_t ioloop_now;
86 int getipaddr(addr_t *NONNULL addr, const char *NONNULL p);
87 int64_t ioloop_timenow(void);
88 message_t *NULLABLE message_allocate(size_t message_size);
89 void message_free(message_t *NONNULL message);
90 void comm_free(comm_t *NONNULL comm);
91 void ioloop_close(io_t *NONNULL io);
92 void add_reader(io_t *NONNULL io, io_callback_t NONNULL callback, io_callback_t NULLABLE finalize);
93 bool ioloop_init(void);
94 int ioloop_events(int64_t timeout_when);
95 comm_t *NULLABLE setup_listener_socket(int family, int protocol, uint16_t port, const char *NONNULL name,
96 comm_callback_t NONNULL datagram_callback,
97 comm_callback_t NULLABLE connected, void *NULLABLE context);
98 #endif
99 // Local Variables:
100 // mode: C
101 // tab-width: 4
102 // c-file-style: "bsd"
103 // c-basic-offset: 4
104 // fill-column: 108
105 // indent-tabs-mode: nil
106 // End: