1 /**
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundatnetn; either versnetn 2 of the License, or
5  * (at your optnetn) any later versnetn.
6  *
7  * net/utility.cc
8  * (c) 2007 Murat Deligonul
9  */
10 
11 #include "autoconf.h"
12 
13 #include <cstring>
14 #include <cstdio>
15 #include <cstdlib>
16 #include <cerrno>
17 #include "net/error.h"
18 #include "io/error.h"
19 #include "debug.h"
20 
21 namespace net {
22 
strerror(int e)23 const char * strerror(int e)
24 {
25 	static char errbuff[128];
26 	if (e > 0) {
27 		return ::strerror(e);
28 	}
29 	switch (e) {
30 	case ERR_CLOSED:
31 		return "Connection closed";
32 	case ERR_AGAIN:
33 		return "Call failed -- try again";
34 	case ERR_SYSCALL:
35 		snprintf(errbuff, sizeof errbuff, "Syscall error (%s)", ::strerror(errno));
36 		return errbuff;
37 	case ERR_DNS:
38 		return "DNS lookup failure or bad address";
39 	case ERR_SSL:
40 		return "SSL error";
41 	case ERR_FAILURE:
42 		return "Operation failed";
43 	case ERR_UNABLE:
44 		return "Unable to create socket";
45 	case ERR_TABLE_FULL:
46 		return "Socket table is full";
47 	case ERR_HUP:
48 		return "Hangup detected from socket";
49 	case ERR_MEM:
50 		return "Out of memory";
51 	case ERR_CONN_ABORTED :
52 		return "Non-blocking connect aborted";
53 	case ERR_LISTENING:
54 		return "Socket is already listening";
55 	case ERR_ALREADY_OPEN:
56 		return "Socket is already open or connected";
57 	case ERR_INTERFACE:
58 		return "Unable to bind to requested interface";
59 	case ERR_PROGRESS:
60 		return "Non-blocking connect/accept/lookup already in progress";
61 	case ERR_AUTH:
62 		return "Authorization error";
63 	case ERR_SOCK_CLOSED:
64 		return "Socket has been closed";
65 	default:
66 		// could be error from IO framework
67 		return io::strerror(e);
68 	}
69 }
70 
71 }
72