3 * Copyright (c) 2018-2019 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * Definitions for simple dispatch implementation.
24 typedef struct dso_state dso_state_t
;
27 typedef union addr addr_t
;
30 struct sockaddr_in sin
;
31 struct sockaddr_in6 sin6
;
34 typedef struct message message_t
;
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
);
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
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
;
62 io_t
*NULLABLE cancel_on_close
;
67 struct dso_transport
{
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
;
79 size_t message_length_len
;
80 size_t message_length
, message_cur
;
81 uint8_t message_length_bytes
[2];
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
);
102 // c-file-style: "bsd"
105 // indent-tabs-mode: nil