1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket Unix header
6 * -------------------------------------------------------------------------
12 #ifndef __GSOCKET_STANDALONE__
16 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
18 #ifndef __GSOCKET_STANDALONE__
19 #include "wx/gsocket.h"
32 #ifdef wxUSE_GSOCKET_CPLUSPLUS
38 bool IsOk() { return m_ok
; }
41 GSocketError
SetLocal(GAddress
*address
);
42 GSocketError
SetPeer(GAddress
*address
);
45 GSocketError
SetServer();
46 GSocket
*WaitConnection();
47 GSocketError
Connect(GSocketStream stream
);
48 GSocketError
SetNonOriented();
49 int Read(char *buffer
, int size
);
50 int Write(const char *buffer
, int size
);
51 GSocketEventFlags
Select(GSocketEventFlags flags
);
52 void SetNonBlocking(int non_block
);
53 void SetTimeout(unsigned long millisec
);
54 GSocketError
GetError();
55 void SetCallback(GSocketEventFlags flags
,
56 GSocketCallback callback
, char *cdata
);
57 void UnsetCallback(GSocketEventFlags flags
);
58 /* API compatibility functions */
59 static void _GSocket_Detected_Read(GSocket
*socket
);
60 static void _GSocket_Detected_Write(GSocket
*socket
);
62 void Enable(GSocketEvent event
);
63 void Disable(GSocketEvent event
);
64 GSocketError
Input_Timeout();
65 GSocketError
Output_Timeout();
66 int Recv_Stream(char *buffer
, int size
);
67 int Recv_Dgram(char *buffer
, int size
);
68 int Send_Stream(const char *buffer
, int size
);
69 int Send_Dgram(const char *buffer
, int size
);
71 void Detected_Write();
74 //DFE: We can't protect these data member until the GUI code is updated
76 #else //def wxUSE_GSOCKET_CPLUSPLUS
80 #endif /* __cplusplus */
81 /* Definition of GSocket */
84 #endif //def wxUSE_GSOCKET_CPLUSPLUS
95 unsigned long m_timeout
;
98 GSocketEventFlags m_detected
;
99 GSocketCallback m_cbacks
[GSOCK_MAX_EVENT
];
100 char *m_data
[GSOCK_MAX_EVENT
];
102 char *m_gui_dependent
;
104 /* Function pointers */
105 struct GSocketBaseFunctionsTable
*m_functions
;
107 #ifndef wxUSE_GSOCKET_CPLUSPLUS
110 #endif /* __cplusplus */
111 #endif //ndef wxUSE_GSOCKET_CPLUSPLUS
115 #endif /* __cplusplus */
116 /* Definition of GAddress */
119 struct sockaddr
*m_addr
;
122 GAddressType m_family
;
125 GSocketError m_error
;
129 #endif /* __cplusplus */
131 // Compatibility methods to support old C API (from gsocket.h)
132 #ifdef wxUSE_GSOCKET_CPLUSPLUS
133 inline void GSocket_Shutdown(GSocket
*socket
)
134 { socket
->Shutdown(); }
135 inline GSocketError
GSocket_SetLocal(GSocket
*socket
, GAddress
*address
)
136 { return socket
->SetLocal(address
); }
137 inline GSocketError
GSocket_SetPeer(GSocket
*socket
, GAddress
*address
)
138 { return socket
->SetPeer(address
); }
139 inline GAddress
*GSocket_GetLocal(GSocket
*socket
)
140 { return socket
->GetLocal(); }
141 inline GAddress
*GSocket_GetPeer(GSocket
*socket
)
142 { return socket
->GetPeer(); }
143 inline GSocketError
GSocket_SetServer(GSocket
*socket
)
144 { return socket
->SetServer(); }
145 inline GSocket
*GSocket_WaitConnection(GSocket
*socket
)
146 { return socket
->WaitConnection(); }
147 inline GSocketError
GSocket_Connect(GSocket
*socket
, GSocketStream stream
)
148 { return socket
->Connect(stream
); }
149 inline GSocketError
GSocket_SetNonOriented(GSocket
*socket
)
150 { return socket
->SetNonOriented(); }
151 inline int GSocket_Read(GSocket
*socket
, char *buffer
, int size
)
152 { return socket
->Read(buffer
,size
); }
153 inline int GSocket_Write(GSocket
*socket
, const char *buffer
, int size
)
154 { return socket
->Write(buffer
,size
); }
155 inline GSocketEventFlags
GSocket_Select(GSocket
*socket
, GSocketEventFlags flags
)
156 { return socket
->Select(flags
); }
157 inline void GSocket_SetNonBlocking(GSocket
*socket
, int non_block
)
158 { socket
->SetNonBlocking(non_block
); }
159 inline void GSocket_SetTimeout(GSocket
*socket
, unsigned long millisec
)
160 { socket
->SetTimeout(millisec
); }
161 inline void GSocket_SetCallback(GSocket
*socket
, GSocketEventFlags flags
,
162 GSocketCallback fallback
, char *cdata
)
163 { socket
->SetCallback(flags
,fallback
,cdata
); }
164 inline void GSocket_UnsetCallback(GSocket
*socket
, GSocketEventFlags flags
)
165 { socket
->UnsetCallback(flags
); }
167 #endif //def wxUSE_GSOCKET_CPLUSPLUS
171 #endif /* __cplusplus */
175 GSocketError
_GSocket_Input_Timeout(GSocket
*socket
);
176 GSocketError
_GSocket_Output_Timeout(GSocket
*socket
);
177 int _GSocket_Recv_Stream(GSocket
*socket
, char *buffer
, int size
);
178 int _GSocket_Recv_Dgram(GSocket
*socket
, char *buffer
, int size
);
179 int _GSocket_Send_Stream(GSocket
*socket
, const char *buffer
, int size
);
180 int _GSocket_Send_Dgram(GSocket
*socket
, const char *buffer
, int size
);
184 int _GSocket_GUI_Init(void);
185 void _GSocket_GUI_Cleanup(void);
187 int _GSocket_GUI_Init_Socket(GSocket
*socket
);
188 void _GSocket_GUI_Destroy_Socket(GSocket
*socket
);
190 void _GSocket_Enable_Events(GSocket
*socket
);
191 void _GSocket_Disable_Events(GSocket
*socket
);
192 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
);
193 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
);
195 void _GSocket_Enable(GSocket
*socket
, GSocketEvent event
);
196 void _GSocket_Disable(GSocket
*socket
, GSocketEvent event
);
198 #ifndef wxUSE_GSOCKET_CPLUSPLUS
199 void _GSocket_Detected_Read(GSocket
*socket
);
200 void _GSocket_Detected_Write(GSocket
*socket
);
201 #endif //ndef wxUSE_GSOCKET_CPLUSPLUS
205 GSocketError
_GAddress_translate_from(GAddress
*address
,
206 struct sockaddr
*addr
, int len
);
207 GSocketError
_GAddress_translate_to (GAddress
*address
,
208 struct sockaddr
**addr
, int *len
);
209 GSocketError
_GAddress_Init_INET(GAddress
*address
);
210 GSocketError
_GAddress_Init_UNIX(GAddress
*address
);
215 #endif /* __cplusplus */
217 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
219 #endif /* __GSOCK_UNX_H */