[2] | 1 | // %flair:license{
|
---|
[13] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 4 | // %flair:license}
|
---|
| 5 | /*!
|
---|
| 6 | * \file TcpSocket.h
|
---|
| 7 | * \brief Class defining a Tcp socket
|
---|
| 8 | * \author Gildas Bayard, Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 9 | * \date 2015/04/28
|
---|
| 10 | * \version 4.0
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | #ifndef TCPSOCKET_H
|
---|
| 14 | #define TCPSOCKET_H
|
---|
| 15 |
|
---|
| 16 | #include <ConnectedSocket.h>
|
---|
| 17 |
|
---|
[13] | 18 | namespace flair {
|
---|
| 19 | namespace core {
|
---|
| 20 | /*! \class TcpSocket
|
---|
| 21 | *
|
---|
| 22 | * \brief Class encapsulating a TCP socket
|
---|
| 23 | *
|
---|
| 24 | */
|
---|
| 25 | class TcpSocket : public ConnectedSocket {
|
---|
| 26 | public:
|
---|
| 27 | TcpSocket(const Object *parent, const std::string name,
|
---|
| 28 | bool blockOnSend = false, bool blockOnReceive = true);
|
---|
| 29 | ~TcpSocket();
|
---|
| 30 | void Listen(const unsigned int port, const std::string localAddress = "ANY");
|
---|
| 31 | TcpSocket *Accept(
|
---|
| 32 | Time timeout = 0); // should throw an exception if not a listening socket
|
---|
| 33 | bool Connect(const unsigned int distantPort, const std::string distantAddress,
|
---|
| 34 | Time timeout = 0); // timeout in milliseconds
|
---|
| 35 | ssize_t SendMessage(const char *message, size_t message_len,
|
---|
| 36 | Time timeout = 0); // timeout in milliseconds
|
---|
| 37 | ssize_t RecvMessage(char *buf, size_t buf_len,
|
---|
| 38 | Time timeout = 0); // timeout in milliseconds
|
---|
[2] | 39 |
|
---|
[13] | 40 | uint16_t NetworkToHost16(uint16_t data);
|
---|
| 41 | uint16_t HostToNetwork16(uint16_t data);
|
---|
| 42 | uint32_t NetworkToHost32(uint32_t data);
|
---|
| 43 | uint32_t HostToNetwork32(uint32_t data);
|
---|
[2] | 44 |
|
---|
[13] | 45 | private:
|
---|
| 46 | int socket; // socket file descriptor
|
---|
| 47 | bool blockOnSend;
|
---|
| 48 | bool blockOnReceive;
|
---|
| 49 | bool isConnected;
|
---|
| 50 | unsigned int distantPort;
|
---|
| 51 | std::string distantAddress;
|
---|
| 52 | };
|
---|
[2] | 53 |
|
---|
| 54 | } // end namespace core
|
---|
| 55 | } // end namespace flair
|
---|
| 56 |
|
---|
| 57 | #endif // TCPSOCKET_H
|
---|