Kea  2.3.2-git
socketsession.h
Go to the documentation of this file.
1 // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef SOCKETSESSION_H
8 #define SOCKETSESSION_H 1
9 
10 #include <boost/noncopyable.hpp>
11 
12 #include <exceptions/exceptions.h>
13 
14 #include <string>
15 
16 #include <sys/socket.h>
17 
18 namespace isc {
19 namespace util {
20 namespace io {
21 
144 
152 public:
153  SocketSessionError(const char *file, size_t line, const char *what):
154  isc::Exception(file, line, what) {}
155 };
156 
173 protected:
175 
176 public:
178  virtual void connectToReceiver() = 0;
179  virtual void close() = 0;
180  virtual void push(int sock, int family, int type, int protocol,
181  const struct sockaddr& local_end,
182  const struct sockaddr& remote_end,
183  const void* data, size_t data_len) = 0;
184 };
185 
194 class SocketSessionForwarder : boost::noncopyable,
196 {
197 public:
238  explicit SocketSessionForwarder(const std::string& unix_file);
239 
244  virtual ~SocketSessionForwarder();
245 
256  virtual void connectToReceiver();
257 
264  virtual void close();
265 
308  virtual void push(int sock, int family, int type, int protocol,
309  const struct sockaddr& local_end,
310  const struct sockaddr& remote_end,
311  const void* data, size_t data_len);
312 
313 private:
314  struct ForwarderImpl;
315  ForwarderImpl* impl_;
316 };
317 
334 public:
358  SocketSession(int sock, int family, int type, int protocol,
359  const sockaddr* local_end, const sockaddr* remote_end,
360  const void* data, size_t data_len);
361 
363  int getSocket() const { return (sock_); }
364 
366  int getFamily() const { return (family_); }
367 
369  int getType() const { return (type_); }
370 
372  int getProtocol() const { return (protocol_); }
373 
375  const sockaddr& getLocalEndpoint() const { return (*local_end_); }
376 
378  const sockaddr& getRemoteEndpoint() const { return (*remote_end_); }
379 
385  const void* getData() const { return (data_); }
386 
390  size_t getDataLength() const { return (data_len_); }
391 
392 private:
393  const int sock_;
394  const int family_;
395  const int type_;
396  const int protocol_;
397  const sockaddr* local_end_;
398  const sockaddr* remote_end_;
399  const void* const data_;
400  const size_t data_len_;
401 };
402 
422 class SocketSessionReceiver : boost::noncopyable {
423 public:
432  explicit SocketSessionReceiver(int fd);
433 
441 
480  SocketSession pop();
481 
482 private:
483  struct ReceiverImpl;
484  ReceiverImpl* impl_;
485 };
486 
487 }
488 }
489 }
490 
491 #endif // SOCKETSESSION_H
492 
493 // Local Variables:
494 // mode: c++
495 // End:
int getProtocol() const
Return the transport protocol (such as IPPROTO_UDP) of the socket.
int getSocket() const
Return the socket file descriptor.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
SocketSessionError(const char *file, size_t line, const char *what)
An exception indicating general errors that takes place in the socket session related class objects...
int getType() const
Return the socket type (such as SOCK_DGRAM) of the socket.
The "base" class of SocketSessionForwarder.
const sockaddr & getLocalEndpoint() const
Return the local end point of the session in the form of sockaddr.
The forwarder of socket sessions.
const void * getData() const
Return a pointer to the beginning of the memory region for the session data.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
size_t getDataLength() const
Return the size of the session data in bytes.
The receiver of socket sessions.
const sockaddr & getRemoteEndpoint() const
Return the remote end point of the session in the form of sockaddr.
Socket session object.
int getFamily() const
Return the address family (such as AF_INET6) of the socket.