Added GSocket for Unix (only GTK for the moment)
Updated wxSocket to use GSocket API Added a progress bar to client.cpp Added CopyTo to wxMemoryOutputStream to copy the internal buffer to a specified buffer. Various changes/fixes to the high-level protocols FTP/HTTP Various Unicode fixes Removed sckint.* git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3085 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
233
include/wx/gsocket.h
Normal file
233
include/wx/gsocket.h
Normal file
@@ -0,0 +1,233 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: GSocket (Generic Socket)
|
||||
* Name: gsocket.h
|
||||
* Purpose: GSocket include file (system independent)
|
||||
* CVSID: $Id$
|
||||
* Log: $Log$
|
||||
* Log: Revision 1.1 1999/07/22 17:51:47 GL
|
||||
* Log: Added GSocket for Unix (only GTK for the moment)
|
||||
* Log: Updated wxSocket to use GSocket API
|
||||
* Log: Added a progress bar to client.cpp
|
||||
* Log: Added CopyTo to wxMemoryOutputStream to copy the internal buffer to a specified buffer.
|
||||
* Log: Various changes/fixes to the high-level protocols FTP/HTTP
|
||||
* Log: Various Unicode fixes
|
||||
* Log: Removed sckint.*
|
||||
* Log:
|
||||
* Log: Revision 1.2 1999/07/18 15:54:28 guilhem
|
||||
* Log: Copyright, etc.
|
||||
* Log:
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef __GSOCKET_H
|
||||
#define __GSOCKET_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if !defined(__cplusplus)
|
||||
|
||||
typedef int bool;
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
typedef struct _GSocket GSocket;
|
||||
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,
|
||||
GSOCK_INVPORT
|
||||
} GSocketError;
|
||||
|
||||
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,
|
||||
GSOCK_LOST_FLAG = 1 << GSOCK_LOST,
|
||||
};
|
||||
|
||||
typedef int GSocketEventFlags;
|
||||
|
||||
typedef void (*GSocketFallback)(GSocket *socket, GSocketEvent event,
|
||||
char *cdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Constructors / Destructors */
|
||||
|
||||
GSocket *GSocket_new();
|
||||
void GSocket_destroy(GSocket *socket);
|
||||
|
||||
/* This will disable all IO calls to this socket but errors are still available */
|
||||
void GSocket_Shutdown(GSocket *socket);
|
||||
|
||||
/* Address handling */
|
||||
|
||||
GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address);
|
||||
GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address);
|
||||
GAddress *GSocket_GetLocal(GSocket *socket);
|
||||
GAddress *GSocket_GetPeer(GSocket *socket);
|
||||
|
||||
/* Non-oriented connections handlers */
|
||||
|
||||
GSocketError GSocket_SetNonOriented(GSocket *socket);
|
||||
|
||||
/* Server specific parts */
|
||||
|
||||
/*
|
||||
GSocket_SetServer() setup the socket as a server. It uses the "Local" field
|
||||
of GSocket. "Local" must be set by GSocket_SetLocal() before
|
||||
GSocket_SetServer() is called. In the other case, it returns GSOCK_INVADDR.
|
||||
*/
|
||||
GSocketError GSocket_SetServer(GSocket *socket);
|
||||
|
||||
/*
|
||||
GSocket_WaitConnection() waits for an incoming client connection.
|
||||
*/
|
||||
GSocket *GSocket_WaitConnection(GSocket *socket);
|
||||
|
||||
/* Client specific parts */
|
||||
|
||||
/*
|
||||
GSocket_Connect() establishes a client connection to a server using the "Peer"
|
||||
field of GSocket. "Peer" must be set by GSocket_SetPeer() before
|
||||
GSocket_Connect() is called. In the other case, it returns GSOCK_INVADDR.
|
||||
*/
|
||||
GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream);
|
||||
|
||||
/* Generic IO */
|
||||
|
||||
/* Like recv(), send(), ... */
|
||||
/*
|
||||
NOTE: In case we read from a non-oriented connection, the incoming (outgoing)
|
||||
connection address is stored in the "Local" ("Peer") field.
|
||||
*/
|
||||
int GSocket_Read(GSocket *socket, char *buffer, int size);
|
||||
int GSocket_Write(GSocket *socket, const char *buffer,
|
||||
int size);
|
||||
bool GSocket_DataAvailable(GSocket *socket);
|
||||
|
||||
/* Flags */
|
||||
|
||||
/*
|
||||
GSocket_SetBlocking() puts the socket in non-blocking mode. This is useful
|
||||
if we don't want to wait.
|
||||
*/
|
||||
void GSocket_SetBlocking(GSocket *socket, bool block);
|
||||
|
||||
/*
|
||||
GSocket_GetError() returns the last error occured on the socket stream.
|
||||
*/
|
||||
|
||||
GSocketError GSocket_GetError(GSocket *socket);
|
||||
|
||||
/* Callbacks */
|
||||
|
||||
/*
|
||||
Only one fallback is possible for each event (INPUT, OUTPUT, CONNECTION, LOST)
|
||||
INPUT: The function is called when there is at least a byte in the
|
||||
input buffer
|
||||
OUTPUT: The function is called when the system is sure the next write call
|
||||
will not block
|
||||
CONNECTION: Two cases is possible:
|
||||
Client socket -> the connection is established
|
||||
Server socket -> a client request a connection
|
||||
LOST: the connection is lost
|
||||
|
||||
SetFallback accepts a combination of these flags so a same callback can
|
||||
receive different events.
|
||||
|
||||
An event is generated only once and its state is reseted when the relative
|
||||
IO call is requested.
|
||||
For example: INPUT -> GSocket_Read()
|
||||
CONNECTION -> GSocket_Accept()
|
||||
*/
|
||||
void GSocket_SetFallback(GSocket *socket, GSocketEventFlags event,
|
||||
GSocketFallback fallback, char *cdata);
|
||||
|
||||
/*
|
||||
UnsetFallback will disables all fallbacks specified by "event".
|
||||
NOTE: event may be a combination of flags
|
||||
*/
|
||||
void GSocket_UnsetFallback(GSocket *socket, GSocketEventFlags event);
|
||||
|
||||
/* GAddress */
|
||||
|
||||
GAddress *GAddress_new();
|
||||
GAddress *GAddress_copy(GAddress *address);
|
||||
void GAddress_destroy(GAddress *address);
|
||||
|
||||
void GAddress_SetFamily(GAddress *address, GAddressType type);
|
||||
GAddressType GAddress_GetFamily(GAddress *address);
|
||||
|
||||
/*
|
||||
The use of any of the next functions will set the address family to the adapted
|
||||
one. For example if you use GAddress_INET_SetHostName, address family will be AF_INET
|
||||
implicitely
|
||||
*/
|
||||
|
||||
GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
|
||||
GSocketError GAddress_INET_SetHostAddress(GAddress *address,
|
||||
unsigned long hostaddr);
|
||||
GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port);
|
||||
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);
|
||||
|
||||
/*
|
||||
* System specific functions
|
||||
*/
|
||||
|
||||
/* On systems needing an event id */
|
||||
void GSocket_SetEventID(GSocket *socket, unsigned long evt_id);
|
||||
|
||||
/* On systems which don't have background refresh */
|
||||
void GSocket_DoEvent(unsigned long evt_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/* __GSOCKET_H */
|
@@ -45,6 +45,8 @@ class wxMemoryOutputStream: public wxOutputStream {
|
||||
|
||||
wxStreamBuffer *OutputStreamBuffer() const { return m_o_streambuf; }
|
||||
|
||||
size_t CopyTo(char *buffer, size_t len) const;
|
||||
|
||||
protected:
|
||||
wxStreamBuffer *m_o_streambuf;
|
||||
|
||||
|
@@ -20,52 +20,42 @@
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#if defined(__WINDOWS__) && defined(WXSOCK_INTERNAL)
|
||||
#include <winsock.h>
|
||||
|
||||
#elif defined(__UNIX__) && defined(WXSOCK_INTERNAL)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "wx/string.h"
|
||||
#include "gsocket.h"
|
||||
|
||||
|
||||
class WXDLLEXPORT wxSockAddress : public wxObject {
|
||||
DECLARE_ABSTRACT_CLASS(wxSockAddress)
|
||||
public:
|
||||
typedef enum { IPV4=1, IPV6=2, UNIX=3 } Addr;
|
||||
|
||||
wxSockAddress() {};
|
||||
virtual ~wxSockAddress() {};
|
||||
wxSockAddress();
|
||||
virtual ~wxSockAddress();
|
||||
|
||||
virtual void Clear() = 0;
|
||||
|
||||
virtual void Build(struct sockaddr*& addr, size_t& len) = 0;
|
||||
virtual void Disassemble(struct sockaddr *addr, size_t len) = 0;
|
||||
virtual int SockAddrLen() = 0;
|
||||
|
||||
virtual int GetFamily() = 0;
|
||||
virtual void Clear();
|
||||
virtual int Type() = 0;
|
||||
|
||||
GAddress *GetAddress() const { return m_address; }
|
||||
void SetAddress(GAddress *address);
|
||||
const wxSockAddress& operator =(const wxSockAddress& addr);
|
||||
|
||||
void CopyObject(wxObject& dest) const;
|
||||
|
||||
protected:
|
||||
GAddress *m_address;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxIPV4address : public wxSockAddress {
|
||||
DECLARE_DYNAMIC_CLASS(wxIPV4address)
|
||||
private:
|
||||
struct sockaddr_in *m_addr;
|
||||
public:
|
||||
wxIPV4address();
|
||||
virtual ~wxIPV4address();
|
||||
|
||||
virtual void Clear();
|
||||
// const wxSockAddress& operator =(const wxSockAddress& addr);
|
||||
|
||||
virtual bool Hostname(const wxString& name);
|
||||
virtual bool Hostname(unsigned long addr);
|
||||
virtual bool Service(const wxString& name);
|
||||
virtual bool Service(unsigned short port);
|
||||
virtual bool LocalHost();
|
||||
bool Hostname(const wxString& name);
|
||||
bool Hostname(unsigned long addr);
|
||||
bool Service(const wxString& name);
|
||||
bool Service(unsigned short port);
|
||||
bool LocalHost();
|
||||
|
||||
wxString Hostname();
|
||||
unsigned short Service();
|
||||
@@ -73,8 +63,6 @@ public:
|
||||
void Build(struct sockaddr*& addr, size_t& len);
|
||||
void Disassemble(struct sockaddr *addr, size_t len);
|
||||
|
||||
inline int SockAddrLen();
|
||||
inline int GetFamily();
|
||||
inline int Type() { return wxSockAddress::IPV4; }
|
||||
};
|
||||
|
||||
@@ -87,9 +75,6 @@ public:
|
||||
wxIPV6address();
|
||||
~wxIPV6address();
|
||||
|
||||
void Clear();
|
||||
// const wxSockAddress& operator =(const wxSockAddress& addr);
|
||||
|
||||
bool Hostname(const wxString& name);
|
||||
bool Hostname(unsigned char addr[16]);
|
||||
bool Service(const wxString& name);
|
||||
@@ -99,11 +84,6 @@ public:
|
||||
wxString Hostname() const;
|
||||
unsigned short Service() const;
|
||||
|
||||
void Build(struct sockaddr*& addr, size_t& len);
|
||||
void Disassemble(struct sockaddr *addr, size_t len);
|
||||
|
||||
inline int SockAddrLen();
|
||||
inline int GetFamily();
|
||||
inline int Type() { return wxSockAddress::IPV6; }
|
||||
};
|
||||
#endif
|
||||
@@ -119,17 +99,9 @@ public:
|
||||
wxUNIXaddress();
|
||||
~wxUNIXaddress();
|
||||
|
||||
void Clear();
|
||||
// const wxSockAddress& operator =(const wxSockAddress& addr);
|
||||
|
||||
void Filename(const wxString& name);
|
||||
wxString Filename();
|
||||
|
||||
void Build(struct sockaddr*& addr, size_t& len);
|
||||
void Disassemble(struct sockaddr *addr, size_t len);
|
||||
|
||||
inline int SockAddrLen();
|
||||
inline int GetFamily();
|
||||
inline int Type() { return wxSockAddress::UNIX; }
|
||||
};
|
||||
#endif
|
||||
|
@@ -1,158 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sckint.h
|
||||
// Purpose: Socket internal classes
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: April 1999
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Guilhem Lavaux
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _WX_NETWORK_SOCKET_INT_H
|
||||
#define _WX_NETWORK_SOCKET_INT_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include "wx/object.h"
|
||||
#include "wx/list.h"
|
||||
#include "wx/socket.h"
|
||||
#include "wx/thread.h"
|
||||
|
||||
// Socket state
|
||||
class SocketState
|
||||
{
|
||||
public:
|
||||
// TRUE if the background notifyier is on.
|
||||
bool notify_state;
|
||||
// Specifies which events we want to be notified.
|
||||
wxSocketBase::wxRequestNotify evt_notify_state;
|
||||
// Socket flags.
|
||||
wxSocketBase::wxSockFlags socket_flags;
|
||||
// Pointer to the C callback function.
|
||||
wxSocketBase::wxSockCbk c_callback;
|
||||
char *c_callback_data;
|
||||
};
|
||||
|
||||
// Socket request
|
||||
class SockRequest
|
||||
{
|
||||
public:
|
||||
// Buffer where to get/put data.
|
||||
char *buffer;
|
||||
// Size of the buffer.
|
||||
size_t size;
|
||||
// Number of bytes really read/written.
|
||||
size_t io_nbytes;
|
||||
// Error.
|
||||
unsigned int error;
|
||||
// Type of the request.
|
||||
wxSocketBase::wxRequestNotify type;
|
||||
// Timeout (in milliseconds).
|
||||
unsigned int timeout;
|
||||
// TRUE if the buffer has been processed.
|
||||
bool done;
|
||||
// TRUE if we must wait for the request completion, in the other case an
|
||||
// event will be sent to the main thread when the request is finished.
|
||||
bool wait;
|
||||
};
|
||||
|
||||
class wxSocketInternal;
|
||||
|
||||
#if wxUSE_THREADS
|
||||
class SocketWaiter: public wxThread {
|
||||
public:
|
||||
SocketWaiter(wxSocketBase *socket, wxSocketInternal *internal);
|
||||
~SocketWaiter();
|
||||
|
||||
// Thread Entry point
|
||||
// ---
|
||||
virtual void *Entry();
|
||||
|
||||
protected:
|
||||
void ProcessReadEvent();
|
||||
void ProcessWriteEvent();
|
||||
|
||||
public:
|
||||
wxSocketBase *m_socket;
|
||||
wxSocketInternal *m_internal;
|
||||
int m_fd;
|
||||
};
|
||||
#endif
|
||||
|
||||
class SocketRequester
|
||||
#if wxUSE_THREADS
|
||||
: public wxThread
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
SocketRequester(wxSocketBase *socket, wxSocketInternal *internal);
|
||||
~SocketRequester();
|
||||
|
||||
void ProcessWaitEvent(SockRequest *req);
|
||||
void ProcessReadEvent(SockRequest *req);
|
||||
void ProcessWriteEvent(SockRequest *req);
|
||||
|
||||
bool WaitFor(wxSocketBase::wxRequestNotify req, int millisec);
|
||||
|
||||
#if wxUSE_THREADS
|
||||
// Thread Entry point
|
||||
// ---
|
||||
virtual void *Entry();
|
||||
#endif
|
||||
|
||||
public:
|
||||
wxSocketBase *m_socket;
|
||||
wxSocketInternal *m_internal;
|
||||
int m_fd;
|
||||
};
|
||||
|
||||
class wxSocketInternal {
|
||||
public:
|
||||
wxSocketInternal(wxSocketBase *socket);
|
||||
~wxSocketInternal();
|
||||
|
||||
// wxSocket thread manager
|
||||
// -----------------------
|
||||
void AcquireData();
|
||||
void ReleaseData();
|
||||
void AcquireFD();
|
||||
void ReleaseFD();
|
||||
|
||||
int GetFD() { return m_fd; }
|
||||
void SetFD(int fd) { m_fd = fd; }
|
||||
|
||||
void ResumeWaiter();
|
||||
void StopWaiter();
|
||||
void ResumeRequester();
|
||||
void StopRequester();
|
||||
|
||||
void QueueRequest(SockRequest *request, bool async);
|
||||
void WaitForEnd(SockRequest *request);
|
||||
|
||||
// Used by SocketRequester
|
||||
SockRequest *WaitForReq();
|
||||
void EndRequest(SockRequest *req);
|
||||
public:
|
||||
wxSocketBase *m_socket;
|
||||
#if wxUSE_THREADS
|
||||
wxMutex m_socket_locker, m_fd_locker, m_request_locker, m_end_requester;
|
||||
wxCondition m_socket_cond;
|
||||
SocketWaiter *m_thread_waiter;
|
||||
#endif
|
||||
SocketRequester *m_thread_requester;
|
||||
wxList m_requests;
|
||||
int m_fd;
|
||||
bool m_invalid_requester;
|
||||
};
|
||||
|
||||
#endif
|
||||
// wxUSE_SOCKETS
|
||||
|
||||
#endif
|
||||
// _WX_NETWORK_SOCKET_INT_H
|
@@ -63,9 +63,9 @@ protected:
|
||||
friend class wxTCPServer;
|
||||
friend class wxTCPClient;
|
||||
friend void Client_OnRequest(wxSocketBase&,
|
||||
wxSocketBase::wxRequestEvent, char *);
|
||||
GSocketEvent, char *);
|
||||
friend void Server_OnRequest(wxSocketServer&,
|
||||
wxSocketBase::wxRequestEvent, char *);
|
||||
GSocketEvent, char *);
|
||||
public:
|
||||
|
||||
wxTCPConnection(char *buffer, int size);
|
||||
|
@@ -27,7 +27,6 @@ class WXDLLEXPORT wxSocketOutputStream : public wxOutputStream
|
||||
wxSocketOutputStream(wxSocketBase& s);
|
||||
~wxSocketOutputStream();
|
||||
|
||||
wxOutputStream& Write(const void *buffer, size_t size);
|
||||
off_t SeekO( off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode) )
|
||||
{ return -1; }
|
||||
off_t TellO()
|
||||
@@ -45,7 +44,6 @@ class WXDLLEXPORT wxSocketInputStream : public wxInputStream
|
||||
wxSocketInputStream(wxSocketBase& s);
|
||||
~wxSocketInputStream();
|
||||
|
||||
wxInputStream& Read(void *buffer, size_t size);
|
||||
off_t SeekI( off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode) )
|
||||
{ return -1; }
|
||||
off_t TellI()
|
||||
@@ -69,4 +67,4 @@ class WXDLLEXPORT wxSocketStream : public wxSocketInputStream,
|
||||
// wxUSE_SOCKETS && wxUSE_STREAMS
|
||||
|
||||
#endif
|
||||
// __SCK_STREAM_H__
|
||||
// __SCK_STREAM_H__
|
||||
|
@@ -20,23 +20,6 @@
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Windows(tm) specific
|
||||
// ---------------------------------------------------------------------------
|
||||
#if defined(__WINDOWS__) && defined(WXSOCK_INTERNAL)
|
||||
#include <winsock.h>
|
||||
#include <wx/msw/private.h>
|
||||
#endif // defined(__WINDOWS__) && defined(WXSOCK_INTERNAL)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Unix specific
|
||||
// ---------------------------------------------------------------------------
|
||||
#if defined(__UNIX__) && defined(WXSOCK_INTERNAL)
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif // defined(__UNIX__) && defined(WXSOCK_INTERNAL)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxSocket headers (generic)
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -48,48 +31,46 @@
|
||||
#endif
|
||||
|
||||
#include "wx/sckaddr.h"
|
||||
#include "gsocket.h"
|
||||
|
||||
class WXDLLEXPORT wxSocketEvent;
|
||||
class WXDLLEXPORT wxSocketHandler;
|
||||
class wxSocketInternal;
|
||||
class WXDLLEXPORT wxSocketBase : public wxEvtHandler
|
||||
{
|
||||
DECLARE_CLASS(wxSocketBase)
|
||||
#ifdef __WXMAC__
|
||||
friend void wxMacSocketOnRequestProc(void *refcon , short event) ;
|
||||
#endif
|
||||
public:
|
||||
|
||||
enum wxSockFlags { NONE=0, NOWAIT=1, WAITALL=2, SPEED=4 };
|
||||
// Type of request
|
||||
enum { REQ_READ=0x1, REQ_PEEK=0x2, REQ_WRITE=0x4, REQ_LOST=0x8,
|
||||
REQ_ACCEPT=0x10, REQ_CONNECT=0x20, REQ_WAIT=0x40};
|
||||
enum { EVT_READ=0, EVT_PEEK=1, EVT_WRITE=2, EVT_LOST=3, EVT_ACCEPT=4,
|
||||
EVT_CONNECT=5 };
|
||||
|
||||
typedef int wxRequestNotify;
|
||||
typedef int wxRequestEvent;
|
||||
enum wxSockType { SOCK_CLIENT, SOCK_SERVER, SOCK_INTERNAL, SOCK_UNINIT };
|
||||
typedef void (*wxSockCbk)(wxSocketBase& sock,wxRequestEvent evt,char *cdata);
|
||||
typedef void (*wxSockCbk)(wxSocketBase& sock,GSocketEvent evt,char *cdata);
|
||||
|
||||
protected:
|
||||
wxSockFlags m_flags;
|
||||
GSocket *m_socket; // wxSocket socket
|
||||
wxSockFlags m_flags; // wxSocket flags
|
||||
wxSockType m_type; // wxSocket type
|
||||
bool m_connected, m_connecting; // State of the socket
|
||||
int m_fd; // Socket file descriptors
|
||||
wxList m_states; // States list
|
||||
int m_id; // Socket id (for event handler)
|
||||
wxSocketHandler *m_handler; // the current socket handler
|
||||
wxRequestNotify m_neededreq; // Specify which requet signals we need
|
||||
unsigned long m_timeout;
|
||||
GSocketEventFlags m_neededreq; // Specify which requet signals we need
|
||||
size_t m_lcount; // Last IO request size
|
||||
int m_error; // Last IO error
|
||||
wxSocketInternal *m_internal;
|
||||
unsigned long m_timeout; // IO timeout value
|
||||
|
||||
char *m_unread; // Pushback buffer
|
||||
size_t m_unrd_size; // Pushback buffer size
|
||||
wxSockCbk m_cbk;
|
||||
char *m_cdata;
|
||||
bool m_notify_state;
|
||||
size_t m_unrd_cur; // Pushback pointer
|
||||
|
||||
wxSockCbk m_cbk; // C callback
|
||||
char *m_cdata; // C callback data
|
||||
|
||||
bool m_connected; // Connected ?
|
||||
bool m_notify_state; // Notify state
|
||||
int m_id; // Socket id (for event handler)
|
||||
|
||||
enum {
|
||||
DEFER_READ, DEFER_WRITE, NO_DEFER
|
||||
} m_defering; // Defering state
|
||||
char *m_defer_buffer; // Defering target buffer
|
||||
size_t m_defer_nbytes; // Defering buffer size
|
||||
|
||||
wxList m_states; // Stack of states
|
||||
|
||||
public:
|
||||
wxSocketBase();
|
||||
@@ -110,14 +91,15 @@ public:
|
||||
void CreatePushbackBefore(const char *buffer, size_t size);
|
||||
|
||||
// Status
|
||||
inline bool Ok() const { return (m_fd < 0 ? 0 : 1); };
|
||||
inline bool Error() const { return (m_error != 0); };
|
||||
inline bool Ok() const { return (m_socket != NULL); };
|
||||
inline bool Error() const
|
||||
{ return (GSocket_GetError(m_socket) != GSOCK_NOERROR); };
|
||||
inline bool IsConnected() const { return m_connected; };
|
||||
inline bool IsDisconnected() const { return !IsConnected(); };
|
||||
inline bool IsNoWait() const { return m_flags & NOWAIT; };
|
||||
inline bool IsNoWait() const { return ((m_flags & NOWAIT) != 0); };
|
||||
bool IsData() const;
|
||||
inline size_t LastCount() const { return m_lcount; }
|
||||
inline int LastError() const { return m_error; }
|
||||
inline GSocketError LastError() const { return GSocket_GetError(m_socket); }
|
||||
inline wxSockType GetType() const { return m_type; }
|
||||
|
||||
void SetFlags(wxSockFlags _flags);
|
||||
@@ -144,11 +126,11 @@ public:
|
||||
void SetEventHandler(wxEvtHandler& evt_hdlr, int id = -1);
|
||||
|
||||
// Method called when it happens something on the socket
|
||||
void SetNotify(wxRequestNotify flags);
|
||||
virtual void OnRequest(wxRequestEvent req_evt);
|
||||
void SetNotify(GSocketEventFlags flags);
|
||||
virtual void OnRequest(GSocketEvent req_evt);
|
||||
|
||||
// Public internal callback
|
||||
virtual void OldOnNotify(wxRequestEvent WXUNUSED(evt));
|
||||
virtual void OldOnNotify(GSocketEvent WXUNUSED(evt));
|
||||
|
||||
// Some info on the socket...
|
||||
virtual bool GetPeer(wxSockAddress& addr_man) const;
|
||||
@@ -158,9 +140,9 @@ public:
|
||||
void Notify(bool notify);
|
||||
|
||||
// So you can know what the socket driver is looking for ...
|
||||
inline wxRequestNotify NeededReq() const { return m_neededreq; }
|
||||
inline GSocketEventFlags NeededReq() const { return m_neededreq; }
|
||||
|
||||
static wxRequestNotify EventToNotify(wxRequestEvent evt);
|
||||
static GSocketEventFlags EventToNotify(GSocketEvent evt);
|
||||
|
||||
protected:
|
||||
friend class wxSocketServer;
|
||||
@@ -178,18 +160,13 @@ protected:
|
||||
#endif
|
||||
|
||||
bool _Wait(long seconds, long microseconds, int type);
|
||||
|
||||
// Set "my" handler
|
||||
inline virtual void SetHandler(wxSocketHandler *handler)
|
||||
{ m_handler = handler; }
|
||||
|
||||
int DeferRead(char *buffer, size_t nbytes);
|
||||
int DeferWrite(const char *buffer, size_t nbytes);
|
||||
void DoDefer(GSocketEvent evt);
|
||||
|
||||
// Pushback library
|
||||
size_t GetPushback(char *buffer, size_t size, bool peek);
|
||||
|
||||
// To prevent many read or write on the same socket at the same time
|
||||
// ==> cause strange things :-)
|
||||
void WantSpeedBuffer(char *buffer, size_t size, wxRequestEvent req);
|
||||
void WantBuffer(char *buffer, size_t size, wxRequestEvent req);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
@@ -221,45 +198,7 @@ public:
|
||||
|
||||
bool WaitOnConnect(long seconds = -1, long microseconds = 0);
|
||||
|
||||
virtual void OnRequest(wxRequestEvent flags);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class WXDLLEXPORT wxSocketHandler : public wxObject
|
||||
{
|
||||
DECLARE_CLASS(wxSocketHandler)
|
||||
protected:
|
||||
wxList *socks;
|
||||
|
||||
public:
|
||||
enum SockStatus { SOCK_NONE, SOCK_DATA, SOCK_CONNECT, SOCK_DISCONNECT,
|
||||
SOCK_ERROR };
|
||||
static wxSocketHandler *master;
|
||||
|
||||
wxSocketHandler();
|
||||
virtual ~wxSocketHandler();
|
||||
|
||||
void Register(wxSocketBase* sock);
|
||||
void UnRegister(wxSocketBase* sock);
|
||||
|
||||
unsigned long Count() const;
|
||||
|
||||
// seconds = -1 means indefinite wait
|
||||
// seconds = 0 means no wait
|
||||
// seconds > 0 means specified wait
|
||||
|
||||
int Wait(long seconds = -1, long microseconds = 0);
|
||||
void YieldSock();
|
||||
|
||||
wxSocketServer *CreateServer
|
||||
(wxSockAddress& addr,
|
||||
wxSocketBase::wxSockFlags flags = wxSocketBase::NONE);
|
||||
wxSocketClient *CreateClient
|
||||
(wxSocketBase::wxSockFlags flags = wxSocketBase::NONE);
|
||||
|
||||
// Create or reuse a socket handler
|
||||
static wxSocketHandler& Master() { return *master; }
|
||||
virtual void OnRequest(GSocketEvent flags);
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxSocketEvent : public wxEvent {
|
||||
@@ -267,13 +206,13 @@ class WXDLLEXPORT wxSocketEvent : public wxEvent {
|
||||
public:
|
||||
wxSocketEvent(int id = 0);
|
||||
|
||||
wxSocketBase::wxRequestEvent SocketEvent() const { return m_skevt; }
|
||||
GSocketEvent SocketEvent() const { return m_skevt; }
|
||||
wxSocketBase *Socket() const { return m_socket; }
|
||||
|
||||
void CopyObject(wxObject& obj_d) const;
|
||||
|
||||
public:
|
||||
wxSocketBase::wxRequestEvent m_skevt;
|
||||
GSocketEvent m_skevt;
|
||||
wxSocketBase *m_socket;
|
||||
};
|
||||
|
||||
|
@@ -145,7 +145,7 @@ public:
|
||||
wxTextCtrl& operator<<(long i);
|
||||
wxTextCtrl& operator<<(float f);
|
||||
wxTextCtrl& operator<<(double d);
|
||||
wxTextCtrl& operator<<(const char c);
|
||||
wxTextCtrl& operator<<(const wxChar c);
|
||||
|
||||
// obsolete functions
|
||||
#if WXWIN_COMPATIBILITY
|
||||
|
Reference in New Issue
Block a user