3 /*-------------------------------------------------------------------------
4 * drawElements C++ Base Library
5 * -----------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief deSocket C++ wrapper.
24 *//*--------------------------------------------------------------------*/
35 class SocketError : public std::runtime_error
38 SocketError (const std::string& message) : std::runtime_error(message) {}
45 ~SocketAddress (void);
47 void setHost (const char* host);
48 void setPort (int port);
49 void setFamily (deSocketFamily family);
50 void setType (deSocketType type);
51 void setProtocol (deSocketProtocol protocol);
53 const char* getHost (void) const { return deSocketAddress_getHost(m_address); }
54 int getPort (void) const { return deSocketAddress_getPort(m_address); }
55 deSocketFamily getFamily (void) const { return deSocketAddress_getFamily(m_address); }
56 deSocketType getType (void) const { return deSocketAddress_getType(m_address); }
57 deSocketProtocol getProtocol (void) const { return deSocketAddress_getProtocol(m_address); }
59 operator deSocketAddress* () { return m_address; }
60 operator const deSocketAddress* () const { return m_address; }
62 deSocketAddress* getPtr (void) { return m_address; }
66 SocketAddress (const SocketAddress& other);
67 SocketAddress& operator= (const SocketAddress& other);
69 deSocketAddress* m_address;
78 void setFlags (deUint32 flags);
80 deSocketState getState (void) const { return deSocket_getState(m_socket); }
81 bool isConnected (void) const { return getState() == DE_SOCKETSTATE_CONNECTED; }
83 void listen (const SocketAddress& address);
84 Socket* accept (SocketAddress& clientAddress) { return accept(clientAddress.getPtr()); }
85 Socket* accept (void) { return accept(DE_NULL); }
87 void connect (const SocketAddress& address);
90 void shutdownSend (void);
91 void shutdownReceive (void);
93 bool isSendOpen (void) { return (deSocket_getOpenChannels(m_socket) & DE_SOCKETCHANNEL_SEND ) != 0; }
94 bool isReceiveOpen (void) { return (deSocket_getOpenChannels(m_socket) & DE_SOCKETCHANNEL_RECEIVE ) != 0; }
98 deSocketResult send (const void* buf, size_t bufSize, size_t* numSent) { return deSocket_send(m_socket, buf, bufSize, numSent); }
99 deSocketResult receive (void* buf, size_t bufSize, size_t* numRecv) { return deSocket_receive(m_socket, buf, bufSize, numRecv); }
102 Socket (deSocket* socket) : m_socket(socket) {}
103 Socket (const Socket& other);
104 Socket& operator= (const Socket& other);
106 Socket* accept (deSocketAddress* clientAddress);
113 #endif // _DESOCKET_HPP