author | Tero Marttila <terom@fixme.fi> |
Sun, 15 Mar 2009 23:22:57 +0200 | |
branch | modules |
changeset 57 | ce1accba5fc7 |
parent 56 | 942370000450 |
child 63 | d399a1d915a3 |
permissions | -rw-r--r-- |
3 | 1 |
#ifndef ERROR_H |
2 |
#define ERROR_H |
|
3 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
4 |
/** |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
5 |
* @file |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
6 |
* |
3 | 7 |
* Error-handling functions |
8 |
*/ |
|
9 |
#include <errno.h> |
|
10 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
11 |
/** |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
12 |
* The type used for error codes is an explicitly *unsigned* int, meaning that error codes themselves are positive. |
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
13 |
* Negative error codes (as signed ints) also exist in some places, and they are just a negative err_t. |
3 | 14 |
*/ |
15 |
typedef unsigned int err_t; |
|
16 |
||
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
17 |
/** |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
18 |
* Ways to interpret error_info.extra |
7 | 19 |
*/ |
20 |
enum error_extra_types { |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
21 |
/** No extra info */ |
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
22 |
ERR_EXTRA_NONE = 0, |
7 | 23 |
|
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
24 |
/** libc errno, using strerror() */ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
25 |
ERR_EXTRA_ERRNO, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
26 |
|
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
27 |
/** libc resolver, using gai_strerror() */ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
28 |
ERR_EXTRA_GAI, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
29 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
30 |
/** GnuTLS, using gnutls_strerror() */ |
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
31 |
ERR_EXTRA_GNUTLS, |
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
32 |
|
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
33 |
/** Static error message string */ |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
34 |
ERR_EXTRA_STR, |
7 | 35 |
}; |
36 |
||
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
37 |
/** |
3 | 38 |
* List of defined error codes, organized mostly by function name |
39 |
*/ |
|
40 |
enum error_code { |
|
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
41 |
_ERR_INVALID = 0x000000, |
3 | 42 |
|
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
43 |
/** stdlib.h functions */ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
44 |
_ERR_STDLIB = 0x000100, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
45 |
ERR_CALLOC, |
37
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
46 |
ERR_STRDUP, |
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
47 |
|
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
48 |
/** DNS resolver */ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
49 |
_ERR_RESOLVER = 0x000200, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
50 |
ERR_GETADDRINFO, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
51 |
ERR_GETADDRINFO_EMPTY, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
52 |
|
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
53 |
/** @see sock_error_code*/ |
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
54 |
_ERR_SOCK = 0x000300, |
4
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
55 |
|
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
56 |
/** @see sock_gnutls_error_code */ |
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
57 |
_ERR_GNUTLS = 0x000400, |
10
9fe218576d13
fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
58 |
|
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
59 |
/** Libevent errors */ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
60 |
_ERR_LIBEVENT = 0x000500, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
61 |
ERR_EVENT_NEW, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
62 |
ERR_EVENT_ADD, |
17 | 63 |
|
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
64 |
/** Evsql errors */ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
65 |
_ERR_EVSQL = 0x000600, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
66 |
ERR_EVSQL_NEW_PQ, |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
67 |
|
37
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
68 |
/** irc_proto errors */ |
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
69 |
_ERR_IRC_LINE = 0x000700, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
70 |
ERR_LINE_TOO_LONG, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
71 |
ERR_LINE_INVALID_TOKEN, |
37
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
72 |
ERR_INVALID_NM, |
4fe4a3c4496e
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
73 |
ERR_INVALID_NICK_LENGTH, |
27
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
74 |
|
e6639132bead
add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
75 |
/** irc_conn errors */ |
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
76 |
_ERR_IRC_CONN = 0x000800, |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
77 |
ERR_IRC_CONN_REGISTER_STATE, |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
78 |
ERR_IRC_CONN_QUIT_STATE, |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
79 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
80 |
/** irc_net errors */ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
81 |
_ERR_IRC_NET = 0x000900, |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
82 |
ERR_IRC_NET_QUIT_STATE, |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
83 |
|
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
84 |
/** @see module_error_code */ |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
85 |
_ERR_MODULE = 0x000a00, |
30
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
86 |
}; |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
87 |
|
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
88 |
/** |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
89 |
* Table of error descriptions |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
90 |
*/ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
91 |
struct error_desc { |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
92 |
/** The flat error code */ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
93 |
err_t code; |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
94 |
|
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
95 |
/** The short name */ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
96 |
const char *name; |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
97 |
|
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
98 |
/** How to interpret .extra */ |
7f8dd120933f
rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
99 |
enum error_extra_types extra_type; |
3 | 100 |
}; |
101 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
102 |
/** |
3 | 103 |
* An error code and associated extra infos |
104 |
*/ |
|
105 |
struct error_info { |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
106 |
/** The base error code */ |
3 | 107 |
err_t code; |
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
108 |
|
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
109 |
union { |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
110 |
/** Additional detail info, usually some third-party error code, as defined by the code's ERR_EXTRA_* */ |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
111 |
int extra; |
3 | 112 |
|
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
113 |
/** Additional info, stored as a pointer to a static string (note how dangerous this is) */ |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
114 |
const char *extra_str; |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
115 |
}; |
3 | 116 |
}; |
117 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
118 |
/** |
7 | 119 |
* Translate an err_t into a function name. |
6 | 120 |
*/ |
121 |
const char *error_name (err_t code); |
|
122 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
123 |
/** |
7 | 124 |
* Maximum length of error messages returned by error_msg (including NUL byte) |
125 |
*/ |
|
126 |
#define ERROR_MSG_MAXLEN 1024 |
|
127 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
128 |
/** |
7 | 129 |
* Translate an error_info into a message. |
130 |
* |
|
131 |
* This is returned as a pointer into a statically allocated buffer. It is not re-entrant. |
|
132 |
*/ |
|
8
be88e543c8ff
split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
133 |
const char *error_msg (const struct error_info *err); |
7 | 134 |
|
3 | 135 |
/** No error, evaulates as logical false */ |
136 |
#define SUCCESS (0) |
|
137 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
138 |
/** Evaulates to error_info.code as lvalue */ |
4
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
139 |
#define ERROR_CODE(err_info_ptr) ((err_info_ptr)->code) |
3 | 140 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
141 |
/** Evaulates to error_info.extra as lvalue */ |
4
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
142 |
#define ERROR_EXTRA(err_info_ptr) ((err_info_ptr)->extra) |
3 | 143 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
144 |
/** Set error_info.code to SUCCESS, evaulates as zero */ |
4
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
145 |
#define RESET_ERROR(err_info_ptr) ((err_info_ptr)->code = SUCCESS) |
3 | 146 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
147 |
/** Compare error_info.code != 0 */ |
4
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
148 |
#define IS_ERROR(err_info_ptr) (!!(err_info_ptr)->code) |
3 | 149 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
150 |
/** Compare the err_code/err_extra for an err_info */ |
10
9fe218576d13
fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
151 |
#define MATCH_ERROR(err_info_ptr, err_code, err_extra) ((err_info_ptr)->code == (err_code) && (err_info_ptr)->extra == (err_extra)) |
9fe218576d13
fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
152 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
153 |
/** Set error_info.code, but leave err_extra as-is. Evaluates to err_code */ |
4
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
154 |
#define SET_ERROR(err_info_ptr, err_code) ((err_info_ptr)->code = (err_code)) |
3 | 155 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
156 |
/** Set error_info.code/extra. XXX: should evaluate to err_code */ |
4
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
157 |
#define _SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra) (err_info_ptr)->code = (err_code); (err_info_ptr)->extra = (err_extra) |
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
158 |
#define SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra) do { _SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra); } while (0) |
3 | 159 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
160 |
/** Set error_info.code to err_code, and .extra to errno. XXX: should evaulate to err_code */ |
4
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
161 |
#define _SET_ERROR_ERRNO(err_info_ptr, err_code) _SET_ERROR_EXTRA(err_info_ptr, err_code, errno); |
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
162 |
#define SET_ERROR_ERRNO(err_info_ptr, err_code) SET_ERROR_EXTRA(err_info_ptr, err_code, errno); |
3 | 163 |
|
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
164 |
/** |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
165 |
* Set error_info.code to err_code, and .extra_str to str. The given string pointer should remain valid while the error |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
166 |
* is being handled down-stack. |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
167 |
*/ |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
168 |
#define _SET_ERROR_STR(err_info_ptr, err_code, err_str) (err_info_ptr)->code = (err_code); (err_info_ptr)->extra_str = (err_str) |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
169 |
#define SET_ERROR_STR(err_info_ptr, err_code, err_str) do { _SET_ERROR_STR(err_info_ptr, err_code, err_str); } while(0) |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
170 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
171 |
/** Set error_info from another error_info. Evaluates to the new error_info */ |
5 | 172 |
#define SET_ERROR_INFO(err_info_ptr, from_ptr) (*err_info_ptr = *from_ptr) |
173 |
||
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
174 |
/** Same as above, but also return err_code from func. XXX: use 'return SET_ERROR...' instead */ |
5 | 175 |
#define RETURN_SET_ERROR(err_info_ptr, err_code) do { SET_ERROR(err_info_ptr, err_code); return (err_code); } while (0) |
4
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
176 |
#define RETURN_SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra) do { _SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra); return (err_code); } while (0) |
a3ca0f97a075
change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
177 |
#define RETURN_SET_ERROR_ERRNO(err_info_ptr, err_code) do { _SET_ERROR_ERRNO(err_info_ptr, err_code); return (err_code); } while (0) |
8
be88e543c8ff
split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
178 |
#define RETURN_SET_ERROR_INFO(err_info_ptr, from_ptr) do { SET_ERROR_INFO(err_info_ptr, from_ptr); return (from_ptr->code); } while (0) |
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
179 |
#define RETURN_SET_ERROR_STR(err_info_ptr, err_code, err_str) do { _SET_ERROR_STR(err_info_ptr, err_code, err_str); return (err_code); } while (0) |
3 | 180 |
|
34
763f65f9df0c
add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents:
30
diff
changeset
|
181 |
/** Same as above, but also do a 'goto error' */ |
5 | 182 |
#define JUMP_SET_ERROR(err_info_ptr, err_code) do { SET_ERROR(err_info_ptr, err_code); goto error; } while (0) |
183 |
#define JUMP_SET_ERROR_INFO(err_info_ptr, from_ptr) do { SET_ERROR_INFO(err_info_ptr, from_ptr); goto error; } while (0) |
|
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
184 |
#define JUMP_SET_ERROR_STR(err_info_ptr, err_code, err_str) do { _SET_ERROR_STR(err_info_ptr, err_code, err_str); goto error; } while (0) |
5 | 185 |
|
3 | 186 |
#endif |