1999-07-23 17:24:25 +00:00
|
|
|
/* -------------------------------------------------------------------------
|
2005-05-04 18:57:50 +00:00
|
|
|
* Project: GSocket (Generic Socket) for WX
|
|
|
|
* Name: gsockunx.h
|
|
|
|
* Copyright: (c) Guilhem Lavaux
|
|
|
|
* Licence: wxWindows Licence
|
|
|
|
* Purpose: GSocket Unix header
|
|
|
|
* CVSID: $Id$
|
1999-07-23 17:24:25 +00:00
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
1999-09-30 23:53:10 +00:00
|
|
|
|
1999-07-22 17:51:54 +00:00
|
|
|
#ifndef __GSOCK_UNX_H
|
|
|
|
#define __GSOCK_UNX_H
|
|
|
|
|
1999-09-30 23:53:10 +00:00
|
|
|
#ifndef __GSOCKET_STANDALONE__
|
1999-08-06 10:10:10 +00:00
|
|
|
#include "wx/setup.h"
|
1999-09-30 23:53:10 +00:00
|
|
|
#endif
|
1999-08-06 10:10:10 +00:00
|
|
|
|
2007-07-14 20:18:38 +00:00
|
|
|
class wxGSocketIOHandler;
|
|
|
|
|
1999-09-30 23:53:10 +00:00
|
|
|
#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
|
1999-08-06 10:10:10 +00:00
|
|
|
|
1999-09-30 23:53:10 +00:00
|
|
|
#ifndef __GSOCKET_STANDALONE__
|
1999-08-06 10:10:10 +00:00
|
|
|
#include "wx/gsocket.h"
|
1999-09-30 23:53:10 +00:00
|
|
|
#else
|
|
|
|
#include "gsocket.h"
|
|
|
|
#endif
|
|
|
|
|
2007-07-14 20:18:38 +00:00
|
|
|
class GSocketGUIFunctionsTableConcrete : public GSocketGUIFunctionsTable
|
2004-01-18 07:46:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-08-03 19:18:39 +00:00
|
|
|
virtual bool OnInit();
|
|
|
|
virtual void OnExit();
|
|
|
|
virtual bool CanUseEventLoop();
|
|
|
|
virtual bool Init_Socket(GSocket *socket);
|
|
|
|
virtual void Destroy_Socket(GSocket *socket);
|
|
|
|
virtual void Install_Callback(GSocket *socket, GSocketEvent event);
|
|
|
|
virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event);
|
|
|
|
virtual void Enable_Events(GSocket *socket);
|
|
|
|
virtual void Disable_Events(GSocket *socket);
|
|
|
|
};
|
|
|
|
|
|
|
|
class GSocket
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GSocket();
|
|
|
|
virtual ~GSocket();
|
2004-01-18 07:46:18 +00:00
|
|
|
bool IsOk() { return m_ok; }
|
|
|
|
void Close();
|
|
|
|
void Shutdown();
|
|
|
|
GSocketError SetLocal(GAddress *address);
|
|
|
|
GSocketError SetPeer(GAddress *address);
|
|
|
|
GAddress *GetLocal();
|
|
|
|
GAddress *GetPeer();
|
|
|
|
GSocketError SetServer();
|
|
|
|
GSocket *WaitConnection();
|
2004-08-08 05:30:36 +00:00
|
|
|
bool SetReusable();
|
2007-07-04 21:33:11 +00:00
|
|
|
bool SetBroadcast();
|
|
|
|
bool DontDoBind();
|
2004-01-18 07:46:18 +00:00
|
|
|
GSocketError Connect(GSocketStream stream);
|
|
|
|
GSocketError SetNonOriented();
|
|
|
|
int Read(char *buffer, int size);
|
|
|
|
int Write(const char *buffer, int size);
|
|
|
|
GSocketEventFlags Select(GSocketEventFlags flags);
|
2004-08-08 05:30:36 +00:00
|
|
|
void SetNonBlocking(bool non_block);
|
2004-01-18 07:46:18 +00:00
|
|
|
void SetTimeout(unsigned long millisec);
|
2004-08-03 19:18:39 +00:00
|
|
|
GSocketError WXDLLIMPEXP_NET GetError();
|
2004-01-18 07:46:18 +00:00
|
|
|
void SetCallback(GSocketEventFlags flags,
|
|
|
|
GSocketCallback callback, char *cdata);
|
|
|
|
void UnsetCallback(GSocketEventFlags flags);
|
2004-07-27 02:15:32 +00:00
|
|
|
GSocketError GetSockOpt(int level, int optname, void *optval, int *optlen);
|
|
|
|
GSocketError SetSockOpt(int level, int optname,
|
|
|
|
const void *optval, int optlen);
|
2004-08-03 19:18:39 +00:00
|
|
|
virtual void Detected_Read();
|
|
|
|
virtual void Detected_Write();
|
2007-11-17 15:21:26 +00:00
|
|
|
void SetInitialSocketBuffers(int recv, int send)
|
|
|
|
{
|
|
|
|
m_initialRecvBufferSize = recv;
|
|
|
|
m_initialSendBufferSize = send;
|
|
|
|
}
|
|
|
|
|
2004-01-18 07:46:18 +00:00
|
|
|
protected:
|
|
|
|
void Enable(GSocketEvent event);
|
|
|
|
void Disable(GSocketEvent event);
|
|
|
|
GSocketError Input_Timeout();
|
|
|
|
GSocketError Output_Timeout();
|
|
|
|
int Recv_Stream(char *buffer, int size);
|
|
|
|
int Recv_Dgram(char *buffer, int size);
|
|
|
|
int Send_Stream(const char *buffer, int size);
|
|
|
|
int Send_Dgram(const char *buffer, int size);
|
|
|
|
bool m_ok;
|
2007-11-17 15:21:26 +00:00
|
|
|
int m_initialRecvBufferSize;
|
|
|
|
int m_initialSendBufferSize;
|
2004-01-18 07:46:18 +00:00
|
|
|
public:
|
2004-03-09 22:48:53 +00:00
|
|
|
/* DFE: We can't protect these data member until the GUI code is updated */
|
|
|
|
/* protected: */
|
1999-07-22 17:51:54 +00:00
|
|
|
int m_fd;
|
2007-07-14 20:18:38 +00:00
|
|
|
wxGSocketIOHandler *m_handler;
|
1999-09-30 23:53:10 +00:00
|
|
|
GAddress *m_local;
|
|
|
|
GAddress *m_peer;
|
1999-07-22 17:51:54 +00:00
|
|
|
GSocketError m_error;
|
|
|
|
|
2004-08-08 05:30:36 +00:00
|
|
|
bool m_non_blocking;
|
|
|
|
bool m_server;
|
|
|
|
bool m_stream;
|
|
|
|
bool m_establishing;
|
|
|
|
bool m_reusable;
|
2007-07-04 21:33:11 +00:00
|
|
|
bool m_broadcast;
|
|
|
|
bool m_dobind;
|
1999-07-30 17:54:18 +00:00
|
|
|
unsigned long m_timeout;
|
1999-07-22 17:51:54 +00:00
|
|
|
|
1999-07-30 17:54:18 +00:00
|
|
|
/* Callbacks */
|
1999-09-30 23:53:10 +00:00
|
|
|
GSocketEventFlags m_detected;
|
1999-08-09 17:35:30 +00:00
|
|
|
GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
|
1999-07-22 17:51:54 +00:00
|
|
|
char *m_data[GSOCK_MAX_EVENT];
|
|
|
|
|
|
|
|
char *m_gui_dependent;
|
2003-08-07 12:26:17 +00:00
|
|
|
|
1999-07-22 17:51:54 +00:00
|
|
|
};
|
|
|
|
|
2004-01-18 07:46:18 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
1999-07-22 17:51:54 +00:00
|
|
|
/* Definition of GAddress */
|
1999-09-30 23:53:10 +00:00
|
|
|
struct _GAddress
|
|
|
|
{
|
1999-07-22 17:51:54 +00:00
|
|
|
struct sockaddr *m_addr;
|
|
|
|
size_t m_len;
|
|
|
|
|
|
|
|
GAddressType m_family;
|
|
|
|
int m_realfamily;
|
|
|
|
|
|
|
|
GSocketError m_error;
|
|
|
|
};
|
2004-01-18 07:46:18 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
1999-07-22 17:51:54 +00:00
|
|
|
|
2000-03-14 04:41:34 +00:00
|
|
|
|
1999-09-30 23:53:10 +00:00
|
|
|
/* GAddress */
|
1999-08-02 17:46:43 +00:00
|
|
|
|
1999-08-04 18:02:24 +00:00
|
|
|
GSocketError _GAddress_translate_from(GAddress *address,
|
|
|
|
struct sockaddr *addr, int len);
|
2000-01-21 03:10:42 +00:00
|
|
|
GSocketError _GAddress_translate_to (GAddress *address,
|
|
|
|
struct sockaddr **addr, int *len);
|
1999-08-04 18:02:24 +00:00
|
|
|
GSocketError _GAddress_Init_INET(GAddress *address);
|
|
|
|
GSocketError _GAddress_Init_UNIX(GAddress *address);
|
1999-07-22 17:51:54 +00:00
|
|
|
|
2000-01-21 03:10:42 +00:00
|
|
|
|
1999-08-06 10:10:10 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
1999-09-30 23:53:10 +00:00
|
|
|
#endif /* __cplusplus */
|
1999-08-06 10:10:10 +00:00
|
|
|
|
1999-09-30 23:53:10 +00:00
|
|
|
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
|
1999-08-06 10:10:10 +00:00
|
|
|
|
1999-09-30 23:53:10 +00:00
|
|
|
#endif /* __GSOCK_UNX_H */
|