[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / network / common / socket-impl.h
1 #ifndef DALI_INTERNAL_ADAPTOR_SOCKET_IMPL_H
2 #define DALI_INTERNAL_ADAPTOR_SOCKET_IMPL_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 #include <dali/internal/network/common/socket-interface.h>
22
23 namespace Dali
24 {
25 namespace Internal
26 {
27 namespace Adaptor
28 {
29 /**
30  * @brief Concrete implementation of a socket under Linux.
31  *
32  * Provides automatic closing of socket on destruction.
33  */
34 class Socket : public SocketInterface
35 {
36 public:
37   /**
38    * @brief Constructor
39    * @param protocol network protocol
40    * @param fileDescriptor option file descriptor if the socket is already open
41    */
42   Socket(Protocol protocol, int fileDescriptor = -1);
43
44   /**
45    * @copydoc Dali::Internal::Adaptor::SocketIsOpen()
46    */
47   bool SocketIsOpen() const override;
48
49   /**
50    * @copydoc Dali::Internal::Adaptor::SocketInterface::CloseSocket
51    */
52   bool CloseSocket() override;
53
54   /**
55    * @copydoc Dali::Internal::Adaptor::SocketInterface::Bind
56    */
57   bool Bind(uint16_t port) override;
58
59   /**
60    * @copydoc Dali::Internal::Adaptor::SocketInterface::Listen
61    */
62   bool Listen(int blacklog) override;
63
64   /**
65    * @copydoc Dali::Internal::Adaptor::SocketInterface::Accept
66    */
67   SocketInterface* Accept() const override;
68
69   /**
70    * @copydoc Dali::Internal::Adaptor::SocketInterface::Select
71    */
72   SelectReturn Select() override;
73
74   /**
75    * @copydoc Dali::Internal::Adaptor::SocketInterface::ExitSelect
76    */
77   void ExitSelect() override;
78
79   /**
80    * @copydoc Dali::Internal::Adaptor::SocketInterface::Recieve
81    */
82   bool Read(void* buffer, unsigned int bufferSizeInBytes, unsigned int& bytesRead) override;
83
84   /**
85    * @copydoc Dali::Internal::Adaptor::SocketInterface::Send
86    */
87   bool Write(const void* buffer, unsigned int bufferLength) override;
88
89   /**
90    * @copydoc Dali::Internal::Adaptor::SocketInterface::ReuseAddress
91    */
92   bool ReuseAddress(bool reUse) override;
93
94   /**
95    * @copydoc Dali::Internal::Adaptor::SocketInterface::SetBufferSize
96    *
97    */
98   bool SetBufferSize(SocketInterface::BufferType type, unsigned int bufferSizeInBytes) override;
99
100   /**
101    * @brief Virtual destructor
102    */
103   virtual ~Socket();
104
105 private:
106   /**
107    * @brief Helper to create the quit pipe
108    */
109   bool CreateQuitPipe();
110
111   /**
112    * @brief  Helper to delete the quit pipe
113    */
114   void DeleteQuitPipe();
115
116   int  mSocketFileDescriptor; ///< file descriptor
117   int  mQuitPipe[2];          ///< Pipe to inform Select to quit.
118   bool mBound : 1;            ///< whether the socket is bound
119   bool mListening : 1;        ///< whether the socket is being listen to
120   bool mQuitPipeCreated : 1;  ///< whether the quit pipe has been created
121   bool mBlocked : 1;          ///< whether the socket is blocked waiting for a connection
122 };
123
124 } // namespace Adaptor
125
126 } // namespace Internal
127
128 } // namespace Dali
129
130 #endif // DALI_INTERNAL_ADAPTOR_SOCKET_IMPL_H