32 #ifndef _NPT_SOCKETS_H_ 33 #define _NPT_SOCKETS_H_ 39 #include "NptConstants.h" 40 #include "NptStreams.h" 41 #include "NptStrings.h" 42 #include "NptDataBuffer.h" 43 #include "NptNetwork.h" 44 #include "NptThreads.h" 49 const int NPT_ERROR_CONNECTION_RESET = NPT_ERROR_BASE_SOCKET - 0;
50 const int NPT_ERROR_CONNECTION_ABORTED = NPT_ERROR_BASE_SOCKET - 1;
51 const int NPT_ERROR_CONNECTION_REFUSED = NPT_ERROR_BASE_SOCKET - 2;
52 const int NPT_ERROR_CONNECTION_FAILED = NPT_ERROR_BASE_SOCKET - 3;
53 const int NPT_ERROR_HOST_UNKNOWN = NPT_ERROR_BASE_SOCKET - 4;
54 const int NPT_ERROR_SOCKET_FAILED = NPT_ERROR_BASE_SOCKET - 5;
55 const int NPT_ERROR_GETSOCKOPT_FAILED = NPT_ERROR_BASE_SOCKET - 6;
56 const int NPT_ERROR_SETSOCKOPT_FAILED = NPT_ERROR_BASE_SOCKET - 7;
57 const int NPT_ERROR_SOCKET_CONTROL_FAILED = NPT_ERROR_BASE_SOCKET - 8;
58 const int NPT_ERROR_BIND_FAILED = NPT_ERROR_BASE_SOCKET - 9;
59 const int NPT_ERROR_LISTEN_FAILED = NPT_ERROR_BASE_SOCKET - 10;
60 const int NPT_ERROR_ACCEPT_FAILED = NPT_ERROR_BASE_SOCKET - 11;
61 const int NPT_ERROR_ADDRESS_IN_USE = NPT_ERROR_BASE_SOCKET - 12;
62 const int NPT_ERROR_NETWORK_DOWN = NPT_ERROR_BASE_SOCKET - 13;
63 const int NPT_ERROR_NETWORK_UNREACHABLE = NPT_ERROR_BASE_SOCKET - 14;
64 const int NPT_ERROR_HOST_UNREACHABLE = NPT_ERROR_BASE_SOCKET - 15;
65 const int NPT_ERROR_NOT_CONNECTED = NPT_ERROR_BASE_SOCKET - 16;
67 const unsigned int NPT_SOCKET_FLAG_CANCELLABLE = 1;
88 m_IpAddress = address;
94 NPT_Result SetPort(NPT_IpPort port) {
98 NPT_IpPort GetPort()
const {
129 virtual NPT_Result Bind(
const NPT_SocketAddress& address,
bool reuse_address =
true) = 0;
130 virtual NPT_Result Connect(
const NPT_SocketAddress& address, NPT_Timeout timeout) = 0;
131 virtual NPT_Result WaitForConnection(NPT_Timeout timeout) = 0;
135 virtual NPT_Result SetReadTimeout(NPT_Timeout timeout) = 0;
136 virtual NPT_Result SetWriteTimeout(NPT_Timeout timeout) = 0;
137 virtual NPT_Result Cancel(
bool shutdown=
true) = 0;
168 virtual NPT_Result SetTimeToLive(
unsigned char ttl) = 0;
169 virtual NPT_Result SetInterface(
const NPT_IpAddress& iface) = 0;
181 virtual NPT_Result Listen(
unsigned int max_clients) = 0;
182 virtual NPT_Result WaitForNewClient(
NPT_Socket*& client,
184 NPT_Flags flags) = 0;
194 static NPT_Result CancelBlockerSocket(NPT_Thread::ThreadId thread_id);
201 NPT_Result Bind(
const NPT_SocketAddress& address,
bool reuse_address =
true)
override {
202 return m_SocketDelegate->Bind(address, reuse_address);
205 NPT_Timeout timeout = NPT_TIMEOUT_INFINITE)
override {
206 return m_SocketDelegate->Connect(address, timeout);
208 NPT_Result WaitForConnection(NPT_Timeout timeout = NPT_TIMEOUT_INFINITE)
override {
209 return m_SocketDelegate->WaitForConnection(timeout);
212 return m_SocketDelegate->GetInputStream(stream);
215 return m_SocketDelegate->GetOutputStream(stream);
218 return m_SocketDelegate->GetInfo(info);
220 NPT_Result SetReadTimeout(NPT_Timeout timeout)
override {
221 return m_SocketDelegate->SetReadTimeout(timeout);
223 NPT_Result SetWriteTimeout(NPT_Timeout timeout)
override {
224 return m_SocketDelegate->SetWriteTimeout(timeout);
226 NPT_Result Cancel(
bool shutdown=
true)
override {
227 return m_SocketDelegate->Cancel(shutdown);
254 return m_UdpSocketDelegate->Send(packet, address);
258 return m_UdpSocketDelegate->Receive(packet, address);
283 NPT_IpAddress::Any)
override {
284 return m_UdpMulticastSocketDelegate->JoinGroup(group, iface);
288 NPT_IpAddress::Any)
override {
289 return m_UdpMulticastSocketDelegate->LeaveGroup(group, iface);
291 NPT_Result SetTimeToLive(
unsigned char ttl)
override {
292 return m_UdpMulticastSocketDelegate->SetTimeToLive(ttl);
294 NPT_Result SetInterface(
const NPT_IpAddress& iface)
override {
295 return m_UdpMulticastSocketDelegate->SetInterface(iface);
326 NPT_Result Listen(
unsigned int max_clients)
override {
327 return m_TcpServerSocketDelegate->Listen(max_clients);
329 NPT_Result WaitForNewClient(
NPT_Socket*& client,
330 NPT_Timeout timeout = NPT_TIMEOUT_INFINITE,
331 NPT_Flags flags = 0)
override {
332 return m_TcpServerSocketDelegate->WaitForNewClient(client, timeout, flags);
340 #endif // _NPT_SOCKETS_H_ Definition: NptSockets.h:190
Definition: NptSockets.h:317
Definition: NptNetwork.h:74
Definition: NptSockets.h:272
Definition: NptSockets.h:77
Definition: NptSockets.h:143
Definition: NptSockets.h:158
Definition: NptSockets.h:123
Definition: NptSockets.h:115
Definition: NptSockets.h:175
Definition: SmartPlayList.cpp:137
Definition: NptDataBuffer.h:44
Definition: NptSockets.h:306
Definition: NptSockets.h:243
Definition: NptStrings.h:57