]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/gsockmsw.h
* Made GSocket::GetError() exp/imp from net library and provide an inline
[wxWidgets.git] / include / wx / msw / gsockmsw.h
CommitLineData
904ec517
GRG
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockmsw.h
4 * Purpose: GSocket MSW header
5 * CVSID: $Id$
6 * -------------------------------------------------------------------------
7 */
8
9#ifndef __GSOCK_MSW_H
10#define __GSOCK_MSW_H
11
0ce742cf
GRG
12#ifndef __GSOCKET_STANDALONE__
13#include "wx/setup.h"
14#endif
15
16#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
17
c21b68f7 18#ifndef __GSOCKET_STANDALONE__
904ec517
GRG
19#include "wx/gsocket.h"
20#else
21#include "gsocket.h"
22#endif
23
4b4d23c7
DE
24#ifdef wxUSE_GSOCKET_CPLUSPLUS
25#include "wx/msw/wrapwin.h"
26#else
c09f2879 27#include <windows.h>
904ec517 28#include <winsock.h>
c21b68f7
GRG
29#endif
30
5c9eff30
GRG
31#ifndef TRUE
32#define TRUE 1
33#endif
34
35#ifndef FALSE
36#define FALSE 0
37#endif
38
4b4d23c7
DE
39#ifdef wxUSE_GSOCKET_CPLUSPLUS
40class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable
41{
42public:
43 virtual bool OnInit();
44 virtual void OnExit();
45 virtual bool CanUseEventLoop();
46 virtual bool Init_Socket(GSocket *socket);
47 virtual void Destroy_Socket(GSocket *socket);
48 virtual void Enable_Events(GSocket *socket);
49 virtual void Disable_Events(GSocket *socket);
50};
51#endif /* def wxUSE_GSOCKET_CPLUSPLUS */
52
53#if defined(__cplusplus) && !defined wxUSE_GSOCKET_CPLUSPLUS
54extern "C" {
55#endif
56
904ec517 57/* Definition of GSocket */
4b4d23c7
DE
58#ifdef wxUSE_GSOCKET_CPLUSPLUS
59class GSocket
60#else
904ec517 61struct _GSocket
4b4d23c7 62#endif
904ec517 63{
4b4d23c7
DE
64#ifdef wxUSE_GSOCKET_CPLUSPLUS
65public:
66 GSocket();
67 ~GSocket();
68 bool IsOk() { return m_ok; }
69 void Close();
70 void Shutdown();
71 GSocketError SetLocal(GAddress *address);
72 GSocketError SetPeer(GAddress *address);
73 GAddress *GetLocal();
74 GAddress *GetPeer();
75 GSocketError SetServer();
76 GSocket *WaitConnection();
77 int SetReusable();
78 GSocketError Connect(GSocketStream stream);
79 GSocketError SetNonOriented();
80 int Read(char *buffer, int size);
81 int Write(const char *buffer, int size);
82 GSocketEventFlags Select(GSocketEventFlags flags);
83 void SetNonBlocking(bool non_block);
84 void SetTimeout(unsigned long millis);
a4506848 85 GSocketError WXDLLIMPEXP_NET GetError();
4b4d23c7
DE
86 void SetCallback(GSocketEventFlags flags,
87 GSocketCallback callback, char *cdata);
88 void UnsetCallback(GSocketEventFlags flags);
89 GSocketError GetSockOpt(int level, int optname,
90 void *optval, int *optlen);
91 GSocketError SetSockOpt(int level, int optname,
92 const void *optval, int optlen);
93protected:
94 GSocketError Input_Timeout();
95 GSocketError Output_Timeout();
96 GSocketError Connect_Timeout();
97 int Recv_Stream(char *buffer, int size);
98 int Recv_Dgram(char *buffer, int size);
99 int Send_Stream(const char *buffer, int size);
100 int Send_Dgram(const char *buffer, int size);
101 bool m_ok;
102
103/* TODO: Make these protected */
104public:
105#endif /* def wxUSE_GSOCKET_CPLUSPLUS */
904ec517
GRG
106 SOCKET m_fd;
107 GAddress *m_local;
108 GAddress *m_peer;
109 GSocketError m_error;
110
483249fc 111 /* Attributes */
27a97d02
GRG
112 int m_non_blocking;
113 int m_server;
114 int m_stream;
27a97d02 115 int m_establishing;
74c481d1 116 int m_reusable;
904ec517
GRG
117 struct timeval m_timeout;
118
119 /* Callbacks */
483249fc 120 GSocketEventFlags m_detected;
904ec517
GRG
121 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
122 char *m_data[GSOCK_MAX_EVENT];
123 int m_msgnumber;
124};
125
4b4d23c7
DE
126#ifdef wxUSE_GSOCKET_CPLUSPLUS
127/* TODO: Fix src/common/socket.cpp to use the new API */
128inline void GSocket_Shutdown(GSocket *socket)
129{ socket->Shutdown(); }
130inline GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address)
131{ return socket->SetLocal(address); }
132inline GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address)
133{ return socket->SetPeer(address); }
134inline GAddress *GSocket_GetLocal(GSocket *socket)
135{ return socket->GetLocal(); }
136inline GAddress *GSocket_GetPeer(GSocket *socket)
137{ return socket->GetPeer(); }
138inline GSocketError GSocket_SetServer(GSocket *socket)
139{ return socket->SetServer(); }
140inline GSocket *GSocket_WaitConnection(GSocket *socket)
141{ return socket->WaitConnection(); }
142inline int GSocket_SetReusable(GSocket *socket)
143{ return socket->SetReusable(); }
144inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream)
145{ return socket->Connect(stream); }
146inline GSocketError GSocket_SetNonOriented(GSocket *socket)
147{ return socket->SetNonOriented(); }
148inline int GSocket_Read(GSocket *socket, char *buffer, int size)
149{ return socket->Read(buffer,size); }
150inline int GSocket_Write(GSocket *socket, const char *buffer, int size)
151{ return socket->Write(buffer,size); }
152inline GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
153{ return socket->Select(flags); }
154inline void GSocket_SetNonBlocking(GSocket *socket, int non_block)
155{ socket->SetNonBlocking(non_block); }
156inline void GSocket_SetTimeout(GSocket *socket, unsigned long millisec)
157{ socket->SetTimeout(millisec); }
a4506848
DE
158inline GSocketError GSocket_GetError(GSocket *socket)
159{ return socket->GetError(); }
4b4d23c7
DE
160inline void GSocket_SetCallback(GSocket *socket, GSocketEventFlags flags,
161 GSocketCallback fallback, char *cdata)
162{ socket->SetCallback(flags,fallback,cdata); }
163inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags)
164{ socket->UnsetCallback(flags); }
165inline GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname,
166 void *optval, int *optlen)
167{ return socket->GetSockOpt(level,optname,optval,optlen); }
168inline GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname,
169 const void *optval, int optlen)
170{ return socket->SetSockOpt(level,optname,optval,optlen); }
171inline void GSocket_destroy(GSocket *socket)
172{ delete socket; }
173#endif /* def wxUSE_GSOCKET_CPLUSPLUS */
174
175#if defined(__cplusplus) && !defined wxUSE_GSOCKET_CPLUSPLUS
176}
177#endif
178
179#ifdef __cplusplus
180extern "C" {
181#endif
182
904ec517
GRG
183/* Definition of GAddress */
184struct _GAddress
185{
186 struct sockaddr *m_addr;
187 size_t m_len;
188
189 GAddressType m_family;
190 int m_realfamily;
191
192 GSocketError m_error;
193};
194
4b4d23c7 195#ifndef wxUSE_GSOCKET_CPLUSPLUS
904ec517
GRG
196/* Input / output */
197
198GSocketError _GSocket_Input_Timeout(GSocket *socket);
199GSocketError _GSocket_Output_Timeout(GSocket *socket);
d3ea6527 200GSocketError _GSocket_Connect_Timeout(GSocket *socket);
904ec517
GRG
201int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size);
202int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size);
203int _GSocket_Send_Stream(GSocket *socket, const char *buffer, int size);
204int _GSocket_Send_Dgram(GSocket *socket, const char *buffer, int size);
205
206/* Callbacks */
207
38bb138f
VS
208int _GSocket_GUI_Init(void);
209void _GSocket_GUI_Cleanup(void);
210int _GSocket_GUI_Init_Socket(GSocket *socket);
211void _GSocket_GUI_Destroy_Socket(GSocket *socket);
70988afb
GRG
212
213LRESULT CALLBACK _GSocket_Internal_WinProc(HWND, UINT, WPARAM, LPARAM);
214
483249fc
GRG
215void _GSocket_Enable_Events(GSocket *socket);
216void _GSocket_Disable_Events(GSocket *socket);
4b4d23c7 217#endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
904ec517
GRG
218
219/* GAddress */
220
221GSocketError _GAddress_translate_from(GAddress *address,
222 struct sockaddr *addr, int len);
d3ea6527
GRG
223GSocketError _GAddress_translate_to (GAddress *address,
224 struct sockaddr **addr, int *len);
904ec517
GRG
225GSocketError _GAddress_Init_INET(GAddress *address);
226GSocketError _GAddress_Init_UNIX(GAddress *address);
227
228#ifdef __cplusplus
229}
230#endif
231
0ce742cf
GRG
232#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
233
904ec517 234#endif /* __GSOCK_MSW_H */