xref: /openbsd-src/usr.sbin/smtpd/ioev.h (revision 4c1e55dc91edd6e69ccc60ce855900fbc12cf34f)
1 /*	$OpenBSD: ioev.h,v 1.1 2012/01/29 00:32:51 eric 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 succesfully	*/
23 	IO_DATAIN,		/* new data in input buffer	*/
24 	IO_LOWAT,		/* output queue running low	*/
25 	IO_DISCONNECTED,	/* error?			*/
26 	IO_TIMEOUT,		/* error?			*/
27 	IO_ERROR,		/* details?			*/
28 };
29 
30 #define IO_READ			0x01
31 #define IO_WRITE		0x02
32 #define IO_RW			(IO_READ | IO_WRITE)
33 #define IO_PAUSE_IN		0x04
34 #define IO_PAUSE_OUT		0x08
35 #define IO_RESET		0x10  /* internal */
36 #define IO_HELD			0x20  /* internal */
37 
38 struct iobuf;
39 struct io {
40 	int		 sock;
41 	void		*arg;
42 	void		(*cb)(struct io*, int);
43 	struct iobuf	*iobuf;
44 	size_t		 lowat;
45 	int		 timeout;
46 	int		 flags;
47 	int		 state;
48 	struct event	 ev;
49 	void		*ssl;
50 };
51 
52 void io_set_blocking(int, int);
53 void io_set_linger(int, int);
54 
55 void io_init(struct io*, int, void*, void(*)(struct io*, int), struct iobuf*);
56 void io_clear(struct io*);
57 void io_set_read(struct io *);
58 void io_set_write(struct io *);
59 void io_set_timeout(struct io *, int);
60 void io_set_lowat(struct io *, size_t);
61 void io_pause(struct io *, int);
62 void io_resume(struct io *, int);
63 void io_reload(struct io *);
64 int io_connect(struct io *, const struct sockaddr *);
65 int io_start_tls(struct io *, void *);
66 const char* io_strio(struct io *);
67 const char* io_strevent(int);
68