1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket MSW header
6 * -------------------------------------------------------------------------
12 #ifndef __GSOCKET_STANDALONE__
16 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
18 #ifndef __GSOCKET_STANDALONE__
19 #include "wx/gsocket.h"
24 #include "wx/msw/wrapwin.h"
34 class GSocketGUIFunctionsTableConcrete
: public GSocketGUIFunctionsTable
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
);
46 /* Definition of GSocket */
52 bool IsOk() { return m_ok
; }
55 GSocketError
SetLocal(GAddress
*address
);
56 GSocketError
SetPeer(GAddress
*address
);
59 GSocketError
SetServer();
60 GSocket
*WaitConnection();
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
);
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
);
87 /* TODO: Make these protected */
100 struct timeval m_timeout
;
103 GSocketEventFlags m_detected
;
104 GSocketCallback m_cbacks
[GSOCK_MAX_EVENT
];
105 char *m_data
[GSOCK_MAX_EVENT
];
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
)
160 /* Definition of GAddress */
163 struct sockaddr
*m_addr
;
166 GAddressType m_family
;
169 GSocketError m_error
;
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
);
186 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
188 #endif /* __GSOCK_MSW_H */