~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to src/xmlrpcpp/XmlRpcSocket.h

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-06-07 11:28:52 UTC
  • Revision ID: package-import@ubuntu.com-20140607112852-v4d5tb1m3h3vi0dl
Tags: upstream-1.3.15
ImportĀ upstreamĀ versionĀ 1.3.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _XMLRPCSOCKET_H_
 
2
#define _XMLRPCSOCKET_H_
 
3
//
 
4
// XmlRpc++ Copyright (c) 2002-2008 by Chris Morley
 
5
//
 
6
#if defined(_MSC_VER)
 
7
# pragma warning(disable:4786)    // identifier was truncated in debug info
 
8
#endif
 
9
 
 
10
#include <string>
 
11
 
 
12
 
 
13
namespace XmlRpc {
 
14
 
 
15
  //! A platform-independent socket API.
 
16
  class XmlRpcSocket {
 
17
  public:
 
18
 
 
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
 
21
#if defined(_WINDOWS)
 
22
# if defined(_WIN64)
 
23
    typedef unsigned __int64 Socket;
 
24
# else
 
25
    typedef unsigned int Socket;
 
26
# endif
 
27
#else
 
28
    typedef int Socket;
 
29
#endif
 
30
 
 
31
    //! An invalid socket constant.
 
32
    static const Socket Invalid = (Socket) -1;
 
33
 
 
34
    //! Creates a stream (TCP) socket. Returns XmlRpcSocket::Invalid on failure.
 
35
    static Socket socket();
 
36
 
 
37
    //! Closes a socket.
 
38
    static void close(Socket socket);
 
39
 
 
40
 
 
41
    //! Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
 
42
    static bool setNonBlocking(Socket socket);
 
43
 
 
44
 
 
45
    // The next four methods are appropriate for servers.
 
46
 
 
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);
 
50
 
 
51
    //! Bind to a specified port
 
52
    static bool bind(Socket socket, int port);
 
53
 
 
54
    //! Set socket in listen mode
 
55
    static bool listen(Socket socket, int backlog);
 
56
 
 
57
    //! Accept a client connection request
 
58
    static Socket accept(Socket socket);
 
59
 
 
60
    //! Connect a socket to a server (from a client)
 
61
    static bool connect(Socket socket, std::string& host, int port);
 
62
 
 
63
    //! Get the port of a bound socket
 
64
    static int getPort(Socket socket);
 
65
 
 
66
    //! Returns true if the last error was not a fatal one (eg, EWOULDBLOCK)
 
67
    static bool nonFatalError();
 
68
 
 
69
    //! Returns last errno
 
70
    static int getError();
 
71
 
 
72
    //! Returns message corresponding to last error
 
73
    static std::string getErrorMsg();
 
74
 
 
75
    //! Returns message corresponding to error
 
76
    static std::string getErrorMsg(int error);
 
77
  };
 
78
 
 
79
} // namespace XmlRpc
 
80
 
 
81
#endif