1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* Copyright (C) 2007-2008 Xagasoft, All rights reserved.
*
* This file is part of the libbu++ library and is released under the
* terms of the license contained in the file LICENSE.
*/
#ifndef WIN32_COMPATIBILITY__H
#define WIN32_COMPATIBILITY__H
#ifdef WIN32
#define DYNLOAD DynamicWinsock2::
#else
#define DYNLOAD
#endif
#ifdef WIN32
#ifdef __cplusplus
extern "C"
{
#include <Winsock2.h>
#include <ws2tcpip.h>
}
#endif
#include "bu/fstring.h"
#include "bu/singleton.h"
#ifndef TEMP_FAILURE_RETRY
#define TEMP_FAILURE_RETRY(expression) \
(__extension__ \
({ long int __result; \
do __result = (long int) (expression); \
while (__result == -1L && errno == EINTR); \
__result; }))
#endif
__extension__ typedef int socklen_t;
namespace DynamicWinsock2
{
int WSAStartup(WORD wVersionRequested,LPWSADATA lpWSAData);
int WSACleanup(void);
int WSAGetLastError();
void inet_ntoa( Bu::FString &out, struct in_addr addr_in );
unsigned long inet_addr( const char *s_in );
int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const struct timeval *timeout);
SOCKET socket(int domain, int type, int protocol);
int ioctlsocket(SOCKET s, long cmd, u_long *argp);
u_short htons(u_short in);
u_long htonl(u_long in);
struct hostent *gethostbyname(const char *name);
void freeaddrinfo(struct addrinfo *ai);
int getaddrinfo(
const char *nodename, const char *servname,
const struct addrinfo *hints, struct addrinfo **res );
int connect(SOCKET s, const struct sockaddr *serv_addr, int addrlen);
int getpeername(SOCKET s, struct sockaddr *name, int *namelen);
int setsockopt(SOCKET s, int level, int optname,
const char *optval, int optlen);
int bind(SOCKET s, const struct sockaddr *my_addr, int addrlen);
int listen(SOCKET s, int backlog);
SOCKET accept(SOCKET s, struct sockaddr *addr, int *addrlen);
int recv( SOCKET s, char *buf, int len, int flags );
int send( SOCKET s, const char *buf, int len, int flags );
int DYN_FD_ISSET(SOCKET s, fd_set *set);
class Winsock2 : public Bu::Singleton<Winsock2>
{
friend class Bu::Singleton<Winsock2>;
private:
Winsock2();
virtual ~Winsock2();
WSADATA wsaData;
public:
}
};
#endif /* WIN32 */
#endif
|