30 #ifndef __CLAW_SOCKET_TRAITS_WIN32_HPP__ 31 #define __CLAW_SOCKET_TRAITS_WIN32_HPP__ 36 #include <sys/types.h> 66 version = MAKEWORD(2, 2);
68 return WSAStartup(version, &data) == 0;
77 return WSACleanup() == 0;
88 fd = socket(AF_INET, SOCK_STREAM, 0);
100 return ::closesocket(d) == 0;
115 struct hostent* hp = gethostbyname(address.c_str());
119 struct sockaddr_in sa;
121 memset(&sa,
'\0',
sizeof(sa));
122 sa.sin_family = hp->h_addrtype;
123 sa.sin_port = htons(port);
124 memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
126 if(::
connect(d, (
struct sockaddr*)&sa,
sizeof(sa)) != SOCKET_ERROR)
144 struct sockaddr_in addr;
146 memset(&addr,
'\0',
sizeof(addr));
147 addr.sin_family = AF_INET;
148 addr.sin_port = htons(port);
149 addr.sin_addr.s_addr = htonl(INADDR_ANY);
151 if(bind(d, (
struct sockaddr*)&addr,
sizeof(addr)) != SOCKET_ERROR)
152 return ::listen(d, queue_size) != SOCKET_ERROR;
169 struct timeval tv, *ptv;
176 tv.tv_sec = time_limit;
185 select(d + 1, &fds, NULL, NULL, ptv);
187 return FD_ISSET(d, &fds);
197 return ::accept(d, NULL, NULL);
220 typedef socket_traits_win32 socket_traits;
223 #endif // __CLAW_SOCKET_TRAITS_WIN32_HPP__ static bool connect(descriptor d, const std::string &address, int port)
Connect a socket to a port.
static descriptor open()
Open a socket.
static bool valid_descriptor(descriptor d)
Tell if a descriptor is a valid socket descriptor.
Win32 interface for using sockets.
SOCKET descriptor
Type of the system description of the socket.
static descriptor accept(descriptor d)
Accept an incoming connexion.
static bool listen(descriptor d, int port, unsigned int queue_size)
Open a socket for incoming connexions.
static bool close(descriptor d)
Close a socket.
static const descriptor invalid_socket
Invalid socket descriptor.
static bool init()
Initialize the use of the socket library.
static bool release()
Close the socket library.
static bool is_open(descriptor d)
Tell if a descriptor is a opened socket.
Some assert macros to strengthen you code.
This is the main namespace.
#define CLAW_PRECOND(b)
Abort the program if a precondition is not true.
static bool select_read(descriptor d, int time_limit=-1)
Select a socket for reading.