diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/compat | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/compat')
-rw-r--r-- | src/compat/win32.cpp | 134 | ||||
-rw-r--r-- | src/compat/win32.h | 104 |
2 files changed, 119 insertions, 119 deletions
diff --git a/src/compat/win32.cpp b/src/compat/win32.cpp index e1151b0..38b9ad7 100644 --- a/src/compat/win32.cpp +++ b/src/compat/win32.cpp | |||
@@ -10,7 +10,7 @@ | |||
10 | #ifdef WIN32 | 10 | #ifdef WIN32 |
11 | 11 | ||
12 | #define deffunc( name ) \ | 12 | #define deffunc( name ) \ |
13 | Bu::Winsock2::FNDEF_DYN_ ##name Bu::Winsock2::_fnptr_ ##name = NULL | 13 | Bu::Winsock2::FNDEF_DYN_ ##name Bu::Winsock2::_fnptr_ ##name = NULL |
14 | 14 | ||
15 | char Bu::Winsock2::scode[32]; | 15 | char Bu::Winsock2::scode[32]; |
16 | 16 | ||
@@ -33,133 +33,133 @@ deffunc( getpeername ); | |||
33 | deffunc( setsockopt ); | 33 | deffunc( setsockopt ); |
34 | deffunc( bind ); | 34 | deffunc( bind ); |
35 | deffunc( listen ); | 35 | deffunc( listen ); |
36 | deffunc( accept ); | 36 | deffunc( accept ); |
37 | deffunc( recv ); | 37 | deffunc( recv ); |
38 | deffunc( send ); | 38 | deffunc( send ); |
39 | deffunc( __WSAFDIsSet ); | 39 | deffunc( __WSAFDIsSet ); |
40 | 40 | ||
41 | // Safely get a function from the library | 41 | // Safely get a function from the library |
42 | #define getfunc( name ) \ | 42 | #define getfunc( name ) \ |
43 | Bu::Winsock2::_fnptr_ ##name = (FNDEF_DYN_ ##name) \ | 43 | Bu::Winsock2::_fnptr_ ##name = (FNDEF_DYN_ ##name) \ |
44 | GetProcAddress( Ws2_32, #name ); \ | 44 | GetProcAddress( Ws2_32, #name ); \ |
45 | if( Bu::Winsock2::_fnptr_ ##name == NULL ) { \ | 45 | if( Bu::Winsock2::_fnptr_ ##name == NULL ) { \ |
46 | throw Bu::ExceptionBase("Error loading function " #name " from dll.");\ | 46 | throw Bu::ExceptionBase("Error loading function " #name " from dll.");\ |
47 | } (void)0 | 47 | } (void)0 |
48 | 48 | ||
49 | Bu::Winsock2::Winsock2() | 49 | Bu::Winsock2::Winsock2() |
50 | { | 50 | { |
51 | Ws2_32 = LoadLibrary(TEXT("WS2_32.DLL")); | 51 | Ws2_32 = LoadLibrary(TEXT("WS2_32.DLL")); |
52 | 52 | ||
53 | getfunc( WSAStartup ); | 53 | getfunc( WSAStartup ); |
54 | getfunc( WSACleanup ); | 54 | getfunc( WSACleanup ); |
55 | getfunc( WSAGetLastError ); | 55 | getfunc( WSAGetLastError ); |
56 | getfunc( inet_ntoa ); | 56 | getfunc( inet_ntoa ); |
57 | getfunc( inet_addr ); | 57 | getfunc( inet_addr ); |
58 | getfunc( select ); | 58 | getfunc( select ); |
59 | getfunc( socket ); | 59 | getfunc( socket ); |
60 | getfunc( shutdown ); | 60 | getfunc( shutdown ); |
61 | getfunc( ioctlsocket ); | 61 | getfunc( ioctlsocket ); |
62 | getfunc( htons ); | 62 | getfunc( htons ); |
63 | getfunc( htonl ); | 63 | getfunc( htonl ); |
64 | getfunc( gethostbyname ); | 64 | getfunc( gethostbyname ); |
65 | getfunc( freeaddrinfo ); | 65 | getfunc( freeaddrinfo ); |
66 | getfunc( getaddrinfo ); | 66 | getfunc( getaddrinfo ); |
67 | getfunc( connect ); | 67 | getfunc( connect ); |
68 | getfunc( getpeername ); | 68 | getfunc( getpeername ); |
69 | getfunc( setsockopt ); | 69 | getfunc( setsockopt ); |
70 | getfunc( bind ); | 70 | getfunc( bind ); |
71 | getfunc( listen ); | 71 | getfunc( listen ); |
72 | getfunc( accept ); | 72 | getfunc( accept ); |
73 | getfunc( recv ); | 73 | getfunc( recv ); |
74 | getfunc( send ); | 74 | getfunc( send ); |
75 | getfunc( __WSAFDIsSet ); | 75 | getfunc( __WSAFDIsSet ); |
76 | 76 | ||
77 | Bu::Winsock2::WSAStartup( MAKEWORD(2, 2), &wsaData ); | 77 | Bu::Winsock2::WSAStartup( MAKEWORD(2, 2), &wsaData ); |
78 | } | 78 | } |
79 | 79 | ||
80 | Bu::Winsock2::~Winsock2() | 80 | Bu::Winsock2::~Winsock2() |
81 | { | 81 | { |
82 | Bu::Winsock2::WSACleanup(); | 82 | Bu::Winsock2::WSACleanup(); |
83 | FreeLibrary( Ws2_32 ); | 83 | FreeLibrary( Ws2_32 ); |
84 | } | 84 | } |
85 | 85 | ||
86 | char *Bu::Winsock2::gai_strerror( int iCode ) | 86 | char *Bu::Winsock2::gai_strerror( int iCode ) |
87 | { | 87 | { |
88 | sprintf( scode, "%d (%d)", iCode, Bu::Winsock2::WSAGetLastError() ); | 88 | sprintf( scode, "%d (%d)", iCode, Bu::Winsock2::WSAGetLastError() ); |
89 | return scode; | 89 | return scode; |
90 | } | 90 | } |
91 | 91 | ||
92 | int Bu::Winsock2::WSAStartup( WORD a, LPWSADATA b ) { | 92 | int Bu::Winsock2::WSAStartup( WORD a, LPWSADATA b ) { |
93 | return (*Bu::Winsock2::_fnptr_WSAStartup)( a, b ); | 93 | return (*Bu::Winsock2::_fnptr_WSAStartup)( a, b ); |
94 | } | 94 | } |
95 | int Bu::Winsock2::WSACleanup( ) { | 95 | int Bu::Winsock2::WSACleanup( ) { |
96 | return (*Bu::Winsock2::_fnptr_WSACleanup)(); | 96 | return (*Bu::Winsock2::_fnptr_WSACleanup)(); |
97 | } | 97 | } |
98 | int Bu::Winsock2::WSAGetLastError( ) { | 98 | int Bu::Winsock2::WSAGetLastError( ) { |
99 | return (*Bu::Winsock2::_fnptr_WSAGetLastError)(); | 99 | return (*Bu::Winsock2::_fnptr_WSAGetLastError)(); |
100 | } | 100 | } |
101 | char * Bu::Winsock2::inet_ntoa( struct in_addr a ) { | 101 | char * Bu::Winsock2::inet_ntoa( struct in_addr a ) { |
102 | return (*Bu::Winsock2::_fnptr_inet_ntoa)( a ); | 102 | return (*Bu::Winsock2::_fnptr_inet_ntoa)( a ); |
103 | } | 103 | } |
104 | unsigned long Bu::Winsock2::inet_addr( const char *s_in ) { | 104 | unsigned long Bu::Winsock2::inet_addr( const char *s_in ) { |
105 | return (*Bu::Winsock2::_fnptr_inet_addr)( s_in ); | 105 | return (*Bu::Winsock2::_fnptr_inet_addr)( s_in ); |
106 | } | 106 | } |
107 | int Bu::Winsock2::select( int a, fd_set *b, fd_set *c, fd_set *d, | 107 | int Bu::Winsock2::select( int a, fd_set *b, fd_set *c, fd_set *d, |
108 | const struct timeval *e ) { | 108 | const struct timeval *e ) { |
109 | return (*Bu::Winsock2::_fnptr_select)( a, b, c, d, e ); | 109 | return (*Bu::Winsock2::_fnptr_select)( a, b, c, d, e ); |
110 | } | 110 | } |
111 | SOCKET Bu::Winsock2::socket( int domain, int type, int protocol ) { | 111 | SOCKET Bu::Winsock2::socket( int domain, int type, int protocol ) { |
112 | return (*Bu::Winsock2::_fnptr_socket)( domain, type, protocol ); | 112 | return (*Bu::Winsock2::_fnptr_socket)( domain, type, protocol ); |
113 | } | 113 | } |
114 | int Bu::Winsock2::shutdown( SOCKET s, int how ) { | 114 | int Bu::Winsock2::shutdown( SOCKET s, int how ) { |
115 | return (*Bu::Winsock2::_fnptr_shutdown)( s, how ); | 115 | return (*Bu::Winsock2::_fnptr_shutdown)( s, how ); |
116 | } | 116 | } |
117 | int Bu::Winsock2::ioctlsocket( SOCKET s, long cmd, u_long *argp ) { | 117 | int Bu::Winsock2::ioctlsocket( SOCKET s, long cmd, u_long *argp ) { |
118 | return (*Bu::Winsock2::_fnptr_ioctlsocket)( s, cmd, argp ); | 118 | return (*Bu::Winsock2::_fnptr_ioctlsocket)( s, cmd, argp ); |
119 | } | 119 | } |
120 | u_short Bu::Winsock2::htons( u_short in ) { | 120 | u_short Bu::Winsock2::htons( u_short in ) { |
121 | return (*Bu::Winsock2::_fnptr_htons)( in ); | 121 | return (*Bu::Winsock2::_fnptr_htons)( in ); |
122 | } | 122 | } |
123 | u_long Bu::Winsock2::htonl( u_long in ) { | 123 | u_long Bu::Winsock2::htonl( u_long in ) { |
124 | return (*Bu::Winsock2::_fnptr_htonl)( in ); | 124 | return (*Bu::Winsock2::_fnptr_htonl)( in ); |
125 | } | 125 | } |
126 | struct hostent * Bu::Winsock2::gethostbyname( const char *name ) { | 126 | struct hostent * Bu::Winsock2::gethostbyname( const char *name ) { |
127 | return (*Bu::Winsock2::_fnptr_gethostbyname)( name ); | 127 | return (*Bu::Winsock2::_fnptr_gethostbyname)( name ); |
128 | } | 128 | } |
129 | void Bu::Winsock2::freeaddrinfo( struct addrinfo *ai ) { | 129 | void Bu::Winsock2::freeaddrinfo( struct addrinfo *ai ) { |
130 | return (*Bu::Winsock2::_fnptr_freeaddrinfo)( ai ); | 130 | return (*Bu::Winsock2::_fnptr_freeaddrinfo)( ai ); |
131 | } | 131 | } |
132 | int Bu::Winsock2::getaddrinfo( const char *a, const char *b, | 132 | int Bu::Winsock2::getaddrinfo( const char *a, const char *b, |
133 | const struct addrinfo *c, struct addrinfo **d ) { | 133 | const struct addrinfo *c, struct addrinfo **d ) { |
134 | return (*Bu::Winsock2::_fnptr_getaddrinfo)( a, b, c, d ); | 134 | return (*Bu::Winsock2::_fnptr_getaddrinfo)( a, b, c, d ); |
135 | } | 135 | } |
136 | int Bu::Winsock2::connect( SOCKET s, const struct sockaddr *a, int b ) { | 136 | int Bu::Winsock2::connect( SOCKET s, const struct sockaddr *a, int b ) { |
137 | return (*Bu::Winsock2::_fnptr_connect)( s, a, b ); | 137 | return (*Bu::Winsock2::_fnptr_connect)( s, a, b ); |
138 | } | 138 | } |
139 | int Bu::Winsock2::getpeername( SOCKET s, struct sockaddr *a, int *b ) { | 139 | int Bu::Winsock2::getpeername( SOCKET s, struct sockaddr *a, int *b ) { |
140 | return (*Bu::Winsock2::_fnptr_getpeername)( s, a, b); | 140 | return (*Bu::Winsock2::_fnptr_getpeername)( s, a, b); |
141 | } | 141 | } |
142 | int Bu::Winsock2::setsockopt( SOCKET s, int a, int b, | 142 | int Bu::Winsock2::setsockopt( SOCKET s, int a, int b, |
143 | const char *c, int d ) { | 143 | const char *c, int d ) { |
144 | return (*Bu::Winsock2::_fnptr_setsockopt)( s, a, b, c, d ); | 144 | return (*Bu::Winsock2::_fnptr_setsockopt)( s, a, b, c, d ); |
145 | } | 145 | } |
146 | int Bu::Winsock2::bind( SOCKET s, const struct sockaddr *a, int b ) { | 146 | int Bu::Winsock2::bind( SOCKET s, const struct sockaddr *a, int b ) { |
147 | return (*Bu::Winsock2::_fnptr_bind)( s, a, b ); | 147 | return (*Bu::Winsock2::_fnptr_bind)( s, a, b ); |
148 | } | 148 | } |
149 | int Bu::Winsock2::listen( SOCKET s, int backlog ) { | 149 | int Bu::Winsock2::listen( SOCKET s, int backlog ) { |
150 | return (*Bu::Winsock2::_fnptr_listen)( s, backlog ); | 150 | return (*Bu::Winsock2::_fnptr_listen)( s, backlog ); |
151 | } | 151 | } |
152 | SOCKET Bu::Winsock2::accept( SOCKET s, struct sockaddr *a, int *b ) { | 152 | SOCKET Bu::Winsock2::accept( SOCKET s, struct sockaddr *a, int *b ) { |
153 | return (*Bu::Winsock2::_fnptr_accept)( s, a, b ); | 153 | return (*Bu::Winsock2::_fnptr_accept)( s, a, b ); |
154 | } | 154 | } |
155 | int Bu::Winsock2::recv( SOCKET s, char *buf, int len, int flags ) { | 155 | int Bu::Winsock2::recv( SOCKET s, char *buf, int len, int flags ) { |
156 | return (*Bu::Winsock2::_fnptr_recv)( s, buf, len, flags ); | 156 | return (*Bu::Winsock2::_fnptr_recv)( s, buf, len, flags ); |
157 | } | 157 | } |
158 | int Bu::Winsock2::send( SOCKET s, const char *buf, int len, int flags ) { | 158 | int Bu::Winsock2::send( SOCKET s, const char *buf, int len, int flags ) { |
159 | return (*Bu::Winsock2::_fnptr_send)( s, buf, len, flags ); | 159 | return (*Bu::Winsock2::_fnptr_send)( s, buf, len, flags ); |
160 | } | 160 | } |
161 | int Bu::Winsock2::__WSAFDIsSet( SOCKET s, fd_set *set ) { | 161 | int Bu::Winsock2::__WSAFDIsSet( SOCKET s, fd_set *set ) { |
162 | return (*Bu::Winsock2::_fnptr___WSAFDIsSet)( s, set ); | 162 | return (*Bu::Winsock2::_fnptr___WSAFDIsSet)( s, set ); |
163 | } | 163 | } |
164 | 164 | ||
165 | Bu::String Bu::getLastWinError() | 165 | Bu::String Bu::getLastWinError() |
@@ -177,11 +177,11 @@ Bu::String Bu::getLastWinError() | |||
177 | (LPSTR) &lpMsgBuf, | 177 | (LPSTR) &lpMsgBuf, |
178 | 0, NULL ); | 178 | 0, NULL ); |
179 | 179 | ||
180 | Bu::String sRet( (char *)lpMsgBuf ); | 180 | Bu::String sRet( (char *)lpMsgBuf ); |
181 | 181 | ||
182 | LocalFree(lpMsgBuf); | 182 | LocalFree(lpMsgBuf); |
183 | 183 | ||
184 | return sRet; | 184 | return sRet; |
185 | } | 185 | } |
186 | 186 | ||
187 | #endif | 187 | #endif |
diff --git a/src/compat/win32.h b/src/compat/win32.h index 7e44c13..0cc42b6 100644 --- a/src/compat/win32.h +++ b/src/compat/win32.h | |||
@@ -32,9 +32,9 @@ extern "C" | |||
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #define decltype( ret, name, ... ) \ | 34 | #define decltype( ret, name, ... ) \ |
35 | typedef ret (__cdecl *FNDEF_DYN_ ##name)( __VA_ARGS__ ); \ | 35 | typedef ret (__cdecl *FNDEF_DYN_ ##name)( __VA_ARGS__ ); \ |
36 | static FNDEF_DYN_ ##name _fnptr_ ##name; \ | 36 | static FNDEF_DYN_ ##name _fnptr_ ##name; \ |
37 | static ret name( __VA_ARGS__ ) | 37 | static ret name( __VA_ARGS__ ) |
38 | 38 | ||
39 | __extension__ typedef int socklen_t; | 39 | __extension__ typedef int socklen_t; |
40 | 40 | ||
@@ -44,54 +44,54 @@ __extension__ typedef int socklen_t; | |||
44 | 44 | ||
45 | namespace Bu | 45 | namespace Bu |
46 | { | 46 | { |
47 | class Winsock2 : public Bu::Singleton<Winsock2> | 47 | class Winsock2 : public Bu::Singleton<Winsock2> |
48 | { | 48 | { |
49 | friend class Bu::Singleton<Winsock2>; | 49 | friend class Bu::Singleton<Winsock2>; |
50 | private: | 50 | private: |
51 | Winsock2(); | 51 | Winsock2(); |
52 | virtual ~Winsock2(); | 52 | virtual ~Winsock2(); |
53 | 53 | ||
54 | WSADATA wsaData; | 54 | WSADATA wsaData; |
55 | HINSTANCE Ws2_32; | 55 | HINSTANCE Ws2_32; |
56 | 56 | ||
57 | public: | 57 | public: |
58 | // decltype( return type, function name<, optional parameters> ) | 58 | // decltype( return type, function name<, optional parameters> ) |
59 | decltype( int, WSAStartup, WORD, LPWSADATA ); | 59 | decltype( int, WSAStartup, WORD, LPWSADATA ); |
60 | decltype( int, WSACleanup ); | 60 | decltype( int, WSACleanup ); |
61 | decltype( int, WSAGetLastError ); | 61 | decltype( int, WSAGetLastError ); |
62 | decltype( char *, inet_ntoa, struct in_addr ); | 62 | decltype( char *, inet_ntoa, struct in_addr ); |
63 | decltype( unsigned long, inet_addr, const char *s_in ); | 63 | decltype( unsigned long, inet_addr, const char *s_in ); |
64 | decltype( int, select, int nfds, fd_set *readfds, fd_set *writefds, | 64 | decltype( int, select, int nfds, fd_set *readfds, fd_set *writefds, |
65 | fd_set *exceptfds, const struct timeval *timeout ); | 65 | fd_set *exceptfds, const struct timeval *timeout ); |
66 | decltype( SOCKET, socket, int domain, int type, int protocol ); | 66 | decltype( SOCKET, socket, int domain, int type, int protocol ); |
67 | decltype( int, shutdown, SOCKET s, int how ); | 67 | decltype( int, shutdown, SOCKET s, int how ); |
68 | decltype( int, ioctlsocket, SOCKET s, long cmd, u_long *argp ); | 68 | decltype( int, ioctlsocket, SOCKET s, long cmd, u_long *argp ); |
69 | decltype( u_short, htons, u_short in ); | 69 | decltype( u_short, htons, u_short in ); |
70 | decltype( u_long, htonl, u_long in ); | 70 | decltype( u_long, htonl, u_long in ); |
71 | decltype( struct hostent *, gethostbyname, const char *name ); | 71 | decltype( struct hostent *, gethostbyname, const char *name ); |
72 | decltype( void, freeaddrinfo, struct addrinfo *ai ); | 72 | decltype( void, freeaddrinfo, struct addrinfo *ai ); |
73 | decltype( int, getaddrinfo, const char *nodename, const char *servname, | 73 | decltype( int, getaddrinfo, const char *nodename, const char *servname, |
74 | const struct addrinfo *hints, struct addrinfo **res ); | 74 | const struct addrinfo *hints, struct addrinfo **res ); |
75 | decltype( int, connect, SOCKET s, const struct sockaddr *serv_addr, | 75 | decltype( int, connect, SOCKET s, const struct sockaddr *serv_addr, |
76 | int addrlen ); | 76 | int addrlen ); |
77 | decltype( int, getpeername, SOCKET s, struct sockaddr *name, | 77 | decltype( int, getpeername, SOCKET s, struct sockaddr *name, |
78 | int *namelen ); | 78 | int *namelen ); |
79 | decltype( int, setsockopt, SOCKET s, int level, int optname, | 79 | decltype( int, setsockopt, SOCKET s, int level, int optname, |
80 | const char *optval, int optlen ); | 80 | const char *optval, int optlen ); |
81 | decltype( int, bind, SOCKET s, const struct sockaddr *my_addr, | 81 | decltype( int, bind, SOCKET s, const struct sockaddr *my_addr, |
82 | int addrlen ); | 82 | int addrlen ); |
83 | decltype( int, listen, SOCKET s, int backlog ); | 83 | decltype( int, listen, SOCKET s, int backlog ); |
84 | decltype( SOCKET, accept, SOCKET s, struct sockaddr *addr, | 84 | decltype( SOCKET, accept, SOCKET s, struct sockaddr *addr, |
85 | int *addrlen); | 85 | int *addrlen); |
86 | decltype( int, recv, SOCKET s, char *buf, int len, int flags ); | 86 | decltype( int, recv, SOCKET s, char *buf, int len, int flags ); |
87 | decltype( int, send, SOCKET s, const char *buf, int len, int flags ); | 87 | decltype( int, send, SOCKET s, const char *buf, int len, int flags ); |
88 | decltype( int, __WSAFDIsSet, SOCKET s, fd_set *set ); | 88 | decltype( int, __WSAFDIsSet, SOCKET s, fd_set *set ); |
89 | 89 | ||
90 | static char scode[32]; | 90 | static char scode[32]; |
91 | static char *gai_strerror( int iCode ); | 91 | static char *gai_strerror( int iCode ); |
92 | }; | 92 | }; |
93 | 93 | ||
94 | Bu::String getLastWinError(); | 94 | Bu::String getLastWinError(); |
95 | }; | 95 | }; |
96 | 96 | ||
97 | #ifdef FD_ISSET | 97 | #ifdef FD_ISSET |
@@ -117,7 +117,7 @@ namespace Bu | |||
117 | #define bu_setsockopt (*Bu::Winsock2::setsockopt) | 117 | #define bu_setsockopt (*Bu::Winsock2::setsockopt) |
118 | #define bu_bind (*Bu::Winsock2::bind) | 118 | #define bu_bind (*Bu::Winsock2::bind) |
119 | #define bu_listen (*Bu::Winsock2::listen) | 119 | #define bu_listen (*Bu::Winsock2::listen) |
120 | #define bu_accept (*Bu::Winsock2::accept) | 120 | #define bu_accept (*Bu::Winsock2::accept) |
121 | #define bu_recv (*Bu::Winsock2::recv) | 121 | #define bu_recv (*Bu::Winsock2::recv) |
122 | #define bu_send (*Bu::Winsock2::send) | 122 | #define bu_send (*Bu::Winsock2::send) |
123 | #define bu___WSAFDIsSet (*Bu::Winsock2::__WSAFDIsSet) | 123 | #define bu___WSAFDIsSet (*Bu::Winsock2::__WSAFDIsSet) |