refactoring: replace wxSocketDispatcher with more generic wxSelectDispatcher (patch 1618976)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44855 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-03-16 15:45:12 +00:00
parent 7058b79442
commit 30c45bdd06
9 changed files with 590 additions and 77 deletions

View File

@@ -0,0 +1,42 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/private/gsocketiohandler.h
// Purpose: class for registering GSocket in wxSelectDispatcher
// Authors: Lukasz Michalski
// Modified by:
// Created: December 2006
// Copyright: (c) Lukasz Michalski
// RCS-ID: $Id$
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_GSOCKETIOHANDLER_H_
#define _WX_PRIVATE_GSOCKETIOHANDLER_H_
#include "wx/defs.h"
#include "wx/private/selectdispatcher.h"
#if wxUSE_SOCKETS
// forward declarations
class GSocket;
class WXDLLIMPEXP_CORE wxGSocketIOHandler : public wxFDIOHandler
{
public:
wxGSocketIOHandler(GSocket* socket);
int GetFlags() const;
void RemoveFlag(wxSelectDispatcherEntryFlags flag);
void AddFlag(wxSelectDispatcherEntryFlags flag);
private:
virtual void OnReadWaiting(int fd);
virtual void OnWriteWaiting(int fd);
virtual void OnExceptionWaiting(int fd);
GSocket* m_socket;
int m_flags;
};
#endif // wxUSE_SOCKETS
#endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_

View File

@@ -0,0 +1,93 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/private/selectdispatcher.h
// Purpose: wxSelectDispatcher class
// Authors: Lukasz Michalski
// Modified by:
// Created: December 2006
// Copyright: (c) Lukasz Michalski
// RCS-ID: $Id$
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_SELECTDISPATCHER_H_
#define _WX_PRIVATE_SELECTDISPATCHER_H_
#include "wx/defs.h"
#include "wx/hashmap.h"
static const int wxSELECT_TIMEOUT_INFINITE = -1;
// handler used to process events on descriptors
class wxFDIOHandler
{
public:
// called when descriptor is available for non-blocking read
virtual void OnReadWaiting(int fd) = 0;
// called when descriptor is available for non-blocking write
virtual void OnWriteWaiting(int fd) = 0;
// called when there is exception on descriptor
virtual void OnExceptionWaiting(int fd) = 0;
};
// those flags describes sets where descriptor should be added
enum wxSelectDispatcherEntryFlags
{
wxSelectInput = 1,
wxSelectOutput = 2,
wxSelectException = 4,
wxSelectAll = wxSelectInput | wxSelectOutput | wxSelectException
};
WX_DECLARE_HASH_MAP(
int,
wxFDIOHandler*,
wxIntegerHash,
wxIntegerEqual,
wxFDIOHandlerMap
);
class WXDLLIMPEXP_CORE wxSelectDispatcher
{
public:
// returns instance of the table
static wxSelectDispatcher& Get();
virtual ~wxSelectDispatcher()
{
}
// register descriptor in sets.
void RegisterFD(int fd, wxFDIOHandler* handler, int flags = wxSelectAll);
// unregister descriptor from sets and return handler for cleanup
wxFDIOHandler* UnregisterFD(int fd, int flags = wxSelectAll);
// return handler for descriptor or null if fd is not registered
wxFDIOHandler* FindHandler(int fd);
// calls select on registered descriptors and
void RunLoop(int timeout = wxSELECT_TIMEOUT_INFINITE);
protected:
wxSelectDispatcher() { }
private:
void ProcessSets(fd_set* readset, fd_set* writeset, fd_set* exeptset, int max_fd);
fd_set m_readset;
fd_set m_writeset;
fd_set m_exeptset;
int m_maxFD;
wxFDIOHandlerMap m_handlers;
static wxSelectDispatcher *ms_instance;
friend class wxSelectDispatcherModule;
};
#endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_

View File

@@ -1,71 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/private/socketevtdispatch.h
// Purpose: wxSocketEventDispatcher class
// Authors: Angel Vidal
// Modified by:
// Created: August 2006
// Copyright: (c) Angel Vidal
// RCS-ID: $Id$
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_SOCKETEVTDISPATCH_H_
#define _WX_PRIVATE_SOCKETEVTDISPATCH_H_
#include "wx/defs.h"
#if wxUSE_SOCKETS
#ifdef __VMS
#include <sys/socket.h>
#endif
#include "wx/hash.h"
// forward declarations
class wxSocketEventDispatcherEntry;
class GSocket;
enum wxSocketEventDispatcherType
{
wxSocketEventDispatcherInput,
wxSocketEventDispatcherOutput
};
class WXDLLIMPEXP_CORE wxSocketEventDispatcher : public wxHashTable
{
protected:
wxSocketEventDispatcher() : wxHashTable(wxKEY_INTEGER) {}
public:
// returns instance of the table
static wxSocketEventDispatcher& Get();
virtual ~wxSocketEventDispatcher()
{
WX_CLEAR_HASH_TABLE(*this)
}
void RegisterCallback(int fd, wxSocketEventDispatcherType socketType,
GSocket* socket);
void UnregisterCallback(int fd, wxSocketEventDispatcherType socketType);
void RunLoop(int timeout = 0);
private:
void AddEvents(fd_set* readset, fd_set* writeset);
int FillSets(fd_set* readset, fd_set* writeset);
wxSocketEventDispatcherEntry* FindEntry(int fd);
private:
static wxSocketEventDispatcher *ms_instance;
friend class wxSocketEventDispatcherModule;
};
#endif // wxUSE_SOCKETS
#endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_