xref: /openbsd-src/usr.sbin/smtpd/ioev.h (revision 0b7734b3d77bb9b21afec6f4621cae6c805dbd45)
1 /*	$OpenBSD: ioev.h,v 1.6 2016/03/25 15:06:58 krw Exp $	*/
2 /*
3  * Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <event.h>
19 
20 enum {
21 	IO_CONNECTED = 0, 	/* connection successful	*/
22 	IO_TLSREADY,		/* TLS started successfully	*/
23 	IO_TLSVERIFIED,		/* XXX - needs more work	*/
24 	IO_TLSERROR,		/* XXX - needs more work	*/
25 	IO_DATAIN,		/* new data in input buffer	*/
26 	IO_LOWAT,		/* output queue running low	*/
27 	IO_DISCONNECTED,	/* error?			*/
28 	IO_TIMEOUT,		/* error?			*/
29 	IO_ERROR,		/* details?			*/
30 };
31 
32 #define IO_READ			0x01
33 #define IO_WRITE		0x02
34 #define IO_RW			(IO_READ | IO_WRITE)
35 #define IO_PAUSE_IN		0x04
36 #define IO_PAUSE_OUT		0x08
37 #define IO_RESET		0x10  /* internal */
38 #define IO_HELD			0x20  /* internal */
39 
40 struct iobuf;
41 struct io {
42 	int		 sock;
43 	void		*arg;
44 	void		(*cb)(struct io*, int);
45 	struct iobuf	*iobuf;
46 	size_t		 lowat;
47 	int		 timeout;
48 	int		 flags;
49 	int		 state;
50 	struct event	 ev;
51 	void		*ssl;
52 	const char	*error; /* only valid immediately on callback */
53 };
54 
55 void io_set_nonblocking(int);
56 void io_set_nolinger(int);
57 
58 void io_init(struct io*, int, void*, void(*)(struct io*, int), struct iobuf*);
59 void io_clear(struct io*);
60 void io_set_read(struct io *);
61 void io_set_write(struct io *);
62 void io_set_timeout(struct io *, int);
63 void io_set_lowat(struct io *, size_t);
64 void io_pause(struct io *, int);
65 void io_resume(struct io *, int);
66 void io_reload(struct io *);
67 int io_connect(struct io *, const struct sockaddr *, const struct sockaddr *);
68 int io_start_tls(struct io *, void *);
69 const char* io_strio(struct io *);
70 const char* io_strevent(int);
71