1#ifndef _XMLRPCSOCKET_H_
2#define _XMLRPCSOCKET_H_
3//
4// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
5//
6#if defined(_MSC_VER)
7# pragma warning(disable:4786)    // identifier was truncated in debug info
8#endif
9
10#ifndef MAKEDEPEND
11# include <string>
12#endif
13
14namespace XmlRpc {
15
16  //! A platform-independent socket API.
17  class XmlRpcSocket {
18  public:
19
20    //! Creates a stream (TCP) socket. Returns -1 on failure.
21    static int socket();
22
23    //! Closes a socket.
24    static void close(int socket);
25
26
27    //! Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
28    static bool setNonBlocking(int socket);
29
30    //! Read text from the specified socket. Returns false on error.
31    static bool nbRead(int socket, std::string& s, bool *eof);
32
33    //! Write text to the specified socket. Returns false on error.
34    static bool nbWrite(int socket, std::string& s, int *bytesSoFar);
35
36
37    // The next four methods are appropriate for servers.
38
39    //! Allow the port the specified socket is bound to to be re-bound immediately so
40    //! server re-starts are not delayed. Returns false on failure.
41    static bool setReuseAddr(int socket);
42
43    //! Bind to a specified port
44    static bool bind(int socket, int port);
45
46    //! Set socket in listen mode
47    static bool listen(int socket, int backlog);
48
49    //! Accept a client connection request
50    static int accept(int socket);
51
52
53    //! Connect a socket to a server (from a client)
54    static bool connect(int socket, std::string& host, int port);
55
56
57    //! Returns last errno
58    static int getError();
59
60    //! Returns message corresponding to last error
61    static std::string getErrorMsg();
62
63    //! Returns message corresponding to error
64    static std::string getErrorMsg(int error);
65  };
66
67} // namespace XmlRpc
68
69#endif
70