1 #ifndef DALI_INTERNAL_ADAPTOR_SOCKET_IMPL_H
2 #define DALI_INTERNAL_ADAPTOR_SOCKET_IMPL_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/internal/network/common/socket-interface.h>
30 * @brief Concrete implementation of a socket under Linux.
32 * Provides automatic closing of socket on destruction.
34 class Socket : public SocketInterface
39 * @param protocol network protocol
40 * @param fileDescriptor option file descriptor if the socket is already open
42 Socket(Protocol protocol, int fileDescriptor = -1);
45 * @copydoc Dali::Internal::Adaptor::SocketIsOpen()
47 bool SocketIsOpen() const override;
50 * @copydoc Dali::Internal::Adaptor::SocketInterface::CloseSocket
52 bool CloseSocket() override;
55 * @copydoc Dali::Internal::Adaptor::SocketInterface::Bind
57 bool Bind(uint16_t port) override;
60 * @copydoc Dali::Internal::Adaptor::SocketInterface::Listen
62 bool Listen(int blacklog) override;
65 * @copydoc Dali::Internal::Adaptor::SocketInterface::Accept
67 SocketInterface* Accept() const override;
70 * @copydoc Dali::Internal::Adaptor::SocketInterface::Select
72 SelectReturn Select() override;
75 * @copydoc Dali::Internal::Adaptor::SocketInterface::ExitSelect
77 void ExitSelect() override;
80 * @copydoc Dali::Internal::Adaptor::SocketInterface::Recieve
82 bool Read(void* buffer, unsigned int bufferSizeInBytes, unsigned int& bytesRead) override;
85 * @copydoc Dali::Internal::Adaptor::SocketInterface::Send
87 bool Write(const void* buffer, unsigned int bufferLength) override;
90 * @copydoc Dali::Internal::Adaptor::SocketInterface::ReuseAddress
92 bool ReuseAddress(bool reUse) override;
95 * @copydoc Dali::Internal::Adaptor::SocketInterface::SetBufferSize
98 bool SetBufferSize(SocketInterface::BufferType type, unsigned int bufferSizeInBytes) override;
101 * @brief Virtual destructor
107 * @brief Helper to create the quit pipe
109 bool CreateQuitPipe();
112 * @brief Helper to delete the quit pipe
114 void DeleteQuitPipe();
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
124 } // namespace Adaptor
126 } // namespace Internal
130 #endif // DALI_INTERNAL_ADAPTOR_SOCKET_IMPL_H