]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/gsockunx.h
ed3640f507a10d5424ffc740e07a6091279bdb88
[wxWidgets.git] / include / wx / unix / gsockunx.h
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockunx.h
4 * Purpose: GSocket Unix header
5 * CVSID: $Id$
6 * -------------------------------------------------------------------------
7 */
8
9 #ifndef __GSOCK_UNX_H
10 #define __GSOCK_UNX_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 #ifndef TRUE
25 #define TRUE 1
26 #endif
27
28 #ifndef FALSE
29 #define FALSE 0
30 #endif
31
32 class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable
33 {
34 public:
35 virtual bool OnInit();
36 virtual void OnExit();
37 virtual bool CanUseEventLoop();
38 virtual bool Init_Socket(GSocket *socket);
39 virtual void Destroy_Socket(GSocket *socket);
40 virtual void Install_Callback(GSocket *socket, GSocketEvent event);
41 virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event);
42 virtual void Enable_Events(GSocket *socket);
43 virtual void Disable_Events(GSocket *socket);
44 };
45
46 class GSocket
47 {
48 public:
49 GSocket();
50 virtual ~GSocket();
51 bool IsOk() { return m_ok; }
52 void Close();
53 void Shutdown();
54 GSocketError SetLocal(GAddress *address);
55 GSocketError SetPeer(GAddress *address);
56 GAddress *GetLocal();
57 GAddress *GetPeer();
58 GSocketError SetServer();
59 GSocket *WaitConnection();
60 int SetReusable();
61 GSocketError Connect(GSocketStream stream);
62 GSocketError SetNonOriented();
63 int Read(char *buffer, int size);
64 int Write(const char *buffer, int size);
65 GSocketEventFlags Select(GSocketEventFlags flags);
66 void SetNonBlocking(int non_block);
67 void SetTimeout(unsigned long millisec);
68 GSocketError WXDLLIMPEXP_NET GetError();
69 void SetCallback(GSocketEventFlags flags,
70 GSocketCallback callback, char *cdata);
71 void UnsetCallback(GSocketEventFlags flags);
72 GSocketError GetSockOpt(int level, int optname, void *optval, int *optlen);
73 GSocketError SetSockOpt(int level, int optname,
74 const void *optval, int optlen);
75 /* API compatibility functions */
76 static void _GSocket_Detected_Read(GSocket *socket);
77 static void _GSocket_Detected_Write(GSocket *socket);
78 virtual void Detected_Read();
79 virtual void Detected_Write();
80 protected:
81 void Enable(GSocketEvent event);
82 void Disable(GSocketEvent event);
83 GSocketError Input_Timeout();
84 GSocketError Output_Timeout();
85 int Recv_Stream(char *buffer, int size);
86 int Recv_Dgram(char *buffer, int size);
87 int Send_Stream(const char *buffer, int size);
88 int Send_Dgram(const char *buffer, int size);
89 bool m_ok;
90 public:
91 /* DFE: We can't protect these data member until the GUI code is updated */
92 /* protected: */
93 int m_fd;
94 GAddress *m_local;
95 GAddress *m_peer;
96 GSocketError m_error;
97
98 int m_non_blocking;
99 int m_server;
100 int m_stream;
101 int m_establishing;
102 int m_reusable;
103 unsigned long m_timeout;
104
105 /* Callbacks */
106 GSocketEventFlags m_detected;
107 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
108 char *m_data[GSOCK_MAX_EVENT];
109
110 char *m_gui_dependent;
111
112 };
113
114 #ifdef __cplusplus
115 extern "C" {
116 #endif /* __cplusplus */
117 /* Definition of GAddress */
118 struct _GAddress
119 {
120 struct sockaddr *m_addr;
121 size_t m_len;
122
123 GAddressType m_family;
124 int m_realfamily;
125
126 GSocketError m_error;
127 };
128 #ifdef __cplusplus
129 }
130 #endif /* __cplusplus */
131
132
133 #ifdef __cplusplus
134 extern "C" {
135 #endif /* __cplusplus */
136
137
138 /* GAddress */
139
140 GSocketError _GAddress_translate_from(GAddress *address,
141 struct sockaddr *addr, int len);
142 GSocketError _GAddress_translate_to (GAddress *address,
143 struct sockaddr **addr, int *len);
144 GSocketError _GAddress_Init_INET(GAddress *address);
145 GSocketError _GAddress_Init_UNIX(GAddress *address);
146
147
148 #ifdef __cplusplus
149 }
150 #endif /* __cplusplus */
151
152 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
153
154 #endif /* __GSOCK_UNX_H */