1999-09-07 11:20:51 -04:00
|
|
|
/* -------------------------------------------------------------------------
|
2005-05-04 14:57:50 -04:00
|
|
|
* Project: GSocket (Generic Socket) for WX
|
|
|
|
* Name: gsockmsw.h
|
|
|
|
* Copyright: (c) Guilhem Lavaux
|
|
|
|
* Licence: wxWindows Licence
|
|
|
|
* Purpose: GSocket MSW header
|
|
|
|
* CVSID: $Id$
|
1999-09-07 11:20:51 -04:00
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GSOCK_MSW_H
|
|
|
|
#define __GSOCK_MSW_H
|
|
|
|
|
1999-09-14 22:21:15 -04:00
|
|
|
#ifndef __GSOCKET_STANDALONE__
|
|
|
|
#include "wx/setup.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
|
|
|
|
|
1999-09-14 20:02:49 -04:00
|
|
|
#ifndef __GSOCKET_STANDALONE__
|
1999-09-07 11:20:51 -04:00
|
|
|
#include "wx/gsocket.h"
|
|
|
|
#else
|
|
|
|
#include "gsocket.h"
|
|
|
|
#endif
|
|
|
|
|
2004-08-02 23:33:36 -04:00
|
|
|
#include "wx/msw/wrapwin.h"
|
1999-09-14 20:02:49 -04:00
|
|
|
|
2005-04-10 02:33:26 -04:00
|
|
|
#if defined(__CYGWIN__)
|
|
|
|
//CYGWIN gives annoying warning about runtime stuff if we don't do this
|
|
|
|
# define USE_SYS_TYPES_FD_SET
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__WXWINCE__) || defined(__CYGWIN__)
|
2005-02-10 09:55:27 -05:00
|
|
|
#include <winsock.h>
|
|
|
|
#endif
|
|
|
|
|
2004-08-02 23:33:36 -04:00
|
|
|
class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool OnInit();
|
|
|
|
virtual void OnExit();
|
|
|
|
virtual bool CanUseEventLoop();
|
|
|
|
virtual bool Init_Socket(GSocket *socket);
|
|
|
|
virtual void Destroy_Socket(GSocket *socket);
|
|
|
|
virtual void Enable_Events(GSocket *socket);
|
|
|
|
virtual void Disable_Events(GSocket *socket);
|
|
|
|
};
|
|
|
|
|
1999-09-07 11:20:51 -04:00
|
|
|
/* Definition of GSocket */
|
2004-08-02 23:33:36 -04:00
|
|
|
class GSocket
|
1999-09-07 11:20:51 -04:00
|
|
|
{
|
2004-08-02 23:33:36 -04:00
|
|
|
public:
|
|
|
|
GSocket();
|
|
|
|
~GSocket();
|
|
|
|
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();
|
2007-07-04 17:33:11 -04:00
|
|
|
bool SetBroadcast();
|
|
|
|
bool DontDoBind();
|
2004-08-02 23:33:36 -04:00
|
|
|
GSocketError Connect(GSocketStream stream);
|
|
|
|
GSocketError SetNonOriented();
|
|
|
|
int Read(char *buffer, int size);
|
|
|
|
int Write(const char *buffer, int size);
|
|
|
|
GSocketEventFlags Select(GSocketEventFlags flags);
|
|
|
|
void SetNonBlocking(bool non_block);
|
|
|
|
void SetTimeout(unsigned long millis);
|
2004-08-03 00:14:42 -04:00
|
|
|
GSocketError WXDLLIMPEXP_NET GetError();
|
2004-08-02 23:33:36 -04:00
|
|
|
void SetCallback(GSocketEventFlags flags,
|
|
|
|
GSocketCallback callback, char *cdata);
|
|
|
|
void UnsetCallback(GSocketEventFlags flags);
|
|
|
|
GSocketError GetSockOpt(int level, int optname,
|
|
|
|
void *optval, int *optlen);
|
|
|
|
GSocketError SetSockOpt(int level, int optname,
|
|
|
|
const void *optval, int optlen);
|
|
|
|
protected:
|
|
|
|
GSocketError Input_Timeout();
|
|
|
|
GSocketError Output_Timeout();
|
|
|
|
GSocketError Connect_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;
|
|
|
|
|
|
|
|
/* TODO: Make these protected */
|
|
|
|
public:
|
1999-09-07 11:20:51 -04:00
|
|
|
SOCKET m_fd;
|
|
|
|
GAddress *m_local;
|
|
|
|
GAddress *m_peer;
|
|
|
|
GSocketError m_error;
|
|
|
|
|
1999-09-30 19:53:10 -04:00
|
|
|
/* Attributes */
|
2004-08-08 01:30:36 -04:00
|
|
|
bool m_non_blocking;
|
|
|
|
bool m_server;
|
|
|
|
bool m_stream;
|
|
|
|
bool m_establishing;
|
|
|
|
bool m_reusable;
|
2007-07-04 17:33:11 -04:00
|
|
|
bool m_broadcast;
|
|
|
|
bool m_dobind;
|
1999-09-07 11:20:51 -04:00
|
|
|
struct timeval m_timeout;
|
|
|
|
|
|
|
|
/* Callbacks */
|
1999-09-30 19:53:10 -04:00
|
|
|
GSocketEventFlags m_detected;
|
1999-09-07 11:20:51 -04:00
|
|
|
GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
|
|
|
|
char *m_data[GSOCK_MAX_EVENT];
|
|
|
|
int m_msgnumber;
|
|
|
|
};
|
|
|
|
|
2004-08-02 23:33:36 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1999-09-07 11:20:51 -04:00
|
|
|
/* Definition of GAddress */
|
|
|
|
struct _GAddress
|
|
|
|
{
|
|
|
|
struct sockaddr *m_addr;
|
|
|
|
size_t m_len;
|
|
|
|
|
|
|
|
GAddressType m_family;
|
|
|
|
int m_realfamily;
|
|
|
|
|
|
|
|
GSocketError m_error;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* GAddress */
|
|
|
|
|
|
|
|
GSocketError _GAddress_translate_from(GAddress *address,
|
|
|
|
struct sockaddr *addr, int len);
|
2000-01-20 22:12:01 -05:00
|
|
|
GSocketError _GAddress_translate_to (GAddress *address,
|
|
|
|
struct sockaddr **addr, int *len);
|
1999-09-07 11:20:51 -04:00
|
|
|
GSocketError _GAddress_Init_INET(GAddress *address);
|
|
|
|
GSocketError _GAddress_Init_UNIX(GAddress *address);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-09-14 22:21:15 -04:00
|
|
|
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
|
|
|
|
|
1999-09-07 11:20:51 -04:00
|
|
|
#endif /* __GSOCK_MSW_H */
|