]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/gsockmsw.h
84a6598e4df324357756476807392ef0da7321ea
[wxWidgets.git] / include / wx / msw / gsockmsw.h
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
12 #ifndef __GSOCKET_STANDALONE__
13 #include "wx/setup.h"
14 #endif
15
16 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
17
18 #ifndef __GSOCKET_STANDALONE__
19 #include "wx/gsocket.h"
20 #else
21 #include "gsocket.h"
22 #endif
23
24 #include "wx/msw/wrapwin.h"
25
26 #ifndef TRUE
27 #define TRUE 1
28 #endif
29
30 #ifndef FALSE
31 #define FALSE 0
32 #endif
33
34 class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable
35 {
36 public:
37 virtual bool OnInit();
38 virtual void OnExit();
39 virtual bool CanUseEventLoop();
40 virtual bool Init_Socket(GSocket *socket);
41 virtual void Destroy_Socket(GSocket *socket);
42 virtual void Enable_Events(GSocket *socket);
43 virtual void Disable_Events(GSocket *socket);
44 };
45
46 /* Definition of GSocket */
47 class GSocket
48 {
49 public:
50 GSocket();
51 ~GSocket();
52 bool IsOk() { return m_ok; }
53 void Close();
54 void Shutdown();
55 GSocketError SetLocal(GAddress *address);
56 GSocketError SetPeer(GAddress *address);
57 GAddress *GetLocal();
58 GAddress *GetPeer();
59 GSocketError SetServer();
60 GSocket *WaitConnection();
61 int SetReusable();
62 GSocketError Connect(GSocketStream stream);
63 GSocketError SetNonOriented();
64 int Read(char *buffer, int size);
65 int Write(const char *buffer, int size);
66 GSocketEventFlags Select(GSocketEventFlags flags);
67 void SetNonBlocking(bool non_block);
68 void SetTimeout(unsigned long millis);
69 GSocketError WXDLLIMPEXP_NET GetError();
70 void SetCallback(GSocketEventFlags flags,
71 GSocketCallback callback, char *cdata);
72 void UnsetCallback(GSocketEventFlags flags);
73 GSocketError GetSockOpt(int level, int optname,
74 void *optval, int *optlen);
75 GSocketError SetSockOpt(int level, int optname,
76 const void *optval, int optlen);
77 protected:
78 GSocketError Input_Timeout();
79 GSocketError Output_Timeout();
80 GSocketError Connect_Timeout();
81 int Recv_Stream(char *buffer, int size);
82 int Recv_Dgram(char *buffer, int size);
83 int Send_Stream(const char *buffer, int size);
84 int Send_Dgram(const char *buffer, int size);
85 bool m_ok;
86
87 /* TODO: Make these protected */
88 public:
89 SOCKET m_fd;
90 GAddress *m_local;
91 GAddress *m_peer;
92 GSocketError m_error;
93
94 /* Attributes */
95 int m_non_blocking;
96 int m_server;
97 int m_stream;
98 int m_establishing;
99 int m_reusable;
100 struct timeval m_timeout;
101
102 /* Callbacks */
103 GSocketEventFlags m_detected;
104 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
105 char *m_data[GSOCK_MAX_EVENT];
106 int m_msgnumber;
107 };
108
109 /* TODO: Fix src/common/socket.cpp to use the new API */
110 inline void GSocket_Shutdown(GSocket *socket)
111 { socket->Shutdown(); }
112 inline GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address)
113 { return socket->SetLocal(address); }
114 inline GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address)
115 { return socket->SetPeer(address); }
116 inline GAddress *GSocket_GetLocal(GSocket *socket)
117 { return socket->GetLocal(); }
118 inline GAddress *GSocket_GetPeer(GSocket *socket)
119 { return socket->GetPeer(); }
120 inline GSocketError GSocket_SetServer(GSocket *socket)
121 { return socket->SetServer(); }
122 inline GSocket *GSocket_WaitConnection(GSocket *socket)
123 { return socket->WaitConnection(); }
124 inline int GSocket_SetReusable(GSocket *socket)
125 { return socket->SetReusable(); }
126 inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream)
127 { return socket->Connect(stream); }
128 inline GSocketError GSocket_SetNonOriented(GSocket *socket)
129 { return socket->SetNonOriented(); }
130 inline int GSocket_Read(GSocket *socket, char *buffer, int size)
131 { return socket->Read(buffer,size); }
132 inline int GSocket_Write(GSocket *socket, const char *buffer, int size)
133 { return socket->Write(buffer,size); }
134 inline GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
135 { return socket->Select(flags); }
136 inline void GSocket_SetNonBlocking(GSocket *socket, int non_block)
137 { socket->SetNonBlocking(non_block != 0); }
138 inline void GSocket_SetTimeout(GSocket *socket, unsigned long millisec)
139 { socket->SetTimeout(millisec); }
140 inline GSocketError GSocket_GetError(GSocket *socket)
141 { return socket->GetError(); }
142 inline void GSocket_SetCallback(GSocket *socket, GSocketEventFlags flags,
143 GSocketCallback fallback, char *cdata)
144 { socket->SetCallback(flags,fallback,cdata); }
145 inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags)
146 { socket->UnsetCallback(flags); }
147 inline GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname,
148 void *optval, int *optlen)
149 { return socket->GetSockOpt(level,optname,optval,optlen); }
150 inline GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname,
151 const void *optval, int optlen)
152 { return socket->SetSockOpt(level,optname,optval,optlen); }
153 inline void GSocket_destroy(GSocket *socket)
154 { delete socket; }
155
156 #ifdef __cplusplus
157 extern "C" {
158 #endif
159
160 /* Definition of GAddress */
161 struct _GAddress
162 {
163 struct sockaddr *m_addr;
164 size_t m_len;
165
166 GAddressType m_family;
167 int m_realfamily;
168
169 GSocketError m_error;
170 };
171
172
173 /* GAddress */
174
175 GSocketError _GAddress_translate_from(GAddress *address,
176 struct sockaddr *addr, int len);
177 GSocketError _GAddress_translate_to (GAddress *address,
178 struct sockaddr **addr, int *len);
179 GSocketError _GAddress_Init_INET(GAddress *address);
180 GSocketError _GAddress_Init_UNIX(GAddress *address);
181
182 #ifdef __cplusplus
183 }
184 #endif
185
186 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
187
188 #endif /* __GSOCK_MSW_H */