1999-07-23 13:24:25 -04:00
|
|
|
/* -------------------------------------------------------------------------
|
2005-05-04 14:57:50 -04: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 13:24:25 -04:00
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
1999-09-30 19:53:10 -04:00
|
|
|
|
1999-07-22 13:51:54 -04:00
|
|
|
#ifndef __GSOCK_UNX_H
|
|
|
|
#define __GSOCK_UNX_H
|
|
|
|
|
1999-09-30 19:53:10 -04:00
|
|
|
#ifndef __GSOCKET_STANDALONE__
|
1999-08-06 06:10:10 -04:00
|
|
|
#include "wx/setup.h"
|
1999-09-30 19:53:10 -04:00
|
|
|
#endif
|
1999-08-06 06:10:10 -04:00
|
|
|
|
1999-09-30 19:53:10 -04:00
|
|
|
#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
|
1999-08-06 06:10:10 -04:00
|
|
|
|
1999-09-30 19:53:10 -04:00
|
|
|
#ifndef __GSOCKET_STANDALONE__
|
1999-08-06 06:10:10 -04:00
|
|
|
#include "wx/gsocket.h"
|
1999-09-30 19:53:10 -04:00
|
|
|
#else
|
|
|
|
#include "gsocket.h"
|
|
|
|
#endif
|
|
|
|
|
2004-08-03 15:18:39 -04:00
|
|
|
class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable
|
2004-01-18 02:46:18 -05:00
|
|
|
{
|
|
|
|
public:
|
2004-08-03 15:18:39 -04: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 02:46:18 -05: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 01:30:36 -04:00
|
|
|
bool SetReusable();
|
2004-01-18 02:46:18 -05: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 01:30:36 -04:00
|
|
|
void SetNonBlocking(bool non_block);
|
2004-01-18 02:46:18 -05:00
|
|
|
void SetTimeout(unsigned long millisec);
|
2004-08-03 15:18:39 -04:00
|
|
|
GSocketError WXDLLIMPEXP_NET GetError();
|
2004-01-18 02:46:18 -05:00
|
|
|
void SetCallback(GSocketEventFlags flags,
|
|
|
|
GSocketCallback callback, char *cdata);
|
|
|
|
void UnsetCallback(GSocketEventFlags flags);
|
2004-07-26 22:15:32 -04: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 15:18:39 -04:00
|
|
|
virtual void Detected_Read();
|
|
|
|
virtual void Detected_Write();
|
2004-01-18 02:46:18 -05: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;
|
|
|
|
public:
|
2004-03-09 17:48:53 -05:00
|
|
|
/* DFE: We can't protect these data member until the GUI code is updated */
|
|
|
|
/* protected: */
|
1999-07-22 13:51:54 -04:00
|
|
|
int m_fd;
|
1999-09-30 19:53:10 -04:00
|
|
|
GAddress *m_local;
|
|
|
|
GAddress *m_peer;
|
1999-07-22 13:51:54 -04:00
|
|
|
GSocketError m_error;
|
|
|
|
|
2004-08-08 01:30:36 -04:00
|
|
|
bool m_non_blocking;
|
|
|
|
bool m_server;
|
|
|
|
bool m_stream;
|
|
|
|
bool m_establishing;
|
|
|
|
bool m_reusable;
|
1999-07-30 13:54:18 -04:00
|
|
|
unsigned long m_timeout;
|
1999-07-22 13:51:54 -04:00
|
|
|
|
1999-07-30 13:54:18 -04:00
|
|
|
/* Callbacks */
|
1999-09-30 19:53:10 -04:00
|
|
|
GSocketEventFlags m_detected;
|
1999-08-09 13:35:30 -04:00
|
|
|
GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
|
1999-07-22 13:51:54 -04:00
|
|
|
char *m_data[GSOCK_MAX_EVENT];
|
|
|
|
|
|
|
|
char *m_gui_dependent;
|
2003-08-07 08:26:17 -04:00
|
|
|
|
1999-07-22 13:51:54 -04:00
|
|
|
};
|
|
|
|
|
2004-01-18 02:46:18 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
1999-07-22 13:51:54 -04:00
|
|
|
/* Definition of GAddress */
|
1999-09-30 19:53:10 -04:00
|
|
|
struct _GAddress
|
|
|
|
{
|
1999-07-22 13:51:54 -04:00
|
|
|
struct sockaddr *m_addr;
|
|
|
|
size_t m_len;
|
|
|
|
|
|
|
|
GAddressType m_family;
|
|
|
|
int m_realfamily;
|
|
|
|
|
|
|
|
GSocketError m_error;
|
|
|
|
};
|
2004-01-18 02:46:18 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
1999-07-22 13:51:54 -04:00
|
|
|
|
2000-03-13 23:41:34 -05:00
|
|
|
|
1999-09-30 19:53:10 -04:00
|
|
|
/* GAddress */
|
1999-08-02 13:46:43 -04:00
|
|
|
|
1999-08-04 14:02:24 -04:00
|
|
|
GSocketError _GAddress_translate_from(GAddress *address,
|
|
|
|
struct sockaddr *addr, int len);
|
2000-01-20 22:10:42 -05:00
|
|
|
GSocketError _GAddress_translate_to (GAddress *address,
|
|
|
|
struct sockaddr **addr, int *len);
|
1999-08-04 14:02:24 -04:00
|
|
|
GSocketError _GAddress_Init_INET(GAddress *address);
|
|
|
|
GSocketError _GAddress_Init_UNIX(GAddress *address);
|
1999-07-22 13:51:54 -04:00
|
|
|
|
2000-01-20 22:10:42 -05:00
|
|
|
|
1999-08-06 06:10:10 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
1999-09-30 19:53:10 -04:00
|
|
|
#endif /* __cplusplus */
|
1999-08-06 06:10:10 -04:00
|
|
|
|
1999-09-30 19:53:10 -04:00
|
|
|
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
|
1999-08-06 06:10:10 -04:00
|
|
|
|
1999-09-30 19:53:10 -04:00
|
|
|
#endif /* __GSOCK_UNX_H */
|