]>
Commit | Line | Data |
---|---|---|
904ec517 | 1 | /* ------------------------------------------------------------------------- |
99d80019 JS |
2 | * Project: GSocket (Generic Socket) for WX |
3 | * Name: gsockmsw.h | |
4 | * Copyright: (c) Guilhem Lavaux | |
5 | * Licence: wxWindows Licence | |
6 | * Purpose: GSocket MSW header | |
7 | * CVSID: $Id$ | |
904ec517 GRG |
8 | * ------------------------------------------------------------------------- |
9 | */ | |
10 | ||
11 | #ifndef __GSOCK_MSW_H | |
12 | #define __GSOCK_MSW_H | |
13 | ||
0ce742cf GRG |
14 | #ifndef __GSOCKET_STANDALONE__ |
15 | #include "wx/setup.h" | |
16 | #endif | |
17 | ||
18 | #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) | |
19 | ||
c21b68f7 | 20 | #ifndef __GSOCKET_STANDALONE__ |
904ec517 GRG |
21 | #include "wx/gsocket.h" |
22 | #else | |
23 | #include "gsocket.h" | |
24 | #endif | |
25 | ||
4b4d23c7 | 26 | #include "wx/msw/wrapwin.h" |
c21b68f7 | 27 | |
9e07d399 RN |
28 | #if defined(__CYGWIN__) |
29 | //CYGWIN gives annoying warning about runtime stuff if we don't do this | |
30 | # define USE_SYS_TYPES_FD_SET | |
31 | # include <sys/types.h> | |
32 | #endif | |
33 | ||
34 | #if defined(__WXWINCE__) || defined(__CYGWIN__) | |
dbfb61b3 JS |
35 | #include <winsock.h> |
36 | #endif | |
37 | ||
4b4d23c7 DE |
38 | class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable |
39 | { | |
40 | public: | |
41 | virtual bool OnInit(); | |
42 | virtual void OnExit(); | |
43 | virtual bool CanUseEventLoop(); | |
44 | virtual bool Init_Socket(GSocket *socket); | |
45 | virtual void Destroy_Socket(GSocket *socket); | |
46 | virtual void Enable_Events(GSocket *socket); | |
47 | virtual void Disable_Events(GSocket *socket); | |
48 | }; | |
4b4d23c7 | 49 | |
904ec517 | 50 | /* Definition of GSocket */ |
4b4d23c7 | 51 | class GSocket |
904ec517 | 52 | { |
4b4d23c7 DE |
53 | public: |
54 | GSocket(); | |
55 | ~GSocket(); | |
56 | bool IsOk() { return m_ok; } | |
57 | void Close(); | |
58 | void Shutdown(); | |
59 | GSocketError SetLocal(GAddress *address); | |
60 | GSocketError SetPeer(GAddress *address); | |
61 | GAddress *GetLocal(); | |
62 | GAddress *GetPeer(); | |
63 | GSocketError SetServer(); | |
64 | GSocket *WaitConnection(); | |
948c96ef | 65 | bool SetReusable(); |
60edcf45 VZ |
66 | bool SetBroadcast(); |
67 | bool DontDoBind(); | |
4b4d23c7 DE |
68 | GSocketError Connect(GSocketStream stream); |
69 | GSocketError SetNonOriented(); | |
70 | int Read(char *buffer, int size); | |
71 | int Write(const char *buffer, int size); | |
72 | GSocketEventFlags Select(GSocketEventFlags flags); | |
73 | void SetNonBlocking(bool non_block); | |
74 | void SetTimeout(unsigned long millis); | |
a4506848 | 75 | GSocketError WXDLLIMPEXP_NET GetError(); |
4b4d23c7 DE |
76 | void SetCallback(GSocketEventFlags flags, |
77 | GSocketCallback callback, char *cdata); | |
78 | void UnsetCallback(GSocketEventFlags flags); | |
79 | GSocketError GetSockOpt(int level, int optname, | |
80 | void *optval, int *optlen); | |
81 | GSocketError SetSockOpt(int level, int optname, | |
82 | const void *optval, int optlen); | |
8c029a5b VZ |
83 | |
84 | void SetInitialSocketBuffers(int recv, int send) | |
85 | { | |
86 | m_initialRecvBufferSize = recv; | |
87 | m_initialSendBufferSize = send; | |
88 | } | |
89 | ||
4b4d23c7 DE |
90 | protected: |
91 | GSocketError Input_Timeout(); | |
92 | GSocketError Output_Timeout(); | |
93 | GSocketError Connect_Timeout(); | |
94 | int Recv_Stream(char *buffer, int size); | |
95 | int Recv_Dgram(char *buffer, int size); | |
96 | int Send_Stream(const char *buffer, int size); | |
97 | int Send_Dgram(const char *buffer, int size); | |
98 | bool m_ok; | |
8c029a5b VZ |
99 | int m_initialRecvBufferSize; |
100 | int m_initialSendBufferSize; | |
4b4d23c7 DE |
101 | |
102 | /* TODO: Make these protected */ | |
103 | public: | |
904ec517 GRG |
104 | SOCKET m_fd; |
105 | GAddress *m_local; | |
106 | GAddress *m_peer; | |
107 | GSocketError m_error; | |
108 | ||
483249fc | 109 | /* Attributes */ |
948c96ef DE |
110 | bool m_non_blocking; |
111 | bool m_server; | |
112 | bool m_stream; | |
113 | bool m_establishing; | |
114 | bool m_reusable; | |
60edcf45 VZ |
115 | bool m_broadcast; |
116 | bool m_dobind; | |
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 __cplusplus |
127 | extern "C" { | |
128 | #endif | |
129 | ||
904ec517 GRG |
130 | /* Definition of GAddress */ |
131 | struct _GAddress | |
132 | { | |
133 | struct sockaddr *m_addr; | |
134 | size_t m_len; | |
135 | ||
136 | GAddressType m_family; | |
137 | int m_realfamily; | |
138 | ||
139 | GSocketError m_error; | |
140 | }; | |
141 | ||
904ec517 GRG |
142 | |
143 | /* GAddress */ | |
144 | ||
145 | GSocketError _GAddress_translate_from(GAddress *address, | |
146 | struct sockaddr *addr, int len); | |
d3ea6527 GRG |
147 | GSocketError _GAddress_translate_to (GAddress *address, |
148 | struct sockaddr **addr, int *len); | |
904ec517 GRG |
149 | GSocketError _GAddress_Init_INET(GAddress *address); |
150 | GSocketError _GAddress_Init_UNIX(GAddress *address); | |
151 | ||
152 | #ifdef __cplusplus | |
153 | } | |
154 | #endif | |
155 | ||
0ce742cf GRG |
156 | #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */ |
157 | ||
904ec517 | 158 | #endif /* __GSOCK_MSW_H */ |