+
+struct IODescriptor;
+struct IOLowlevelDescriptor;
+
+extern struct IOLowlevelDescriptor *first_descriptor;
+extern struct IOLowlevelDescriptor *timer_priority;
+extern struct IOLowlevelDescriptor *lowlevel_descriptor;
+
+#define IOLOWLEVEL_CALLBACK(NAME) void NAME(struct IOLowlevelDescriptor *iold, int can_read)
+typedef IOLOWLEVEL_CALLBACK(iolowlevel_callback);
+
+#define IOFLAGS_WANT_READ 0x01
+#define IOFLAGS_WANT_WRITE 0x02
+#define IOFLAGS_HAVE_IOFD 0x04
+#define IOFLAGS_HAVE_TIMEOUT 0x08
+
+#define IOFDFLAGS_HAVE_IOLD 0x01
+#define IOFDFLAGS_FREE_LOCK 0x02
+#define IOFDFLAGS_WANT_FREE 0x04
+#define IOFDFLAGS_SSL_ACTIVE 0x08
+#define IOFDFLAGS_SSL_SERVER_HS 0x10
+#define IOFDFLAGS_SSL_HS_READ 0x20
+#define IOFDFLAGS_SSL_HS_WRITE 0x40
+
+struct IOLowlevelDescriptor {
+ int fd;
+ unsigned int flags;
+ struct timeval timeout;
+ union {
+ struct IODescriptor *iofd;
+ iolowlevel_callback *callback;
+ } data;
+ struct IOLowlevelDescriptor *next, *prev;
+};
+
+#define IOLOWLEVEL_GET_IOFD(iold) ((iold->flags & IOFLAGS_HAVE_IOFD) ? iold->data.iofd : NULL)
+#define IODESCRIPTOR_GET_IOLD(iofd) ((iofd->flags & IOFDFLAGS_HAVE_IOLD) ? iofd->fd.iold : NULL)