GComm  0.2.3
socket.hpp
1 //
2 // Copyright (C) 2009 Codership Oy <info@codership.com>
3 //
4 
6 // @file socket.hpp Socket interface.
7 //
8 // This file defines socket interface used by gcomm. Currently socket interface
9 // provides synchronous send() but only async_recv().
10 //
11 
12 #ifndef GCOMM_SOCKET_HPP
13 #define GCOMM_SOCKET_HPP
14 
15 #include "gcomm/datagram.hpp"
16 
17 #include "gu_uri.hpp"
18 
19 
20 namespace gcomm
21 {
22  typedef const void* SocketId;
23  class Socket;
24  typedef boost::shared_ptr<Socket> SocketPtr;
25  class Acceptor;
26 }
27 
28 
30 {
31 public:
32  typedef enum
33  {
34  S_CLOSED,
35  S_CONNECTING,
36  S_CONNECTED,
37  S_FAILED,
38  S_CLOSING
39  } State;
40 
44  static const std::string OptNonBlocking;
45  static const std::string OptIfAddr;
46  static const std::string OptIfLoop;
47  static const std::string OptCRC32;
48  static const std::string OptMcastTTL;
50  Socket(const gu::URI& uri)
51  :
52  uri_(uri)
53  { }
54 
55  virtual ~Socket() { }
56  virtual void connect(const gu::URI& uri) = 0;
57  virtual void close() = 0;
58 
59  virtual int send(const Datagram& dg) = 0;
60  virtual void async_receive() = 0;
61 
62  virtual size_t mtu() const = 0;
63  virtual std::string local_addr() const = 0;
64  virtual std::string remote_addr() const = 0;
65  virtual State state() const = 0;
66  virtual SocketId id() const = 0;
67 protected:
68  const gu::URI uri_;
69 };
70 
71 
73 {
74 public:
75  typedef enum
76  {
77  S_CLOSED,
78  S_LISTENING,
79  S_FAILED
80  } State;
81 
82  Acceptor(const gu::URI& uri)
83  :
84  uri_(uri)
85  { }
86 
87  virtual ~Acceptor() { }
88 
89  virtual void listen(const gu::URI& uri) = 0;
90  virtual std::string listen_addr() const = 0;
91  virtual void close() = 0;
92  virtual State state() const = 0;
93  virtual SocketPtr accept() = 0;
94  virtual SocketId id() const = 0;
95 protected:
96  const gu::URI uri_;
97 };
98 
99 #endif // GCOMM_SOCKET_HPP
Socket(const gu::URI &uri)
Definition: socket.hpp:50
static const std::string OptMcastTTL
Definition: socket.hpp:48
static const std::string OptCRC32
Definition: socket.hpp:47
static const std::string OptIfLoop
Definition: socket.hpp:46
static const std::string OptNonBlocking
Definition: socket.hpp:44
static const std::string OptIfAddr
Definition: socket.hpp:45
Definition: socket.hpp:72
Definition: socket.hpp:29