]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/gsockmsw.h
0fb678a3f06adcc4e4cb6e8b82c2201b6d76ef09
[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 #ifdef __WXWINCE__
27 #include <winsock.h>
28 #endif
29
30 class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable
31 {
32 public:
33 virtual bool OnInit();
34 virtual void OnExit();
35 virtual bool CanUseEventLoop();
36 virtual bool Init_Socket(GSocket *socket);
37 virtual void Destroy_Socket(GSocket *socket);
38 virtual void Enable_Events(GSocket *socket);
39 virtual void Disable_Events(GSocket *socket);
40 };
41
42 /* Definition of GSocket */
43 class GSocket
44 {
45 public:
46 GSocket();
47 ~GSocket();
48 bool IsOk() { return m_ok; }
49 void Close();
50 void Shutdown();
51 GSocketError SetLocal(GAddress *address);
52 GSocketError SetPeer(GAddress *address);
53 GAddress *GetLocal();
54 GAddress *GetPeer();
55 GSocketError SetServer();
56 GSocket *WaitConnection();
57 bool SetReusable();
58 GSocketError Connect(GSocketStream stream);
59 GSocketError SetNonOriented();
60 int Read(char *buffer, int size);
61 int Write(const char *buffer, int size);
62 GSocketEventFlags Select(GSocketEventFlags flags);
63 void SetNonBlocking(bool non_block);
64 void SetTimeout(unsigned long millis);
65 GSocketError WXDLLIMPEXP_NET GetError();
66 void SetCallback(GSocketEventFlags flags,
67 GSocketCallback callback, char *cdata);
68 void UnsetCallback(GSocketEventFlags flags);
69 GSocketError GetSockOpt(int level, int optname,
70 void *optval, int *optlen);
71 GSocketError SetSockOpt(int level, int optname,
72 const void *optval, int optlen);
73 protected:
74 GSocketError Input_Timeout();
75 GSocketError Output_Timeout();
76 GSocketError Connect_Timeout();
77 int Recv_Stream(char *buffer, int size);
78 int Recv_Dgram(char *buffer, int size);
79 int Send_Stream(const char *buffer, int size);
80 int Send_Dgram(const char *buffer, int size);
81 bool m_ok;
82
83 /* TODO: Make these protected */
84 public:
85 SOCKET m_fd;
86 GAddress *m_local;
87 GAddress *m_peer;
88 GSocketError m_error;
89
90 /* Attributes */
91 bool m_non_blocking;
92 bool m_server;
93 bool m_stream;
94 bool m_establishing;
95 bool m_reusable;
96 struct timeval m_timeout;
97
98 /* Callbacks */
99 GSocketEventFlags m_detected;
100 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
101 char *m_data[GSOCK_MAX_EVENT];
102 int m_msgnumber;
103 };
104
105 #ifdef __cplusplus
106 extern "C" {
107 #endif
108
109 /* Definition of GAddress */
110 struct _GAddress
111 {
112 struct sockaddr *m_addr;
113 size_t m_len;
114
115 GAddressType m_family;
116 int m_realfamily;
117
118 GSocketError m_error;
119 };
120
121
122 /* GAddress */
123
124 GSocketError _GAddress_translate_from(GAddress *address,
125 struct sockaddr *addr, int len);
126 GSocketError _GAddress_translate_to (GAddress *address,
127 struct sockaddr **addr, int *len);
128 GSocketError _GAddress_Init_INET(GAddress *address);
129 GSocketError _GAddress_Init_UNIX(GAddress *address);
130
131 #ifdef __cplusplus
132 }
133 #endif
134
135 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
136
137 #endif /* __GSOCK_MSW_H */