1
#ifndef _XMLRPCSOCKET_H_
2
#define _XMLRPCSOCKET_H_
4
// XmlRpc++ Copyright (c) 2002-2008 by Chris Morley
7
# pragma warning(disable:4786) // identifier was truncated in debug info
15
//! A platform-independent socket API.
19
// On windows, a socket is an unsigned int large enough to hold a ptr
20
// This should match the definition of SOCKET in winsock2.h
23
typedef unsigned __int64 Socket;
25
typedef unsigned int Socket;
31
//! An invalid socket constant.
32
static const Socket Invalid = (Socket) -1;
34
//! Creates a stream (TCP) socket. Returns XmlRpcSocket::Invalid on failure.
35
static Socket socket();
38
static void close(Socket socket);
41
//! Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
42
static bool setNonBlocking(Socket socket);
45
// The next four methods are appropriate for servers.
47
//! Allow the port the specified socket is bound to to be re-bound immediately so
48
//! server re-starts are not delayed. Returns false on failure.
49
static bool setReuseAddr(Socket socket);
51
//! Bind to a specified port
52
static bool bind(Socket socket, int port);
54
//! Set socket in listen mode
55
static bool listen(Socket socket, int backlog);
57
//! Accept a client connection request
58
static Socket accept(Socket socket);
60
//! Connect a socket to a server (from a client)
61
static bool connect(Socket socket, std::string& host, int port);
63
//! Get the port of a bound socket
64
static int getPort(Socket socket);
66
//! Returns true if the last error was not a fatal one (eg, EWOULDBLOCK)
67
static bool nonFatalError();
69
//! Returns last errno
70
static int getError();
72
//! Returns message corresponding to last error
73
static std::string getErrorMsg();
75
//! Returns message corresponding to error
76
static std::string getErrorMsg(int error);