1999-07-22 13:51:54 -04:00
|
|
|
/* -------------------------------------------------------------------------
|
2005-05-04 14:57:50 -04:00
|
|
|
* Project: GSocket (Generic Socket)
|
|
|
|
* Name: gsocket.h
|
|
|
|
* Author: Guilhem Lavaux
|
|
|
|
* Guillermo Rodriguez Garcia <guille@iies.es> (maintainer)
|
|
|
|
* Copyright: (c) Guilhem Lavaux
|
|
|
|
* Licence: wxWindows Licence
|
|
|
|
* Purpose: GSocket include file (system independent)
|
|
|
|
* CVSID: $Id$
|
1999-07-22 13:51:54 -04:00
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
2000-01-20 22:10:42 -05:00
|
|
|
|
1999-07-22 13:51:54 -04:00
|
|
|
#ifndef __GSOCKET_H
|
|
|
|
#define __GSOCKET_H
|
|
|
|
|
1999-09-14 22:21:15 -04:00
|
|
|
#ifndef __GSOCKET_STANDALONE__
|
2005-03-16 11:18:31 -05:00
|
|
|
#include "wx/defs.h"
|
2002-07-01 21:21:09 -04:00
|
|
|
|
2004-03-09 17:48:53 -05:00
|
|
|
#include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
|
2002-07-01 21:21:09 -04:00
|
|
|
|
1999-09-14 22:21:15 -04:00
|
|
|
#endif
|
1999-08-06 06:10:10 -04:00
|
|
|
|
1999-09-14 22:21:15 -04:00
|
|
|
#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
|
1999-08-06 06:10:10 -04:00
|
|
|
|
1999-08-09 13:35:30 -04:00
|
|
|
#include <stddef.h>
|
2002-09-12 09:48:55 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Including sys/types.h under cygwin results in the warnings about "fd_set
|
|
|
|
having been defined in sys/types.h" when winsock.h is included later and
|
|
|
|
doesn't seem to be necessary anyhow. It's not needed under Mac neither.
|
|
|
|
*/
|
2003-07-12 13:58:22 -04:00
|
|
|
#if !defined(__WXMAC__) && !defined(__CYGWIN__) && !defined(__WXWINCE__)
|
1999-07-22 13:51:54 -04:00
|
|
|
#include <sys/types.h>
|
2000-08-09 07:14:15 -04:00
|
|
|
#endif
|
1999-07-22 13:51:54 -04:00
|
|
|
|
2003-07-12 13:58:22 -04:00
|
|
|
#ifdef __WXWINCE__
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
2004-08-02 23:33:36 -04:00
|
|
|
class GSocket;
|
2004-01-18 02:46:18 -05:00
|
|
|
|
1999-09-11 16:29:14 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1999-07-22 13:51:54 -04:00
|
|
|
typedef struct _GAddress GAddress;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
GSOCK_NOFAMILY = 0,
|
|
|
|
GSOCK_INET,
|
|
|
|
GSOCK_INET6,
|
|
|
|
GSOCK_UNIX
|
|
|
|
} GAddressType;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
GSOCK_STREAMED,
|
|
|
|
GSOCK_UNSTREAMED
|
|
|
|
} GSocketStream;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
GSOCK_NOERROR = 0,
|
|
|
|
GSOCK_INVOP,
|
|
|
|
GSOCK_IOERR,
|
|
|
|
GSOCK_INVADDR,
|
|
|
|
GSOCK_INVSOCK,
|
|
|
|
GSOCK_NOHOST,
|
1999-08-01 03:26:36 -04:00
|
|
|
GSOCK_INVPORT,
|
1999-08-09 13:35:30 -04:00
|
|
|
GSOCK_WOULDBLOCK,
|
1999-09-05 06:23:22 -04:00
|
|
|
GSOCK_TIMEDOUT,
|
2004-07-25 07:16:31 -04:00
|
|
|
GSOCK_MEMERR,
|
2004-08-20 06:05:47 -04:00
|
|
|
GSOCK_OPTERR
|
1999-07-22 13:51:54 -04:00
|
|
|
} GSocketError;
|
|
|
|
|
2000-01-20 22:10:42 -05:00
|
|
|
/* See below for an explanation on how events work.
|
|
|
|
*/
|
1999-07-22 13:51:54 -04:00
|
|
|
typedef enum {
|
|
|
|
GSOCK_INPUT = 0,
|
|
|
|
GSOCK_OUTPUT = 1,
|
|
|
|
GSOCK_CONNECTION = 2,
|
|
|
|
GSOCK_LOST = 3,
|
|
|
|
GSOCK_MAX_EVENT = 4
|
|
|
|
} GSocketEvent;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
GSOCK_INPUT_FLAG = 1 << GSOCK_INPUT,
|
|
|
|
GSOCK_OUTPUT_FLAG = 1 << GSOCK_OUTPUT,
|
|
|
|
GSOCK_CONNECTION_FLAG = 1 << GSOCK_CONNECTION,
|
1999-07-23 17:03:02 -04:00
|
|
|
GSOCK_LOST_FLAG = 1 << GSOCK_LOST
|
1999-07-22 13:51:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef int GSocketEventFlags;
|
|
|
|
|
1999-07-30 13:54:18 -04:00
|
|
|
typedef void (*GSocketCallback)(GSocket *socket, GSocketEvent event,
|
1999-07-23 17:03:02 -04:00
|
|
|
char *cdata);
|
1999-07-22 13:51:54 -04:00
|
|
|
|
|
|
|
|
2003-08-07 08:26:17 -04:00
|
|
|
/* Functions tables for internal use by GSocket code: */
|
|
|
|
|
2004-08-02 23:33:36 -04:00
|
|
|
/* Actually this is a misnomer now, but reusing this name means I don't
|
|
|
|
have to ifdef app traits or common socket code */
|
|
|
|
class GSocketGUIFunctionsTable
|
|
|
|
{
|
|
|
|
public:
|
2005-02-24 09:33:32 -05:00
|
|
|
// needed since this class declares virtual members
|
|
|
|
virtual ~GSocketGUIFunctionsTable() { }
|
2004-08-02 23:33:36 -04:00
|
|
|
virtual bool OnInit() = 0;
|
|
|
|
virtual void OnExit() = 0;
|
|
|
|
virtual bool CanUseEventLoop() = 0;
|
|
|
|
virtual bool Init_Socket(GSocket *socket) = 0;
|
|
|
|
virtual void Destroy_Socket(GSocket *socket) = 0;
|
|
|
|
#ifndef __WINDOWS__
|
|
|
|
virtual void Install_Callback(GSocket *socket, GSocketEvent event) = 0;
|
|
|
|
virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event) = 0;
|
|
|
|
#endif
|
|
|
|
virtual void Enable_Events(GSocket *socket) = 0;
|
|
|
|
virtual void Disable_Events(GSocket *socket) = 0;
|
|
|
|
};
|
|
|
|
|
2003-08-07 08:26:17 -04:00
|
|
|
|
1999-09-11 16:29:14 -04:00
|
|
|
/* Global initializers */
|
1999-07-25 10:26:15 -04:00
|
|
|
|
2003-08-07 08:26:17 -04:00
|
|
|
/* Sets GUI functions callbacks. Must be called *before* GSocket_Init
|
|
|
|
if the app uses async sockets. */
|
2004-08-08 00:48:33 -04:00
|
|
|
void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable *guifunc);
|
2003-08-07 08:26:17 -04:00
|
|
|
|
1999-07-25 10:26:15 -04:00
|
|
|
/* GSocket_Init() must be called at the beginning */
|
2000-03-16 16:57:20 -05:00
|
|
|
int GSocket_Init(void);
|
2000-01-20 22:10:42 -05:00
|
|
|
|
|
|
|
/* GSocket_Cleanup() must be called at the end */
|
2000-03-14 04:32:27 -05:00
|
|
|
void GSocket_Cleanup(void);
|
1999-07-25 10:26:15 -04:00
|
|
|
|
2000-01-20 22:10:42 -05:00
|
|
|
|
1999-07-22 13:51:54 -04:00
|
|
|
/* Constructors / Destructors */
|
|
|
|
|
2000-03-14 04:32:27 -05:00
|
|
|
GSocket *GSocket_new(void);
|
2004-01-18 02:46:18 -05:00
|
|
|
|
2000-01-20 22:10:42 -05:00
|
|
|
|
1999-07-22 13:51:54 -04:00
|
|
|
/* GAddress */
|
|
|
|
|
2000-03-14 04:32:27 -05:00
|
|
|
GAddress *GAddress_new(void);
|
1999-07-22 13:51:54 -04:00
|
|
|
GAddress *GAddress_copy(GAddress *address);
|
|
|
|
void GAddress_destroy(GAddress *address);
|
|
|
|
|
|
|
|
void GAddress_SetFamily(GAddress *address, GAddressType type);
|
|
|
|
GAddressType GAddress_GetFamily(GAddress *address);
|
|
|
|
|
1999-09-11 16:29:14 -04:00
|
|
|
/* The use of any of the next functions will set the address family to
|
|
|
|
* the specific one. For example if you use GAddress_INET_SetHostName,
|
|
|
|
* address family will be implicitly set to AF_INET.
|
|
|
|
*/
|
1999-07-22 13:51:54 -04:00
|
|
|
|
|
|
|
GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
|
2000-01-20 22:10:42 -05:00
|
|
|
GSocketError GAddress_INET_SetAnyAddress(GAddress *address);
|
1999-07-22 13:51:54 -04:00
|
|
|
GSocketError GAddress_INET_SetHostAddress(GAddress *address,
|
|
|
|
unsigned long hostaddr);
|
1999-07-24 05:05:25 -04:00
|
|
|
GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
|
|
|
|
const char *protocol);
|
1999-07-22 13:51:54 -04:00
|
|
|
GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
|
|
|
|
|
|
|
|
GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
|
|
|
|
size_t sbuf);
|
|
|
|
unsigned long GAddress_INET_GetHostAddress(GAddress *address);
|
|
|
|
unsigned short GAddress_INET_GetPort(GAddress *address);
|
|
|
|
|
|
|
|
/* TODO: Define specific parts (INET6, UNIX) */
|
|
|
|
|
|
|
|
GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path);
|
|
|
|
GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2002-05-09 18:34:44 -04:00
|
|
|
}
|
1999-08-06 06:10:10 -04:00
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2004-08-06 15:11:09 -04:00
|
|
|
# if defined(__WINDOWS__)
|
2004-08-02 23:33:36 -04:00
|
|
|
# include "wx/msw/gsockmsw.h"
|
2004-08-06 15:11:09 -04:00
|
|
|
# elif defined(__WXMAC__) && !defined(__DARWIN__)
|
|
|
|
# include "wx/mac/gsockmac.h"
|
2004-08-02 23:33:36 -04:00
|
|
|
# else
|
|
|
|
# include "wx/unix/gsockunx.h"
|
|
|
|
# endif
|
1999-08-06 06:10:10 -04:00
|
|
|
|
1999-09-14 22:21:15 -04:00
|
|
|
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
|
1999-07-22 13:51:54 -04:00
|
|
|
|
1999-09-11 16:29:14 -04:00
|
|
|
#endif /* __GSOCKET_H */
|