Kea 2.5.4
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
13
14#include <string>
15
16#include <sys/socket.h>
17
18namespace isc {
19namespace util {
20namespace io {
21
144
152public:
153 SocketSessionError(const char *file, size_t line, const char *what):
154 isc::Exception(file, line, what) {}
155};
156
173protected:
175
176public:
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
194class SocketSessionForwarder : boost::noncopyable,
196{
197public:
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
313private:
314 struct ForwarderImpl;
315 ForwarderImpl* impl_;
316};
317
334public:
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
392private:
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
422class SocketSessionReceiver : boost::noncopyable {
423public:
432 explicit SocketSessionReceiver(int fd);
433
441
481
482private:
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:
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The "base" class of SocketSessionForwarder.
virtual void push(int sock, int family, int type, int protocol, const struct sockaddr &local_end, const struct sockaddr &remote_end, const void *data, size_t data_len)=0
An exception indicating general errors that takes place in the socket session related class objects.
SocketSessionError(const char *file, size_t line, const char *what)
The forwarder of socket sessions.
virtual ~SocketSessionForwarder()
The destructor.
virtual void close()
Close the connection to the receiver.
virtual void connectToReceiver()
Establish a connection to the receiver.
SocketSessionForwarder(const std::string &unix_file)
The constructor.
virtual void push(int sock, int family, int type, int protocol, const struct sockaddr &local_end, const struct sockaddr &remote_end, const void *data, size_t data_len)
Forward a socket session to the receiver.
The receiver of socket sessions.
SocketSession pop()
Receive a socket session from the forwarder.
SocketSessionReceiver(int fd)
The constructor.
Socket session object.
const void * getData() const
Return a pointer to the beginning of the memory region for the session data.
size_t getDataLength() const
Return the size of the session data in bytes.
int getProtocol() const
Return the transport protocol (such as IPPROTO_UDP) of the socket.
const sockaddr & getRemoteEndpoint() const
Return the remote end point of the session in the form of sockaddr.
int getType() const
Return the socket type (such as SOCK_DGRAM) of the socket.
int getSocket() const
Return the socket file descriptor.
const sockaddr & getLocalEndpoint() const
Return the local end point of the session in the form of sockaddr.
SocketSession(int sock, int family, int type, int protocol, const sockaddr *local_end, const sockaddr *remote_end, const void *data, size_t data_len)
The constructor.
int getFamily() const
Return the address family (such as AF_INET6) of the socket.
Defines the logger used by the top-level component of kea-lfc.