1 #ifndef __DALI_INTERNAL_ADAPTOR_SOCKET_IMPL_H__
2 #define __DALI_INTERNAL_ADAPTOR_SOCKET_IMPL_H__
5 * Copyright (c) 2015 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 <base/interfaces/socket-interface.h>
33 * @brief Concrete implementation of a socket under Linux.
35 * Provides automatic closing of socket on destruction.
37 class Socket : public SocketInterface
43 * @param protocol network protocol
44 * @param fileDescriptor option file descriptor if the socket is already open
46 Socket( Protocol protocol , int fileDescriptor = -1 );
49 * @copydoc Dali::Internal::Adaptor::SocketIsOpen()
51 virtual bool SocketIsOpen() const;
54 * @copydoc Dali::Internal::Adaptor::SocketInterface::CloseSocket
56 virtual bool CloseSocket();
59 * @copydoc Dali::Internal::Adaptor::SocketInterface::Bind
61 virtual bool Bind( uint16_t port ) ;
64 * @copydoc Dali::Internal::Adaptor::SocketInterface::Listen
66 virtual bool Listen( int blacklog);
69 * @copydoc Dali::Internal::Adaptor::SocketInterface::Accept
71 virtual SocketInterface* Accept() const ;
74 * @copydoc Dali::Internal::Adaptor::SocketInterface::Select
76 virtual SelectReturn Select( );
79 * @copydoc Dali::Internal::Adaptor::SocketInterface::ExitSelect
81 virtual void ExitSelect();
84 * @copydoc Dali::Internal::Adaptor::SocketInterface::Recieve
86 virtual bool Read( void* buffer, unsigned int bufferSizeInBytes, unsigned int& bytesRead );
89 * @copydoc Dali::Internal::Adaptor::SocketInterface::Send
91 virtual bool Write( const void* buffer, unsigned int bufferLength );
94 * @copydoc Dali::Internal::Adaptor::SocketInterface::ReuseAddress
96 virtual bool ReuseAddress( bool reUse );
99 * @copydoc Dali::Internal::Adaptor::SocketInterface::SetBufferSize
102 virtual bool SetBufferSize( SocketInterface::BufferType type, unsigned int bufferSizeInBytes );
105 * @brief Virtual destructor
113 * @brief Helper to create the quit pipe
115 bool CreateQuitPipe();
118 * @brief Helper to delete the quit pipe
120 void DeleteQuitPipe();
122 int mSocketFileDescriptor; ///< file descriptor
123 int mQuitPipe[2]; ///< Pipe to inform Select to quit.
124 bool mBound:1; ///< whether the socket is bound
125 bool mListening:1; ///< whether the socket is being listen to
126 bool mQuitPipeCreated:1; ///< whether the quit pipe has been created
127 bool mBlocked:1; ///< whether the socket is blocked waiting for a connection
138 #endif // __DALI_INTERNAL_ADAPTOR_SOCKET_IMPL_H__