asycxx-devel Mailing List for Asynchronous C++ Application framework (Page 2)
Status: Alpha
Brought to you by:
joe_steeve
You can subscribe to this list here.
| 2009 |
Jan
|
Feb
(16) |
Mar
(27) |
Apr
(44) |
May
(3) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|---|
|
From: <joe...@us...> - 2009-04-08 07:44:43
|
Revision: 44
http://asycxx.svn.sourceforge.net/asycxx/?rev=44&view=rev
Author: joe_steeve
Date: 2009-04-08 07:44:37 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
use ASYCXX_ prefix instead of HMI_CTRL_ prefix
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/src/asycxx-common.h
Modified: trunk/src/asycxx-common.h
===================================================================
--- trunk/src/asycxx-common.h 2009-04-08 07:43:45 UTC (rev 43)
+++ trunk/src/asycxx-common.h 2009-04-08 07:44:37 UTC (rev 44)
@@ -62,7 +62,7 @@
} \
}
-h_msecs_t GetCurrentTimeStamp (void);
+asycxx_msecs_t GetCurrentTimeStamp (void);
void SetFDAsNonBlocking (int fd);
#define HMI_CTRL_MAX_URL_LEN 512
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:43:46
|
Revision: 43
http://asycxx.svn.sourceforge.net/asycxx/?rev=43&view=rev
Author: joe_steeve
Date: 2009-04-08 07:43:45 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
refactored the enum Result as asycxx::RetCode
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/_asycxx.h
Modified: trunk/include/asycxx/_asycxx.h
===================================================================
--- trunk/include/asycxx/_asycxx.h 2009-04-08 07:43:06 UTC (rev 42)
+++ trunk/include/asycxx/_asycxx.h 2009-04-08 07:43:45 UTC (rev 43)
@@ -14,18 +14,23 @@
#ifndef __HIPRO_ASYCXX___ASYCXX_H__
#define __HIPRO_ASYCXX___ASYCXX_H__
-enum Result
- {
- Result_Success = 0,
- Result_Error,
- Result_Pending,
- Result_NotFound,
- };
+namespace asycxx
+{
+ /* Common return codes used through out asycxx */
+ enum RetCode
+ {
+ RetCode_Success = 0,
+ RetCode_Error,
+ RetCode_NotFound,
+ RetCode_Pending,
+ };
+}
typedef unsigned char u8_t;
-typedef long long h_msecs_t;
-typedef long long h_timestamp_t;
+typedef long long asycxx_msecs_t;
+typedef long long asycxx_timestamp_t;
+
#endif /* __HIPRO_ASYCXX___ASYCXX_H__ */
/*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:43:07
|
Revision: 42
http://asycxx.svn.sourceforge.net/asycxx/?rev=42&view=rev
Author: joe_steeve
Date: 2009-04-08 07:43:06 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
updated GimpleMsgBus to accomodate changes in rest of asycxx
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/GimpleMsgBus.h
trunk/src/GimpleMsgBus.cxx
Modified: trunk/include/asycxx/GimpleMsgBus.h
===================================================================
--- trunk/include/asycxx/GimpleMsgBus.h 2009-04-08 07:42:19 UTC (rev 41)
+++ trunk/include/asycxx/GimpleMsgBus.h 2009-04-08 07:43:06 UTC (rev 42)
@@ -20,7 +20,8 @@
#include "Error.h"
#include "Reactor.h"
-#include "Protocol.h"
+#include "StreamProtocol.h"
+#include "StreamTransport.h"
#include "MsgBus.h"
/**
@@ -36,51 +37,54 @@
* the Transport.
*/
-class GimpleMsgBus : public Protocol, public MsgBus
+namespace asycxx
{
+ class GimpleMsgBus : public StreamProtocol, public MsgBus
+ {
-public:
- GimpleMsgBus (Reactor *reactor, Factory *factory, Transport *transport,
- MsgHandler *handler);
- ~GimpleMsgBus ();
+ public:
+ GimpleMsgBus (Reactor *reactor, StreamProtocolFactory *factory,
+ StreamTransport *transport, MsgHandler *handler);
+ ~GimpleMsgBus ();
- void DataAvailable (DataBuffer *data);
- void ReadError (void);
- void WriteError (void);
- void ReadTimeout (h_msecs_t excess_time);
- void WriteTimeout (h_msecs_t excess_time);
- void SendMsg (DataBuffer *msg);
+ void DataAvailable (DataBuffer *data);
+ void ReadError (void);
+ void WriteError (void);
+ void ReadTimeout (asycxx_msecs_t excess_time);
+ void WriteTimeout (asycxx_msecs_t excess_time);
+ void SendMsg (DataBuffer *msg);
-protected:
- Result InitProtocol (void);
+ protected:
+ RetCode InitProtocol (void);
-private:
- struct GMBPacketHdr_s
- {
- char signature [4]; /* should contain "GMB\0" */
- uint32_t len; /* length of the xml-packet in
- network-byte-order. */
- } __attribute__ ((packed));
-
- enum GMBState
+ private:
+ struct GMBPacketHdr_s
{
- GMB_WaitingForNewMsg = 0,
- GMB_MsgHarvestInProgress
- };
- GMBState m_State;
+ char signature [4]; /* should contain "GMB\0" */
+ uint32_t len; /* length of the xml-packet in
+ network-byte-order. */
+ } __attribute__ ((packed));
- GMBPacketHdr_s m_Hdr;
- size_t m_Hdr_filled;
- size_t m_Hdr_left;
+ enum GMBState
+ {
+ GMB_WaitingForNewMsg = 0,
+ GMB_MsgHarvestInProgress
+ };
+ GMBState m_State;
- DataBuffer *m_Payload;
- size_t m_Payload_filled;
- size_t m_Payload_left;
+ GMBPacketHdr_s m_Hdr;
+ size_t m_Hdr_filled;
+ size_t m_Hdr_left;
- Result ReadHeader (void *data_ptr, size_t len, size_t& processed);
- Result ReadPayload (void *data_ptr, size_t len, size_t& processed);
-};
+ DataBuffer *m_Payload;
+ size_t m_Payload_filled;
+ size_t m_Payload_left;
+ RetCode ReadHeader (void *data_ptr, size_t len, size_t& processed);
+ RetCode ReadPayload (void *data_ptr, size_t len, size_t& processed);
+ };
+}
+
#endif /* __HIPRO_ASYCXX__GIMPLE_MSG_BUS_H__ */
/*
Modified: trunk/src/GimpleMsgBus.cxx
===================================================================
--- trunk/src/GimpleMsgBus.cxx 2009-04-08 07:42:19 UTC (rev 41)
+++ trunk/src/GimpleMsgBus.cxx 2009-04-08 07:43:06 UTC (rev 42)
@@ -21,14 +21,15 @@
#include "asycxx-common.h"
#include <asycxx/Error.h>
#include <asycxx/Transport.h>
-#include <asycxx/Factory.h>
+#include <asycxx/StreamProtocolFactory.h>
#include <asycxx/MsgHandler.h>
#include <asycxx/GimpleMsgBus.h>
+using namespace asycxx;
-GimpleMsgBus::GimpleMsgBus (Reactor *reactor, Factory *factory,
- Transport *transport, MsgHandler *handler) :
- Protocol (reactor, factory, transport),
+GimpleMsgBus::GimpleMsgBus (Reactor *reactor, StreamProtocolFactory *factory,
+ StreamTransport *transport, MsgHandler *handler) :
+ StreamProtocol (reactor, factory, transport),
MsgBus (handler)
{
ctorLOG ("GimpleMsgBus");
@@ -58,17 +59,17 @@
}
-Result
+RetCode
GimpleMsgBus::InitProtocol (void)
{
- return Result_Success;
+ return RetCode_Success;
}
void
GimpleMsgBus::DataAvailable (DataBuffer *data)
{
- Result ret;
+ RetCode ret;
void *data_ptr;
size_t dleft, processed;
dleft = data->Len();
@@ -84,9 +85,9 @@
{
case GMB_WaitingForNewMsg:
ret = ReadHeader (data_ptr, dleft, processed);
- if (ret != Result_Success)
+ if (ret != RetCode_Success)
{
- m_Transport->LoseConnection ();
+ getTransport()->loseConnection ();
return;
}
data_ptr = (void *)((unsigned int)data->Data() + processed);
@@ -95,9 +96,9 @@
case GMB_MsgHarvestInProgress:
ret = ReadPayload (data_ptr, dleft, processed);
- if (ret != Result_Success)
+ if (ret != RetCode_Success)
{
- m_Transport->LoseConnection ();
+ getTransport()->loseConnection ();
return;
}
data_ptr = (void *)((unsigned int)data->Data() + processed);
@@ -110,7 +111,7 @@
}
-Result
+RetCode
GimpleMsgBus::ReadHeader (void *data_ptr, size_t len, size_t& processed)
{
ASSERT ((data_ptr != NULL), "bad data pointer");
@@ -149,7 +150,7 @@
{
processed = 0;
ERR ("bad signature");
- return Result_Error;
+ return RetCode_Error;
}
/* converting byte-order from network to host */
@@ -163,11 +164,11 @@
}
processed = to_copy;
- return Result_Success;
+ return RetCode_Success;
}
-Result
+RetCode
GimpleMsgBus::ReadPayload (void *data_ptr, size_t len, size_t& processed)
{
ASSERT ((data_ptr != NULL), "bad data pointer");
@@ -180,7 +181,7 @@
"m_Payload_left is going haywire. currently %u",
m_Payload_left);
- Result ret;
+ RetCode ret;
size_t to_copy;
void *dptr;
@@ -206,10 +207,10 @@
/* deliver message to the MessageHandler */
ret = m_Handler->GotMsg (m_Payload);
- if (ret != Result_Success)
+ if (ret != RetCode_Success)
{
ERR ("MsgHandler <%p> does not like data.");
- return Result_Error;
+ return RetCode_Error;
}
/* setup the next state */
@@ -219,7 +220,7 @@
}
processed = to_copy;
- return Result_Success;
+ return RetCode_Success;
}
@@ -248,7 +249,7 @@
/* send it to transport */
try
{
- m_Transport->Write (pkt);
+ getTransport()->Write (pkt);
}
catch (...)
{
@@ -272,13 +273,13 @@
}
void
-GimpleMsgBus::ReadTimeout (h_msecs_t excess_time)
+GimpleMsgBus::ReadTimeout (asycxx_msecs_t excess_time)
{
ERR ("data read timeout. excess = %lld", excess_time);
}
void
-GimpleMsgBus::WriteTimeout (h_msecs_t excess_time)
+GimpleMsgBus::WriteTimeout (asycxx_msecs_t excess_time)
{
ERR ("data write timeout. excess = %lld", excess_time);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:42:24
|
Revision: 41
http://asycxx.svn.sourceforge.net/asycxx/?rev=41&view=rev
Author: joe_steeve
Date: 2009-04-08 07:42:19 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
refactored class:TCPLLTransport
* changes to support changes in TCPTransport
* moved class:TCPLLTransport to 'asycxx' namespace
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/TCPLLTransport.h
trunk/src/TCPLLTransport.cxx
Modified: trunk/include/asycxx/TCPLLTransport.h
===================================================================
--- trunk/include/asycxx/TCPLLTransport.h 2009-04-08 07:41:32 UTC (rev 40)
+++ trunk/include/asycxx/TCPLLTransport.h 2009-04-08 07:42:19 UTC (rev 41)
@@ -18,17 +18,47 @@
#include "Reactor.h"
#include "TCPTransport.h"
-class TCPLLTransport : public TCPTransport
+namespace asycxx
{
-public:
- TCPLLTransport (Reactor *reactor, int fd);
- virtual ~TCPLLTransport ();
+ class TCPLLTransport : public TCPTransport
+ {
+ public:
+ TCPLLTransport (Reactor *reactor, int fd);
+ virtual ~TCPLLTransport () {}
+
+ /**
+ * \brief set the socket as TCP_NODELAY
+ *
+ * \details This method disables the Nagle algorithm on the connection
+ * by setting TCP_NODELAY.
+ */
+ void configureTCPLLNoDelay (void);
- void configureTCPLLNoDelay (void);
- void configureTCPLLKeepAlive (int idle_time, int probe_count,
- int probe_interval);
-};
+ /**
+ * \brief Configure the TCP keepalive mechanism
+ *
+ * \param[in] idle_time Idle time (time in which no data came
+ * across the wire) in seconds to wait for the keep-alive
+ * mechanism to kick in.
+ * \param[in] probe_count Number of keep-alive probes to send to
+ * the other end before deciding that the other-end is dead.
+ * \param[in] probe_interval The time in seconds between each
+ * keep-alive probe.
+ *
+ * \details This method configure's the TCP keepalive
+ * mechanism. This method is provided so that the user of this
+ * transport can tweak the keep-alive mechanism to see network
+ * errors faster. The maximum time taken before an error is
+ * noticed is
+ *
+ * idle_time + (probe_count * (probe_interval - 1))
+ */
+ void configureTCPLLKeepAlive (int idle_time, int probe_count,
+ int probe_interval);
+ };
+}
+
#endif /* __HIPRO_ASYCXX__TCP_LL_TRANSPORT_H__ */
/*
Modified: trunk/src/TCPLLTransport.cxx
===================================================================
--- trunk/src/TCPLLTransport.cxx 2009-04-08 07:41:32 UTC (rev 40)
+++ trunk/src/TCPLLTransport.cxx 2009-04-08 07:42:19 UTC (rev 41)
@@ -27,6 +27,7 @@
#include <asycxx/Protocol.h>
#include <asycxx/TCPLLTransport.h>
+using namespace asycxx;
TCPLLTransport::TCPLLTransport (Reactor *reactor, int fd)
: TCPTransport (reactor, fd)
@@ -36,51 +37,19 @@
}
-TCPLLTransport::~TCPLLTransport ()
-{
-}
-
-/**
- * \brief set the socket as TCP_NODELAY
- *
- * \details This method disables the Nagle algorithm on the connection
- * by setting TCP_NODELAY.
- */
+/* setup tcp-no-delay */
void
TCPLLTransport::configureTCPLLNoDelay (void)
{
- ASSERT ((m_Fd != -1), "sanity checks");
-
int iret;
int optval = 1;
- iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_NODELAY, (void *)&optval,
+ iret = setsockopt (Fd(), IPPROTO_TCP, TCP_NODELAY, (void *)&optval,
sizeof (optval));
- if (iret == -1)
- {
- THROW (RunTimeError, "setting up TCP_NODELAY on fd=%d failed with %s",
- m_Fd, strerror (errno));
- }
+ ASSERT ((iret == 0), "setting up TCP_NODELAY on fd=%d failed with %s",
+ Fd(), strerror (errno));
}
-
-/**
- * \brief Configure the TCP keepalive mechanism
- *
- * \param[in] idle_time Idle time (time in which no data came across
- * the wire) in seconds to wait for the keep-alive mechanism to kick
- * in.
- * \param[in] probe_count Number of keep-alive probes to send to the
- * other end before deciding that the other-end is dead.
- * \param[in] probe_interval The time in seconds between each
- * keep-alive probe.
- *
- * \details This method configure's the TCP keepalive mechanism. This
- * method is provided so that the user of this transport can tweak the
- * keep-alive mechanism to see network errors faster. The maximum time
- * taken before an error is noticed is
- *
- * idle_time + (probe_count * (probe_interval - 1))
- */
+/* enable tcp-keep-alive */
void
TCPLLTransport::configureTCPLLKeepAlive (int idle_time, int probe_count,
int probe_interval)
@@ -96,54 +65,30 @@
if (idle_time > 0)
{
optval = idle_time;
- iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_KEEPIDLE,
+ iret = setsockopt (Fd(), IPPROTO_TCP, TCP_KEEPIDLE,
(void *)&optval, sizeof (optval));
- if (iret == -1)
- {
- if (errno == EBADF)
- { THROW (BadFDError,
- "setting up TCP_KEEPIDLE(%d) on fd=%d threw '%s'",
- idle_time, m_Fd, strerror (errno)); }
- THROW (RunTimeError,
- "setting up TCP_KEEPIDLE(%d) on fd=%d threw '%s'",
- idle_time, m_Fd, strerror (errno));
- }
+ ASSERT ((iret == 0), "setting up TCP_KEEPIDLE(%d) on fd=%d threw '%s'",
+ idle_time, Fd(), strerror (errno));
}
/* setup TCP_KEEPCNT */
if (probe_count > 0)
{
optval = probe_count;
- iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_KEEPCNT,
+ iret = setsockopt (Fd(), IPPROTO_TCP, TCP_KEEPCNT,
(void *)&optval, sizeof (optval));
- if (iret == -1)
- {
- if (errno == EBADF)
- { THROW (BadFDError,
- "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'",
- probe_count, m_Fd, strerror (errno)); }
- THROW (RunTimeError,
- "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'",
- probe_count, m_Fd, strerror (errno));
- }
+ ASSERT ((iret == 0), "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'",
+ probe_count, Fd(), strerror (errno));
}
/* setup TCP_KEEPINTVL */
if (probe_interval > 0)
{
optval = probe_interval;
- iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_KEEPCNT,
+ iret = setsockopt (Fd(), IPPROTO_TCP, TCP_KEEPCNT,
(void *)&optval, sizeof (optval));
- if (iret == -1)
- {
- if (errno == EBADF)
- { THROW (BadFDError,
- "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'",
- probe_interval, m_Fd, strerror (errno)); }
- THROW (RunTimeError,
- "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'",
- probe_interval, m_Fd, strerror (errno));
- }
+ ASSERT ((iret == 0), "setting up TCP_KEEPCNT(%d) on fd=%d threw '%s'",
+ probe_interval, Fd(), strerror (errno));
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:41:33
|
Revision: 40
http://asycxx.svn.sourceforge.net/asycxx/?rev=40&view=rev
Author: joe_steeve
Date: 2009-04-08 07:41:32 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
refactored RefCounter.*
* moved class:RefCounter into 'asycxx' namespace
* moved most of the one-liner code from RefCounter.cxx to RefCounter.h
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/RefCounter.h
trunk/src/RefCounter.cxx
Modified: trunk/include/asycxx/RefCounter.h
===================================================================
--- trunk/include/asycxx/RefCounter.h 2009-04-08 07:40:45 UTC (rev 39)
+++ trunk/include/asycxx/RefCounter.h 2009-04-08 07:41:32 UTC (rev 40)
@@ -17,19 +17,36 @@
#include "Error.h"
-class RefCounter
+namespace asycxx
{
-public:
- RefCounter ();
+ class RefCounter
+ {
+ public:
+ /*
+ * CTOR:
+ */
+ RefCounter () { m_OwnerCount = 1; }
- void Own (void);
- void DisOwn (void);
+ void Own (void) { m_OwnerCount ++; }
+ void DisOwn (void)
+ {
+ m_OwnerCount --;
+ if (m_OwnerCount == 0)
+ {
+ delete this;
+ }
+ }
-protected:
- virtual ~RefCounter ();
- int m__OwnerCount;
-};
+ protected:
+ /* DTOR: A reference counted object may not be deleted
+ * directly. Hence we have the 'dtor' as protected.
+ */
+ virtual ~RefCounter ();
+ private:
+ int m_OwnerCount;
+ };
+}
#endif /* __HIPRO_ASYCXX__REF_COUNTER_H__ */
/*
Modified: trunk/src/RefCounter.cxx
===================================================================
--- trunk/src/RefCounter.cxx 2009-04-08 07:40:45 UTC (rev 39)
+++ trunk/src/RefCounter.cxx 2009-04-08 07:41:32 UTC (rev 40)
@@ -16,50 +16,15 @@
#endif
#include "asycxx-common.h"
-#include <asycxx/Error.h>
#include <asycxx/RefCounter.h>
+using namespace asycxx;
-/**
- * \author Joe Steeve, jo...@hi...
- * \class RefCounter
- * \brief A simple reference counting mechanism
- *
- * \details This class provides functionality necessary for a simple
- * reference-counting system. The creator of the object already owns
- * the object. Hence the creator should explicitly calls
- * RefCounter::DisOwn() to disown the object
- */
-
-RefCounter::RefCounter ()
-{
- m__OwnerCount = 1;
-}
-
RefCounter::~RefCounter ()
{
- if (m__OwnerCount != 0)
- {
- ERR ("FATAL: some-one still owns me");
- }
+ ASSERT ((m_OwnerCount == 0), "FATAL: some-one still owns me");
}
-void
-RefCounter::Own (void)
-{
- m__OwnerCount ++;
-}
-
-void
-RefCounter::DisOwn (void)
-{
- m__OwnerCount --;
- if (m__OwnerCount == 0)
- {
- delete this;
- }
-}
-
/*
Local Variables:
mode: c++
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:40:46
|
Revision: 39
http://asycxx.svn.sourceforge.net/asycxx/?rev=39&view=rev
Author: joe_steeve
Date: 2009-04-08 07:40:45 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
moved class:SelectReactor to 'asycxx' namespace
* also added minor refactor to support changes in class:Reactor
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/SelectReactor.h
trunk/src/SelectReactor.cxx
Modified: trunk/include/asycxx/SelectReactor.h
===================================================================
--- trunk/include/asycxx/SelectReactor.h 2009-04-08 07:39:49 UTC (rev 38)
+++ trunk/include/asycxx/SelectReactor.h 2009-04-08 07:40:45 UTC (rev 39)
@@ -19,30 +19,43 @@
#include <sys/select.h>
+#include "Selectable.h"
#include "Reactor.h"
-class SelectReactor :public Reactor
+namespace asycxx
{
+ /**
+ *
+ */
+ class SelectReactor :public Reactor
+ {
+ public:
+ SelectReactor (void);
+ virtual ~SelectReactor (void);
-public:
- SelectReactor (void);
- ~SelectReactor (void);
+ protected:
+ /* Overridden methods */
+ int WaitForEvents (void);
+ void ProcessEvents (void);
-protected:
- void WaitForEvents (void);
- void ProcessFDEvents (void);
+ private:
+ /* counts maintained for 'select()' */
+ int m_maxFd;
+ int m_FdCount;
-private:
- int m_maxFd;
- int m_FdCount;
- fd_set m_FdsForReading;
- bool m_bReadingFdSetIsEmpty;
- fd_set m_FdsForWriting;
- bool m_bWritingFdSetIsEmpty;
-
- void BuildFdSets (void);
-};
+ /* fd-sets for 'select()' */
+ fd_set m_FdsForReading;
+ fd_set m_FdsForWriting;
+ /* helper bools to track if a given fd-set is empty */
+ bool m_bReadingFdSetIsEmpty;
+ bool m_bWritingFdSetIsEmpty;
+
+ /* helper function to build the fd-sets */
+ void BuildFdSets (void);
+ };
+}
+
#endif /* __HIPRO_ASYCXX__SELECT_REACTOR_H__ */
/*
Modified: trunk/src/SelectReactor.cxx
===================================================================
--- trunk/src/SelectReactor.cxx 2009-04-08 07:39:49 UTC (rev 38)
+++ trunk/src/SelectReactor.cxx 2009-04-08 07:40:45 UTC (rev 39)
@@ -23,10 +23,10 @@
#include <asycxx/Error.h>
#include <asycxx/SelectReactor.h>
+using namespace asycxx;
-/**
- * \brief ctor
- *
+/*
+ * CTOR
*/
SelectReactor::SelectReactor (void)
{
@@ -38,9 +38,8 @@
}
-/**
- * \brief dtor
- *
+/*
+ * DTOR
*/
SelectReactor::~SelectReactor (void)
{
@@ -48,16 +47,14 @@
}
-/**
- * \brief Wait for file-descriptor events till some time-out
- *
- * \details This method uses the select() system call to wait till
- * some of the file-descriptors become readable/writable. This method
- * blocks waiting for events for a maximum of TIME_SENSITIVITY
+/*
+ * This method uses the select() system call to wait till some of the
+ * file-descriptors become readable/writable. This method blocks
+ * waiting for events for a maximum of TIME_SENSITIVITY
* milli-seconds. This method updates the m_PendingEvents to show how
* many file-descriptors need action on.
*/
-void
+int
SelectReactor::WaitForEvents (void)
{
int iret;
@@ -71,11 +68,13 @@
else { rfds = &m_FdsForReading; }
if (m_bWritingFdSetIsEmpty == true) { wfds = NULL; }
else { wfds = &m_FdsForWriting; }
+
/* make sure we are waiting for something */
if ((m_bReadingFdSetIsEmpty == true) && (m_bWritingFdSetIsEmpty == true))
{
LOG3 ("<%p>: Who are we waiting for??", this);
}
+
/* wake-up time. we are not sleeping forever */
tv.tv_sec = 0L;
tv.tv_usec = (TIME_SENSITIVITY * 1000);
@@ -89,19 +88,20 @@
this, strerror (errno), m_FdCount);
}
}
- /* update the pending file-descriptor events */
- m_PendingFDEvents = iret;
+
+ /* return the pending file-descriptor events */
+ return iret;
}
-/**
- * \brief Builds file-descriptor sets for select ()
+/*
+ * Builds file-descriptor sets for select ()
*/
void
SelectReactor::BuildFdSets (void)
{
- size_t i;
- Reactor::Event * e;
+ Reactor::Event * ev;
+ std::list<Event *>::iterator it;
m_bReadingFdSetIsEmpty = true;
m_bWritingFdSetIsEmpty = true;
@@ -111,18 +111,18 @@
FD_ZERO (&m_FdsForReading);
FD_ZERO (&m_FdsForWriting);
- for (i=0; i<m_readEvents.size(); i++)
+ for (it = m_readEvents.begin(); it != m_readEvents.end(); it++)
{
- e = m_readEvents[i];
- FD_SET (e->m_Fd, &m_FdsForReading);
- if (m_maxFd < e->m_Fd) { m_maxFd = e->m_Fd; }
+ ev = *it;
+ FD_SET (ev->Fd, &m_FdsForReading);
+ if (m_maxFd < ev->Fd) { m_maxFd = ev->Fd; }
m_FdCount ++;
}
- for (i=0; i<m_writeEvents.size(); i++)
+ for (it = m_writeEvents.begin(); it != m_writeEvents.end(); it++)
{
- e = m_writeEvents[i];
- FD_SET (e->m_Fd, &m_FdsForWriting);
- if (m_maxFd < e->m_Fd) { m_maxFd = e->m_Fd; }
+ ev = *it;
+ FD_SET (ev->Fd, &m_FdsForWriting);
+ if (m_maxFd < ev->Fd) { m_maxFd = ev->Fd; }
m_FdCount ++;
}
m_maxFd++;
@@ -132,47 +132,40 @@
}
-/**
- * \brief Process the pending file-descriptor events
- *
- * \details This method looks up the FDSETs setup by the select()
- * system call and triggers the appropriate event.
+/*
+ * This method looks up the FDSETs setup by the select() system call
+ * and triggers the appropriate events.
*/
void
-SelectReactor::ProcessFDEvents (void)
+SelectReactor::ProcessEvents (void)
{
- size_t i;
- Reactor::Event * e;
+ Reactor::Event * ev;
fd_set *read_fds, *write_fds;
+ std::list<Event *>::iterator it;
read_fds = &m_FdsForReading;
write_fds = &m_FdsForWriting;
- /* check for readable descriptors */
- for (i=0; i<m_readEvents.size(); i++)
+ /* check the readers list for 'Readable's */
+ for (it = m_readEvents.begin(); it != m_readEvents.end(); it++)
{
- e = m_readEvents[i];
- if (FD_ISSET (e->m_Fd, read_fds))
- {
- DoFDEventNotification (e);
+ ev = *it;
+ if (FD_ISSET (ev->Fd, read_fds))
+ {
+ /* Notify that the 'Selectable' is now readable */
+ ev->pSelectable->Readable();
}
- else
- {
- DoFDTimeoutNotification (e);
- }
}
+
/* check for writable descriptors */
- for (i=0; i<m_writeEvents.size(); i++)
+ for (it = m_writeEvents.begin(); it != m_writeEvents.end(); it++)
{
- e = m_writeEvents[i];
- if (FD_ISSET (e->m_Fd, write_fds))
+ ev = *it;
+ if (FD_ISSET (ev->Fd, write_fds))
{
- DoFDEventNotification (e);
+ /* Notify that the 'Selectable' is now writable */
+ ev->pSelectable->Writable();
}
- else
- {
- DoFDTimeoutNotification (e);
- }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:39:51
|
Revision: 38
http://asycxx.svn.sourceforge.net/asycxx/?rev=38&view=rev
Author: joe_steeve
Date: 2009-04-08 07:39:49 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
removed 'Deferred' code from class:Reactor
Reactor now directly manages 'Selectables'. Since both Transports and
Listeners are Selectables, we can directly use them instead of
callbacks.
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/Reactor.h
trunk/src/Reactor.cxx
Modified: trunk/include/asycxx/Reactor.h
===================================================================
--- trunk/include/asycxx/Reactor.h 2009-04-08 07:39:05 UTC (rev 37)
+++ trunk/include/asycxx/Reactor.h 2009-04-08 07:39:49 UTC (rev 38)
@@ -14,74 +14,152 @@
#ifndef __HIPRO_ASYCXX__REACTOR_H__
#define __HIPRO_ASYCXX__REACTOR_H__
+#include <list>
-#include <deque>
-
#include "_asycxx.h"
-#include "Deferred.h"
+#include "Selectable.h"
+
#define TIME_SENSITIVITY 200LL
-class Reactor
+namespace asycxx
{
-public:
- Reactor ();
- virtual ~Reactor ();
+ /**
+ * \class Reactor
+ *
+ * \brief The main event dispatching mechanism
+ *
+ * \details The reactor provides a mechanism to register
+ * 'Selectable's waiting for readability or writability. The reactor
+ * sits in a tight loop waiting for any of the 'Selectable's to
+ * become readable/writable. The exact mechanism of this depends on
+ * the Reactor implementation. Eg: SelectReactor uses select(),
+ * while EPollReactor uses epoll().
+ */
+ class Reactor
+ {
+ public:
+ Reactor();
+ virtual ~Reactor();
- Deferred * OnReadable (int Fd) throw ();
- Deferred * OnReadable (int Fd, h_msecs_t timeoutTime) throw ();
- Deferred * OnWritable (int Fd) throw ();
- Deferred * OnWritable (int Fd, h_msecs_t timeoutTime) throw ();
- Deferred * OnTimeElapsed (h_msecs_t timeoutTime) throw ();
- void UnRegister (Deferred *deferred) throw ();
+ /**
+ * \brief Gets the current time-stamp (millisecond accuracy)
+ *
+ * \details This method returns the current time-stamp. This
+ * time-stamp gets updated every time the Reactor wakes up.
+ */
+ asycxx_timestamp_t CurrentTS (void) { return m_LastAwokenTS; }
- h_timestamp_t CurrentTS (void) { return m_LastAwokenTS; }
- void Run (void);
+ /**
+ * \brief Add a 'Selectable' to be notified when Readable
+ *
+ * \param[in] reader A 'Selectable' object
+ *
+ * \details This method adds the given 'Selectable' to the list of
+ * 'readers'.
+ */
+ virtual void addReader (Selectable *reader);
+
+ /**
+ * \brief Add a 'Selectable' to be notified when Writable
+ *
+ * \param[in] writer A 'Selectable' object
+ *
+ * \details This method adds the given 'Selectable' to the list of
+ * 'writers'.
+ */
+ virtual void addWriter (Selectable *writer);
+
+ /**
+ * \brief Remove a 'Selectable' from 'readers list'
+ *
+ * \param[in] reader A 'Selectable' object
+ *
+ * \details This method removes the given 'Selectable' from the
+ * list of 'readers'. The given 'Selectable' wont get 'Readable'
+ * notification anymore.
+ */
+ virtual void removeReader (Selectable *reader);
+
+ /**
+ * \brief Remove a 'Selectable' from 'writers list'
+ *
+ * \param[in] reader A 'Selectable' object
+ *
+ * \details This method removes the given 'Selectable' from the
+ * list of 'writers'. The given 'Selectable' wont get 'Writable'
+ * notification anymore.
+ */
+ virtual void removeWriter (Selectable *writer);
+
+ /**
+ * \brief Clear all the 'readers' and 'writers'
+ *
+ * \details This method clears the readers and writers list. All
+ * objects associated with the selectables in the respective lists
+ * would also be destroyed.
+ *
+ * Note: Unless the application has registered a 'Timer', the
+ * application would hang after calling this method.
+ */
+ //virtual void resetAll (void);
+
+ /**
+ * \brief Runs the reactor
+ *
+ * \details This method does not return. It blocks waiting for
+ * events on the registered 'Selectables' and notifies them.
+ */
+ void Run (void);
-protected:
- class Event
- {
- public:
- Event ();
- ~Event ();
+ protected:
+ class Event
+ {
+ public:
+ Event (Selectable *selectable)
+ {
+ pSelectable = selectable;
+ Fd = pSelectable->Fd();
+ bDie = false;
+ }
+ ~Event () {}
- bool m_bDie;
+ int Fd;
+ bool bDie;
+ Selectable *pSelectable;
+ };
- int m_Fd;
- h_msecs_t m_TimeoutTime;
- h_timestamp_t m_LastTriggerTS;
- h_timestamp_t m_NextTriggerTS;
- Deferred m_Deferred;
- };
- std::deque<Event *> m_readEvents;
- std::deque<Event *> m_writeEvents;
- std::deque<Event *> m_timeEvents;
+ std::list<Event *> m_readEvents;
+ std::list<Event *> m_writeEvents;
- int m_PendingFDEvents;
- virtual void WaitForEvents (void) = 0;
- virtual void ProcessFDEvents (void) = 0;
+ /**
+ * \brief Wait until some event occurs
+ *
+ * \details This method should be implemented by the specific
+ * reactor implementations. This method should block till some event
+ * occurs and is available for processing. This method should return
+ * the number of pending file-descriptor events.
+ */
+ virtual int WaitForEvents (void) = 0;
- /**
- * \brief The TimeStamp when latest activity happened
- *
- * \detail This holds the last time-stamp when the reactor was doing
- * something. This should be updated by Reactor implementations
- * (Select, Epoll, etc.) everytime they wake up to do something
- * (attend to file-descriptor activity or handle timeout actions
- */
- h_timestamp_t m_LastAwokenTS;
- void DoFDEventNotification (Reactor::Event *ev);
- void DoFDTimeoutNotification (Reactor::Event *ev);
+ /**
+ * \brief Process the timeouts of FD events
+ *
+ * \details This method looks up the list of events for timeouts and
+ * fires them.
+ */
+ virtual void ProcessEvents (void) = 0;
-private:
- void ProcessTimeEvents (void);
- void ProcessFDTimeouts (void);
- void CleanupEventLists (void);
- Deferred * AddToReadEvents (int Fd, h_msecs_t timeoutTime);
- Deferred * AddToWriteEvents (int Fd, h_msecs_t timeoutTime);
+ private:
+ asycxx_timestamp_t m_LastAwokenTS;
-};
+ void CleanupEventLists (void);
+ void _CleanupEventList (std::list<Event *>& ev_list);
+ void addFdEvent (Selectable *s, const char *type,
+ std::list<Reactor::Event *>& ev_list);
+ };
+}
#endif /* __HIPRO_ASYCXX__REACTOR_H__ */
/*
Modified: trunk/src/Reactor.cxx
===================================================================
--- trunk/src/Reactor.cxx 2009-04-08 07:39:05 UTC (rev 37)
+++ trunk/src/Reactor.cxx 2009-04-08 07:39:49 UTC (rev 38)
@@ -11,545 +11,191 @@
*
*******************************************************************/
-/**
- * \author Joe Steeve, jo...@hi...
- * \class Reactor
- * \brief Core 'reactor' functionality
- *
- * \details The reactor is the core.
- */
#ifdef HAVE_CONFIG_H
#include <asycxx-config.h>
#endif
#include <unistd.h>
-#include <exception>
#include "asycxx-common.h"
#include <asycxx/Reactor.h>
-#include <asycxx/Deferred.h>
+#include <asycxx/Selectable.h>
+#include <asycxx/Error.h>
-//////////////////////////////////////////////////////////////////////////////
+using namespace asycxx;
-/**
- * \author Joe Steeve, jo...@hi...
- * \class Reactor::Event
- * \brief Defines an event
- *
- * \details This class defines an 'Event'
- */
-
-/**
- * \brief ctor.
- */
-Reactor::Event::Event ()
-{
- m_Fd = -1;
- m_TimeoutTime = 0L;
- m_LastTriggerTS = 0L;
- m_NextTriggerTS = 0L;
- m_bDie = false;
-}
-
-/**
- * \brief dtor.
- */
-Reactor::Event::~Event ()
-{
-}
-
-
//////////////////////////////////////////////////////////////////////////////
-/**
- * \brief Constructor
- *
+/*
+ * CTOR:
*/
Reactor::Reactor ()
{
- m_PendingFDEvents = 0;
- m_LastAwokenTS = GetCurrentTimeStamp ();
+ m_LastAwokenTS = GetCurrentTimeStamp();
}
-/**
- * \brief Destructor
- *
+/*
+ * DTOR: we clear up all the event lists here
*/
Reactor::~Reactor ()
{
- size_t i;
- Event *ev;
+ std::list<Event *>::iterator it;
/* Destroy all event-infos */
- for (i=0; i<m_readEvents.size(); i++)
+ for (it = m_readEvents.begin(); it != m_readEvents.end(); it++)
{
- ev = m_readEvents[0];
- m_readEvents.pop_front();
- delete ev;
+ delete *it;
}
- for (i=0; i<m_writeEvents.size(); i++)
+ for (it = m_writeEvents.begin(); it != m_writeEvents.end(); it++)
{
- ev = m_writeEvents[0];
- m_writeEvents.pop_front();
- delete ev;
+ delete *it;
}
- for (i=0; i<m_timeEvents.size(); i++)
- {
- ev = m_timeEvents[0];
- m_timeEvents.pop_front();
- delete ev;
- }
}
-/**
- * \brief Get a deferred that fires when given 'Fd' becomes readable
- *
- * \details The deferred returned by this method does not keep track
- * of time. It fires only when Fd becomes readable.
+/*
+ * Methods to register the given 'Selectable's
*/
-Deferred *
-Reactor::OnReadable (int Fd) throw ()
+void
+Reactor::addReader (Selectable *reader)
{
- if (Fd == -1)
- { THROW (DevError, "bad fd = -1"); }
-
- return AddToReadEvents (Fd, 0L);
+ ASSERT ((reader != NULL), "bad reader");
+ ASSERT ((reader->Fd() != -1), "bad fd = -1");
+ addFdEvent (reader, "reader", m_readEvents);
}
-/**
- * \brief Get a deferred that fires when given 'Fd' becomes readable
- *
- * \details The deferred returned by this method fires when given 'Fd'
- * becomes readable or when given 'timeoutTime' elapses.
- */
-Deferred *
-Reactor::OnReadable (int Fd, h_msecs_t timeoutTime) throw ()
-{
- if (Fd == -1)
- { THROW (DevError, "bad fd = -1"); }
- if (timeoutTime == 0L)
- { THROW (DevError, "timeoutTime = 0 will wait for ever"); }
- return AddToReadEvents(Fd, timeoutTime);
-}
-/**
- * \brief Get a deferred that fires when given 'Fd' becomes readable
- *
- * \details The deferred returned by this method does not keep track
- * of time. It fires only when Fd becomes writable.
- */
-Deferred *
-Reactor::OnWritable (int Fd) throw ()
+void
+Reactor::addWriter (Selectable *writer)
{
- if (Fd == -1)
- { THROW (DevError, "bad fd = -1"); }
-
- return AddToWriteEvents (Fd, 0L);
+ ASSERT ((writer != NULL), "bad reader");
+ ASSERT ((writer->Fd() != -1), "bad fd = -1");
+ addFdEvent (writer, "writer", m_writeEvents);
}
-/**
- * \brief Get a deferred that fires when given 'Fd' becomes readable
- *
- * \details The deferred returned by this method fires when given 'Fd'
- * becomes writable or when given 'timeoutTime' elapses.
- */
-Deferred *
-Reactor::OnWritable (int Fd, h_msecs_t timeoutTime) throw ()
-{
- if (Fd == -1)
- { THROW (DevError, "bad fd = -1"); }
- if (timeoutTime == 0L)
- { THROW (DevError, "timeoutTime = 0 will wait for ever"); }
- return AddToWriteEvents (Fd, timeoutTime);
-}
-
-/**
- * \brief Add the given Fd to the on-readable-event monitoring list
- *
- * \param[in] Fd A valid file descriptor
- * \param[in] timeoutTime Timeout in milliseconds
- *
- * \details This method adds the given file-descriptor to the list of
- * file-descriptors being monitored for 'readability'.
+/*
+ * Method to add a given fd to the given list. Used as a common
+ * convenience function for the addReader, addWriter methods.
*/
-Deferred *
-Reactor::AddToReadEvents (int Fd, h_msecs_t timeoutTime)
+void
+Reactor::addFdEvent (Selectable *s, const char *type,
+ std::list<Reactor::Event *>& ev_list)
{
- size_t i;
+ Reactor::Event *ev;
+ std::list<Event *>::iterator it;
/* lets make sure we dont have this file-descriptor in our lists
already */
- for (i=0; i < m_readEvents.size(); i++)
+ for (it = ev_list.begin(); it != ev_list.end(); it++)
{
- if ((m_readEvents[i]->m_Fd == Fd) && (m_readEvents[i]->m_bDie == false))
+ ev = *it;
+ if ((ev->Fd == s->Fd()) && (ev->bDie == false))
{
- THROW (DevError, "fd=%u alreaded registered for On-Readable event",
- Fd);
+ THROW (DevError, "fd=%u '%s' exists", ev->Fd, type);
}
}
- Reactor::Event *ev;
- try
- {
- ev = new Reactor::Event();
- }
- catch (std::bad_alloc &e)
- {
- THROW (OutOfMemoryError, "allocating a read-'Event' object");
- }
+ /* create a new event and configure it */
+ ev = new Reactor::Event (s);
- ev->m_Fd = Fd;
- ev->m_TimeoutTime = timeoutTime;
- ev->m_LastTriggerTS = m_LastAwokenTS;
- ev->m_NextTriggerTS = m_LastAwokenTS + timeoutTime;
-
- try
- {
- m_readEvents.push_back (ev);
- LOG3 ("added Reactor::Event<%p> OnReadable: timeout=%lld msecs, fd=%d",
- ev, timeoutTime, Fd);
- }
- catch (...)
- {
- delete ev;
- THROW (OutOfMemoryError, "adding 'Event' to m_readEvents");
- }
-
- return &ev->m_Deferred;
+ /* add the event to our lists */
+ ev_list.push_back (ev);
+ LOG3 ("added Reactor::Event<%p> '%s': fd=%d", ev, type, ev->Fd);
}
-/**
- * \brief Add the given Fd to the on-writable-event monitoring list
- *
- * \param[in] Fd A valid file descriptor
- * \param[in] timeoutTime Timeout in milliseconds
- *
- * \details This method adds the given file-descriptor to the list of
- * file-descriptors being monitored for 'writability'.
+/*
+ * Methods to remove events from readers, writers, and time-waiters
+ * lists.
*/
-Deferred *
-Reactor::AddToWriteEvents (int Fd, h_msecs_t timeoutTime)
+void
+Reactor::removeReader (Selectable *reader)
{
- size_t i;
-
- /* lets make sure we dont have a similar event already registered */
- for (i=0; i < m_writeEvents.size(); i++)
- {
- if ((m_writeEvents[i]->m_Fd == Fd) && (m_writeEvents[i]->m_bDie == false))
- {
- THROW (DevError, "fd=%u alreaded registered for On-Writable event",
- Fd);
- }
- }
-
Reactor::Event *ev;
- try
+ std::list<Event *>::iterator it;
+ for (it = m_readEvents.begin(); it != m_readEvents.end(); it++)
{
- ev = new Reactor::Event();
+ ev = *it;
+ if (ev->Fd == reader->Fd()) { ev->bDie = true; return; }
}
- catch (std::bad_alloc &e)
- {
- THROW (OutOfMemoryError, "allocating a write-'Event' object");
- }
-
- ev->m_Fd = Fd;
- ev->m_TimeoutTime = timeoutTime;
- ev->m_LastTriggerTS = m_LastAwokenTS;
- ev->m_NextTriggerTS = m_LastAwokenTS + timeoutTime;
-
- try
- {
- m_writeEvents.push_back (ev);
-// LOG3 ("added Reactor::Event<%p> OnWritable: timeout=%lld msecs, fd=%d",
-// ev, timeoutTime, Fd);
- }
- catch (...)
- {
- delete ev;
- THROW (OutOfMemoryError, "adding 'Event' to m_writeEvents");
- }
-
- return &ev->m_Deferred;
}
-
-/**
- * \brief Creates a time-elapsed event
- *
- * \param[in] timeoutTime time-out time in milliseconds
- *
- * \details This method registers a time-elapsed event for the given
- * 'timeoutTime'.
- */
-Deferred *
-Reactor::OnTimeElapsed (h_msecs_t timeoutTime) throw ()
-{
- Reactor::Event *ev;
-
- try
- {
- ev = new Reactor::Event();
- }
- catch (std::bad_alloc &e)
- {
- THROW (OutOfMemoryError, "allocating an 'Event' object");
- }
-
- ev->m_TimeoutTime = timeoutTime;
- ev->m_LastTriggerTS = m_LastAwokenTS;
- ev->m_NextTriggerTS = m_LastAwokenTS + timeoutTime;
-
- try
- {
- m_timeEvents.push_back (ev);
- LOG3 ("added Reactor::Event<%p> for OnTimeElapsed (%lld msecs)",
- ev, timeoutTime);
- }
- catch (...)
- {
- delete ev;
- THROW (OutOfMemoryError, "adding 'Event' to m_timeEvents");
- }
-
- return &ev->m_Deferred;
-}
-
-
-/**
- * \brief Unregisters the event associated with the given deferred
- *
- * \param[in] deferred The Deferred that was provided at the time of
- * registering for an event.
- *
- * \details This method looks up the event-lists for the event that is
- * associated with the given deferred object, and marks it for
- * removal.
- */
-void
-Reactor::UnRegister (Deferred *deferred) throw ()
-{
- size_t i;
- for (i=0; i< m_readEvents.size(); i++)
- {
- if (&m_readEvents[i]->m_Deferred == deferred)
- {
- m_readEvents[i]->m_bDie = true;
- return;
- }
- }
- for (i=0; i< m_writeEvents.size(); i++)
- {
- if (&m_writeEvents[i]->m_Deferred == deferred)
- {
- m_writeEvents[i]->m_bDie = true;
- return;
- }
- }
- for (i=0; i< m_timeEvents.size(); i++)
- {
- if (&m_timeEvents[i]->m_Deferred == deferred)
- {
- m_timeEvents[i]->m_bDie = true;
- return;
- }
- }
-}
-
-
-/**
- * \brief Cleans up the inactive events
- *
- * \details This method looks through the event-lists for events that
- * can be removed, and removes them permanently.
- */
void
-Reactor::CleanupEventLists (void)
+Reactor::removeWriter (Selectable *writer)
{
- size_t i;
Reactor::Event *ev;
-
- for (i=0; i< m_readEvents.size(); i++)
+ std::list<Event *>::iterator it;
+ for (it = m_writeEvents.begin(); it != m_writeEvents.end(); it++)
{
- if (m_readEvents[i]->m_bDie == true)
- {
- ev = m_readEvents[i];
- m_readEvents.erase(m_readEvents.begin()+i);
- delete ev;
- i--;
- }
+ ev = *it;
+ if (ev->Fd == writer->Fd()) { ev->bDie = true; return; }
}
- for (i=0; i< m_writeEvents.size(); i++)
- {
- if (m_writeEvents[i]->m_bDie == true)
- {
- ev = m_writeEvents[i];
- m_writeEvents.erase(m_writeEvents.begin()+i);
- delete ev;
- i--;
- }
- }
- for (i=0; i< m_timeEvents.size(); i++)
- {
- if (m_timeEvents[i]->m_bDie == true)
- {
- ev = m_timeEvents[i];
- m_timeEvents.erase(m_timeEvents.begin()+i);
- delete ev;
- i--;
- }
- }
}
-/**
- * \brief Process time-events
- *
- * \details This method looks up the list of time-events for events
- * that are ready to be triggered, and triggers them.
+/*
+ * The main run-loop. Simply sits in a tight loop waiting for events.
*/
void
-Reactor::ProcessTimeEvents (void)
+Reactor::Run (void)
{
- size_t i;
- Reactor::Event * ev;
- h_msecs_t excessTime;
-
- for (i=0; i < m_timeEvents.size(); i++)
+ while (1)
{
- ev = m_timeEvents[i];
- if (m_LastAwokenTS >= ev->m_NextTriggerTS)
- {
- excessTime = m_LastAwokenTS - ev->m_NextTriggerTS;
- ev->m_Deferred.NotifyTimeout (excessTime);
- ev->m_LastTriggerTS = m_LastAwokenTS;
- ev->m_NextTriggerTS = m_LastAwokenTS + ev->m_TimeoutTime;
- }
- }
-}
+ /* wait for events */
+ WaitForEvents ();
+ /* update the current timestamp */
+ m_LastAwokenTS = GetCurrentTimeStamp();
-/**
- * \brief Process the timeouts of FD events
- *
- * \details This method looks up the list of events for timeouts and
- * fires them.
- */
-void
-Reactor::ProcessFDTimeouts (void)
-{
- size_t i;
- Reactor::Event * e;
+ /* process file-descriptor events if we have any */
+ ProcessEvents ();
- /* check for readable descriptors */
- for (i=0; i<m_readEvents.size(); i++)
- {
- e = m_readEvents[i];
- DoFDTimeoutNotification (e);
- }
- /* check for writable descriptors */
- for (i=0; i<m_writeEvents.size(); i++)
- {
- e = m_writeEvents[i];
- DoFDTimeoutNotification (e);
- }
-}
+ /* update the timer so that it can fire timeouts */
+ /* TODO: update the timer here */
-
-/**
- * \brief The main run-loop
- *
- * \details This is the main run-loop of the reactor. This is a
- * continuous while loop which waits for events and dispatches them.
- */
-void
-Reactor::Run (void)
-{
- while (1)
- {
- WaitForEvents ();
- m_LastAwokenTS = GetCurrentTimeStamp ();
- if (m_PendingFDEvents > 0)
- {
- ProcessFDEvents ();
- }
- else
- {
- ProcessFDTimeouts ();
- }
- if (m_PendingFDEvents > 0)
- {
- LOG3 ("not all pending fd-events were processed. %d remaining",
- m_PendingFDEvents);
- }
- ProcessTimeEvents ();
+ /* cleanup the event lists of dead 'Selectable's */
CleanupEventLists ();
};
- ERR ("FATAL: broken out of Reactor::Run(). should not happen");
+ ERR ("FATAL: broken out of Reactor::Run(). should not have happened");
}
-/**
- * \brief Helper to notify read/write events on a file-descriptor
- *
- * \param[in] e Pointer to the Reactor::Event whose deferred should be
- * fired.
- *
- * \details This method fires the deferred for the given event. If the
- * event-notification failes with a BadFDError exception, then this
- * calls the OnError call-back, and unregisters the event from the
- * reactor.
+/*
+ * This method looks through the event-lists for events that can be
+ * removed, and removes them permanently.
*/
void
-Reactor::DoFDEventNotification (Reactor::Event *ev)
+Reactor::CleanupEventLists (void)
{
- try
- {
- ev->m_Deferred.NotifyEvent ();
- }
- catch (BadFDError& e)
- {
- /* We got a bad-file descriptor here */
- ev->m_Deferred.NotifyError ();
- UnRegister (&ev->m_Deferred);
- }
- ev->m_LastTriggerTS = m_LastAwokenTS;
- ev->m_NextTriggerTS = m_LastAwokenTS + ev->m_TimeoutTime;
-// LOG3 ("EvNo:: updating timeout, fd=%u, ts=%llu, to_ts=%llu",
-// ev->m_Fd, ev->m_LastTriggerTS, ev->m_NextTriggerTS);
- m_PendingFDEvents --;
+ _CleanupEventList (m_readEvents);
+ _CleanupEventList (m_writeEvents);
}
-
-/**
- * \brief Helper to notify timeout events on a file-descriptor
- *
- * \param[in] e Pointer to the Reactor::Event whose deferred should be
- * fired in case we hit a timeout.
- *
- * \details This method fires the 'timeout' method in the deferred for
- * the given event. First checks to see if the timeout has elapsed.
+/*
+ * Convenience function to clean up entries in the given event list
*/
void
-Reactor::DoFDTimeoutNotification (Reactor::Event *ev)
+Reactor::_CleanupEventList (std::list<Event *>& ev_list)
{
- h_msecs_t excessTime;
+ Reactor::Event *ev;
+ std::list<Event *>::iterator it;
- if (ev->m_TimeoutTime != 0)
- {
- if (m_LastAwokenTS >= ev->m_NextTriggerTS)
+ it = ev_list.begin();
+ while (it != ev_list.end())
+ {
+ ev = *it;
+ if (ev->bDie == true)
{
- excessTime = m_LastAwokenTS - ev->m_NextTriggerTS;
- ev->m_Deferred.NotifyTimeout (excessTime);
- ev->m_LastTriggerTS = m_LastAwokenTS;
- ev->m_NextTriggerTS = m_LastAwokenTS + ev->m_TimeoutTime;
-// LOG3 ("ToNo:: updating timeout, fd=%u, ts=%llu, to_ts=%llu",
-// ev->m_Fd, ev->m_LastTriggerTS, ev->m_NextTriggerTS);
+ it = ev_list.erase (it);
+ delete ev;
}
+ else
+ {
+ it++;
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:39:06
|
Revision: 37
http://asycxx.svn.sourceforge.net/asycxx/?rev=37&view=rev
Author: joe_steeve
Date: 2009-04-08 07:39:05 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
moved Error* to 'asycxx' namespace
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/Error.h
trunk/src/Error.cxx
Modified: trunk/include/asycxx/Error.h
===================================================================
--- trunk/include/asycxx/Error.h 2009-04-08 07:38:15 UTC (rev 36)
+++ trunk/include/asycxx/Error.h 2009-04-08 07:39:05 UTC (rev 37)
@@ -21,48 +21,58 @@
#define ExpMSG_LEN 1024
-class Error
+namespace asycxx
{
-public:
- Error () {}
- Error (const char *fmt, ...)
- {
- va_list args;
- va_start (args, fmt);
- doError (fmt, args);
- va_end (args);
- }
- virtual ~Error () {}
+ enum ErrorCode
+ {
+ Err_Unknown = 1,
+ Err_Timeout,
+ Err_BadFD,
+ };
-protected:
- void doError (const char *fmt, va_list vargs);
- virtual const char *GetErrorName (void) { return "Unknown error"; }
-};
+ class Error
+ {
+ public:
+ Error () {}
+ Error (const char *fmt, ...)
+ {
+ va_list args;
+ va_start (args, fmt);
+ doError (fmt, args);
+ va_end (args);
+ }
+ virtual ~Error () {}
-#define CREATE_ERROR(err, berr, name) \
- class err : public berr \
- { \
-public: \
- err () {} \
- err (const char *fmt, ...) \
- { \
- va_list args; \
- va_start (args, fmt); \
- doError (fmt, args); \
- va_end (args); \
- } \
-protected: \
- virtual const char *GetErrorName (void) { return name; } \
+ protected:
+ void doError (const char *fmt, va_list vargs);
+ virtual const char *GetErrorName (void) { return "Unknown error"; }
+ };
+
+#define CREATE_ERROR(err, berr, name) \
+ class err : public berr \
+ { \
+ public: \
+ err () {} \
+ err (const char *fmt, ...) \
+ { \
+ va_list args; \
+ va_start (args, fmt); \
+ doError (fmt, args); \
+ va_end (args); \
+ } \
+ protected: \
+ virtual const char *GetErrorName (void) { return name; } \
}
-CREATE_ERROR (FatalError, Error, "unknown FatalError");
-CREATE_ERROR (OutOfMemoryError, FatalError, "OutOfMemoryError");
-CREATE_ERROR (DevError, FatalError, "DevError");
-CREATE_ERROR (RunTimeError, FatalError, "RunTimeError");
+ CREATE_ERROR (FatalError, Error, "unknown FatalError");
+ CREATE_ERROR (OutOfMemoryError, FatalError, "OutOfMemoryError");
+ CREATE_ERROR (DevError, FatalError, "DevError");
+ CREATE_ERROR (RunTimeError, FatalError, "RunTimeError");
-CREATE_ERROR (RecoverableError, Error, "unknown RecoverableError");
-CREATE_ERROR (BadFDError, RecoverableError, "BadFDError");
+ CREATE_ERROR (RecoverableError, Error, "unknown RecoverableError");
+ CREATE_ERROR (BadFDError, RecoverableError, "BadFDError");
+}
#endif /* __HIPRO_ASYCXX__ERROR_H__ */
/*
Modified: trunk/src/Error.cxx
===================================================================
--- trunk/src/Error.cxx 2009-04-08 07:38:15 UTC (rev 36)
+++ trunk/src/Error.cxx 2009-04-08 07:39:05 UTC (rev 37)
@@ -22,6 +22,8 @@
#include "asycxx-common.h"
#include <asycxx/Error.h>
+using namespace asycxx;
+
void
Error::doError (const char *fmt, va_list vargs)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:38:17
|
Revision: 36
http://asycxx.svn.sourceforge.net/asycxx/?rev=36&view=rev
Author: joe_steeve
Date: 2009-04-08 07:38:15 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
moved class:DataBuffer into 'asycxx' namespace
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/DataBuffer.h
trunk/src/DataBuffer.cxx
Modified: trunk/include/asycxx/DataBuffer.h
===================================================================
--- trunk/include/asycxx/DataBuffer.h 2009-04-08 07:37:17 UTC (rev 35)
+++ trunk/include/asycxx/DataBuffer.h 2009-04-08 07:38:15 UTC (rev 36)
@@ -20,39 +20,41 @@
#include "_asycxx.h"
#include "RefCounter.h"
-class DataBuffer : public RefCounter
+namespace asycxx
{
-public:
- /* ctors */
- DataBuffer (size_t len);
- DataBuffer (void *buffer, size_t len);
+ class DataBuffer : public RefCounter
+ {
+ public:
+ /* ctors */
+ DataBuffer (size_t len);
+ DataBuffer (void *buffer, size_t len);
- /* Accessors */
- void * Data (void) { return m_Data; }
- size_t Len (void) { return m_DataLen; }
- void Len (size_t len);
- size_t BufferLen (void) { return m_BufferLen; }
- void Processed (size_t len);
- size_t Processed (void) { return m_ProcessedLen; }
- void * UnProcessed (void);
+ /* Accessors */
+ void * Data (void) { return m_Data; }
+ size_t Len (void) { return m_DataLen; }
+ void Len (size_t len);
+ size_t BufferLen (void) { return m_BufferLen; }
+ void Processed (size_t len);
+ size_t Processed (void) { return m_ProcessedLen; }
+ void * UnProcessed (void);
-protected:
- /* dtors */
- ~DataBuffer ();
+ protected:
+ /* dtors */
+ ~DataBuffer ();
-private:
- /* initializer */
- void _init (void);
+ private:
+ /* initializer */
+ void _init (void);
- /* The buffer */
- void *m_Data;
+ /* The buffer */
+ void *m_Data;
- /* meta-data about the buffer and its contents */
- size_t m_BufferLen; /* Maximum length of the buffer */
- size_t m_DataLen; /* Length of data held in the buffer */
- size_t m_ProcessedLen; /* Length of data processed */
-};
-
+ /* meta-data about the buffer and its contents */
+ size_t m_BufferLen; /* Maximum length of the buffer */
+ size_t m_DataLen; /* Length of data held in the buffer */
+ size_t m_ProcessedLen; /* Length of data processed */
+ };
+}
#endif /* __HIPRO_ASYCXX__DATA_BUFFER_H__ */
/*
Modified: trunk/src/DataBuffer.cxx
===================================================================
--- trunk/src/DataBuffer.cxx 2009-04-08 07:37:17 UTC (rev 35)
+++ trunk/src/DataBuffer.cxx 2009-04-08 07:38:15 UTC (rev 36)
@@ -20,6 +20,7 @@
#include "asycxx-common.h"
#include <asycxx/DataBuffer.h>
+using namespace asycxx;
void
DataBuffer::_init (void)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:37:19
|
Revision: 35
http://asycxx.svn.sourceforge.net/asycxx/?rev=35&view=rev
Author: joe_steeve
Date: 2009-04-08 07:37:17 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
class:TCPListener now uses StreamProtocol/ProtocolFactory/Transport
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/TCPListener.h
trunk/src/TCPListener.cxx
Modified: trunk/include/asycxx/TCPListener.h
===================================================================
--- trunk/include/asycxx/TCPListener.h 2009-04-08 07:36:33 UTC (rev 34)
+++ trunk/include/asycxx/TCPListener.h 2009-04-08 07:37:17 UTC (rev 35)
@@ -19,37 +19,75 @@
#include "Error.h"
#include "Listener.h"
-#include "Factory.h"
-#include "Deferred.h"
+#include "StreamProtocolFactory.h"
#include "Reactor.h"
-class TCPListener : public Listener
+namespace asycxx
{
-public:
+ class TCPListener : public Listener
+ {
+ public:
- TCPListener (Reactor *reactor, Factory *factory, unsigned short port);
- TCPListener (Reactor *reactor, Factory *factory, char *ip,
- unsigned short port);
- virtual ~TCPListener ();
+ /**
+ * \brief ctor to put TCPListener on localhost:port
+ *
+ * \param[in] reactor The reactor to hook to
+ * \param[in] factory The factory to use to produce protocols to
+ * handle new connections
+ * \param[in] port The port number to bind to
+ *
+ * \details This constructor puts the TCPListener object to listen
+ * on the 127.0.0.1:port interface.
+ */
+ TCPListener (Reactor *reactor, StreamProtocolFactory *factory,
+ unsigned short port);
- void SetupTCPNoDelay (void);
+ /**
+ * \brief ctor to put TCPListener on given ip:port
+ *
+ * \param[in] reactor The reactor to hook to
+ * \param[in] factory The factory to use to produce protocols to
+ * handle new connections
+ * \param[in] ip A string containing the IP address to bind to
+ * \param[in] port The port number to bind to
+ *
+ * \details This constructor puts the TCPListener object to listen
+ * on the given ip:port interface. This method expects a valid
+ * IPv4 ip-address in the 'ip' parameter.
+ */
+ TCPListener (Reactor *reactor, StreamProtocolFactory *factory,
+ char *ip, unsigned short port);
-protected:
- Reactor *m_Reactor;
- Factory *m_Factory;
- Deferred *m_ReactorDeferred;
+ virtual ~TCPListener () {};
- int m_Socket;
- unsigned short m_BindPort;
- in_addr m_BindIPAddr;
- char m_BindAddr_str[64];
- bool m_bSetupNoDelay;
+ /**
+ * \brief set the socket as TCP_NODELAY
+ *
+ * \details This method disables the Nagle algorithm on the
+ * connection by setting TCP_NODELAY.
+ */
+ void SetupTCPNoDelay (void) { m_bSetupNoDelay = true; }
- void Init (Reactor *reactor, Factory *factory,
- struct in_addr ip_addr, unsigned short port);
- static void handleNewConnection (void *obj);
-};
+ /* methods to be implemented for 'Selectable' */
+ virtual void Readable (void);
+
+ virtual void Writable (void) {}
+ virtual void closeReader (void) {}
+ virtual void closeWriter (void) {}
+ protected:
+ Reactor *m_Reactor;
+ StreamProtocolFactory *m_Factory;
+
+ unsigned short m_BindPort;
+ in_addr m_BindIPAddr;
+ char m_BindAddr_str[64];
+ bool m_bSetupNoDelay;
+
+ void Init (Reactor *reactor, StreamProtocolFactory *factory,
+ struct in_addr ip_addr, unsigned short port);
+ };
+}
#endif /* __HIPRO_ASYCXX__TCP_LISTENER_H__ */
/*
Modified: trunk/src/TCPListener.cxx
===================================================================
--- trunk/src/TCPListener.cxx 2009-04-08 07:36:33 UTC (rev 34)
+++ trunk/src/TCPListener.cxx 2009-04-08 07:37:17 UTC (rev 35)
@@ -27,141 +27,87 @@
#include "asycxx-common.h"
#include <asycxx/Error.h>
-#include <asycxx/Factory.h>
-#include <asycxx/Protocol.h>
+#include <asycxx/StreamProtocolFactory.h>
+#include <asycxx/StreamProtocol.h>
#include <asycxx/TCPTransport.h>
#include <asycxx/TCPListener.h>
+using namespace asycxx;
-/**
- * \brief ctor to put TCPListener on localhost:port
- *
- * \param[in] reactor The reactor to hook to
- * \param[in] factory The factory to use to produce protocols to
- * handle new connections
- * \param[in] port The port number to bind to
- *
- * \details This constructor puts the TCPListener object to listen on
- * the 127.0.0.1:port interface.
- */
-TCPListener::TCPListener (Reactor *reactor, Factory *factory,
+/* a simple constructor where we listen on loopback */
+TCPListener::TCPListener (Reactor *reactor, StreamProtocolFactory *factory,
unsigned short port)
{
struct in_addr ip_addr;
-
ip_addr.s_addr = htonl (INADDR_LOOPBACK);
+
Init (reactor, factory, ip_addr, port);
}
-/**
- * \brief ctor to put TCPListener on given ip:port
- *
- * \param[in] reactor The reactor to hook to
- * \param[in] factory The factory to use to produce protocols to
- * handle new connections
- * \param[in] ip A string containing the IP address to bind to
- * \param[in] port The port number to bind to
- *
- * \details This constructor puts the TCPListener object to listen on
- * the given ip:port interface. This method expects a valid IPv4
- * ip-address in the 'ip' parameter.
- */
-TCPListener::TCPListener (Reactor *reactor, Factory *factory,
+/* a ctor to listen on a specific interface */
+TCPListener::TCPListener (Reactor *reactor, StreamProtocolFactory *factory,
char *ip, unsigned short port)
{
int ret;
struct in_addr ip_addr;
ret = inet_aton (ip, &ip_addr);
- if (ret == 0)
- {
- THROW (RunTimeError, "'%s' is not a valid ip-address", ip);
- }
+ ASSERT ((ret != 0), "'%s' is not a valid ip-address", ip);
Init (reactor, factory, ip_addr, port);
}
-/*
- * \brief dtor
- */
-TCPListener::~TCPListener ()
-{
- if (m_Socket != -1)
- {
- close (m_Socket);
- }
-}
-
-/**
- * \brief Initialize the TCPListener
- *
- * \param[in] reactor The reactor to hook to
- * \param[in] factory The factory to use to produce protocols
- * \param[in] ip_addr A 'struct in_addr' containing the IP address to
- * listen on
- * \param[in] port The port to listen on
- *
- * \details This method is the backend method for all the
- * constructors. This creates a socket, puts it on listening mode,
- * binds it to the given interface and hooks it up to the reactor.
- */
+/* This method is the backend method for all the constructors. This
+ * creates a socket, puts it on listening mode, binds it to the given
+ * interface and hooks it up to the reactor. */
void
-TCPListener::Init (Reactor *reactor, Factory *factory,
+TCPListener::Init (Reactor *reactor, StreamProtocolFactory *factory,
struct in_addr ip_addr, unsigned short port)
{
int iret;
- ASSERT ((factory != NULL), "checking parameters");
- ASSERT ((reactor != NULL), "checking parameters");
+ ASSERT ((factory != NULL), "NULL factory :(");
+ ASSERT ((reactor != NULL), "NULL reactor :(");
m_Factory = factory;
m_Reactor = reactor;
m_bSetupNoDelay = false;
+ int sock;
sprintf (m_BindAddr_str, "%s:%d", inet_ntoa (ip_addr), port);
/* creating a socket */
- m_Socket = socket (PF_INET, SOCK_STREAM, 0);
- if (m_Socket == -1)
- {
- THROW (RunTimeError,
- "TCPListener: %s : creating socket to listen on %s",
- strerror (errno), m_BindAddr_str);
- }
+ sock = socket (PF_INET, SOCK_STREAM, 0);
+ ASSERT ((sock != -1), "TCPListener: %s : creating socket to listen on %s",
+ strerror (errno), m_BindAddr_str);
+
/* set so_reuseaddr to avoid 'address in use' */
int on = 1;
- iret = setsockopt (m_Socket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+ iret = setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
ASSERT ((iret == 0), "%s: setting SO_REUSEADDR on socket=%d",
- strerror (errno), m_Socket);
+ strerror (errno), sock);
+
/* bind the socket to an interface */
struct sockaddr_in saddr;
saddr.sin_family = AF_INET;
saddr.sin_port = htons (port);
saddr.sin_addr.s_addr = ip_addr.s_addr;
- iret = bind (m_Socket, (struct sockaddr *)&saddr, sizeof (saddr));
- if (iret == -1)
- {
- close (m_Socket);
- THROW (RunTimeError,
- "TCPListener: %s : binding socket=%u to %s",
- strerror (errno), m_Socket, m_BindAddr_str);
- }
+ iret = bind (sock, (struct sockaddr *)&saddr, sizeof (saddr));
+ ASSERT ((iret == 0), "TCPListener: %s : binding socket=%u to %s",
+ strerror (errno), sock, m_BindAddr_str);
+
/* put the socket on listen mode */
- iret = listen (m_Socket, 5);
- if (iret == -1)
- {
- close (m_Socket);
- THROW (RunTimeError,
- "TCPListener: %s : putting socket=%u to listen on %s",
- strerror (errno), m_Socket, m_BindAddr_str);
- }
+ iret = listen (sock, 5);
+ ASSERT ((iret == 0), "TCPListener: %s : putting socket=%u to listen on %s",
+ strerror (errno), sock, m_BindAddr_str);
+
/* put the socket on non-blocking mode so that we can pass it on to
the reactor */
- SetFDAsNonBlocking (m_Socket);
-
- /* register the non-blocking FD with the reactor */
- m_ReactorDeferred = m_Reactor->OnReadable (m_Socket);
- m_ReactorDeferred->OnEvent (TCPListener::handleNewConnection, (void *)this);
+ SetFDAsNonBlocking (sock);
+ Fd (sock);
+
+ /* hook ourselves to the reactor */
+ m_Reactor->addReader (this);
}
@@ -171,20 +117,16 @@
* \details
*/
void
-TCPListener::handleNewConnection (void *obj)
+TCPListener::Readable (void)
{
- ASSERT ((obj != NULL), "checking parameters");
-
int conn, ret;
struct sockaddr_in addr;
socklen_t addrlen;
- Protocol *proto;
- TCPListener *pthis = (TCPListener *) obj;
while (1)
{
addrlen = sizeof (struct sockaddr_in);
- conn = accept (pthis->m_Socket, (struct sockaddr *)&addr, &addrlen);
+ conn = accept (Fd(), (struct sockaddr *)&addr, &addrlen);
if (conn == -1)
{
if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
@@ -192,59 +134,46 @@
if ((errno == EINTR) || (errno == ECONNABORTED))
{
ERR ("non-fatal: %s: accepting connections on %s",
- strerror(errno), pthis->m_BindAddr_str);
+ strerror(errno), m_BindAddr_str);
return;
}
ERR ("%s: accepting connections on %s",
- strerror(errno), pthis->m_BindAddr_str);
+ strerror(errno), m_BindAddr_str);
ERR ("**FATAL** I am silently unregistering **FATAL**");
ERR ("**FATAL** I very definitely am lost :( **FATAL**");
- pthis->m_Reactor->UnRegister (pthis->m_ReactorDeferred);
+ m_Reactor->removeReader (this);
return;
}
char client[64];
sprintf (client, "%s:%d", inet_ntoa (addr.sin_addr), addr.sin_port);
- LOG3 ("incoming connection from %s on %s", client, pthis->m_BindAddr_str);
+ LOG3 ("incoming connection from %s on %s", client, m_BindAddr_str);
/* See if we need TCP_NODELAY, and configure it */
- if (pthis->m_bSetupNoDelay == true)
+ if (m_bSetupNoDelay == true)
{
int optval = 1;
ret = setsockopt (conn, IPPROTO_TCP, TCP_NODELAY, (void *)&optval,
sizeof (optval));
- if (ret == -1)
- {
- THROW (RunTimeError,
- "setting up TCP_NODELAY on fd=%d failed with %s",
- conn, strerror (errno));
- }
+ ASSERT ((ret == 0), "setting up TCP_NODELAY on fd=%d failed with %s",
+ conn, strerror (errno));
}
/* create a transport */
TCPTransport *trans;
- trans = new TCPTransport (pthis->m_Reactor, conn);
+ trans = new TCPTransport (m_Reactor, conn);
/* create a protocol using the factory */
- proto = pthis->m_Factory->GetProtocol (trans);
- proto->BuildProtocol ();
+ StreamProtocol *proto;
+ proto = m_Factory->GetProtocol (trans);
+
+ /* attach the protocol to the transport */
+ trans->setProtocol (proto);
}
}
-/**
- * \brief set the socket as TCP_NODELAY
- *
- * \details This method disables the Nagle algorithm on the connection
- * by setting TCP_NODELAY.
- */
-void
-TCPListener::SetupTCPNoDelay (void)
-{
- m_bSetupNoDelay = true;
-}
-
/*
Local Variables:
mode: c++
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:36:35
|
Revision: 34
http://asycxx.svn.sourceforge.net/asycxx/?rev=34&view=rev
Author: joe_steeve
Date: 2009-04-08 07:36:33 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
moved oneliners in MsgHandler.cxx to MsgHandler.h
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/MsgHandler.h
Removed Paths:
-------------
trunk/src/MsgHandler.cxx
Modified: trunk/include/asycxx/MsgHandler.h
===================================================================
--- trunk/include/asycxx/MsgHandler.h 2009-04-08 07:35:50 UTC (rev 33)
+++ trunk/include/asycxx/MsgHandler.h 2009-04-08 07:36:33 UTC (rev 34)
@@ -26,19 +26,26 @@
* \brief The interface of a MsgHandler
*/
-class MsgHandler
+namespace asycxx
{
-public:
- MsgHandler ();
- virtual ~MsgHandler ();
+ class MsgHandler
+ {
+ public:
+ MsgHandler () { m_Bus = NULL; }
+ virtual ~MsgHandler () {}
- void SetMsgBus (MsgBus *bus);
- virtual Result GotMsg (DataBuffer *data) = 0;
+ void SetMsgBus (MsgBus *bus)
+ {
+ ASSERT ((bus != NULL), "cannot use a NULL MsgBus");
+ m_Bus = bus;
+ }
-protected:
- MsgBus *m_Bus;
-};
+ virtual RetCode GotMsg (DataBuffer *data) = 0;
+ protected:
+ MsgBus *m_Bus;
+ };
+}
#endif /* __HIPRO_ASYCXX__MSG_HANDLER_H__ */
/*
Deleted: trunk/src/MsgHandler.cxx
===================================================================
--- trunk/src/MsgHandler.cxx 2009-04-08 07:35:50 UTC (rev 33)
+++ trunk/src/MsgHandler.cxx 2009-04-08 07:36:33 UTC (rev 34)
@@ -1,47 +0,0 @@
-
-/********************************************************************
- * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
- * rights reserved.
- *
- * This program and the accompanying materials are made available
- * under the terms described in the LICENSE file which accompanies
- * this distribution. If the LICENSE file was not attached to this
- * distribution or for further clarifications, please contact
- * le...@hi....
- *
- *******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <asycxx-config.h>
-#endif
-
-#include "asycxx-common.h"
-#include <asycxx/Error.h>
-#include <asycxx/MsgHandler.h>
-
-MsgHandler::MsgHandler ()
-{
- m_Bus = NULL;
-}
-
-
-MsgHandler::~MsgHandler ()
-{
-}
-
-
-void
-MsgHandler::SetMsgBus (MsgBus *bus)
-{
- ASSERT ((bus != NULL), "cannot use a NULL MsgBus");
- m_Bus = bus;
-}
-
-/*
- Local Variables:
- mode: c++
- indent-tabs-mode: nil
- tab-width: 4
- c-file-style: "gnu"
- End:
-*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:35:52
|
Revision: 33
http://asycxx.svn.sourceforge.net/asycxx/?rev=33&view=rev
Author: joe_steeve
Date: 2009-04-08 07:35:50 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
moved class:MsgBus into 'asycxx' namespace
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/MsgBus.h
trunk/src/MsgBus.cxx
Modified: trunk/include/asycxx/MsgBus.h
===================================================================
--- trunk/include/asycxx/MsgBus.h 2009-04-08 07:35:06 UTC (rev 32)
+++ trunk/include/asycxx/MsgBus.h 2009-04-08 07:35:50 UTC (rev 33)
@@ -27,21 +27,25 @@
* time of construction. This class assumes ownership of the
* MsgHandler and destroys it when this is destroyed.
*/
-class MsgHandler;
-class MsgBus
+namespace asycxx
{
-public:
- MsgBus (MsgHandler *handler);
- virtual ~MsgBus ();
+ class MsgHandler;
- virtual void SendMsg (DataBuffer *msg) = 0;
+ class MsgBus
+ {
+ public:
+ MsgBus (MsgHandler *handler);
+ virtual ~MsgBus ();
-protected:
- MsgHandler *m_Handler;
+ virtual void SendMsg (DataBuffer *msg) = 0;
-};
+ protected:
+ MsgHandler *m_Handler;
+ };
+}
+
#endif /* __HIPRO_ASYCXX__MSG_BUS_H__ */
/*
Modified: trunk/src/MsgBus.cxx
===================================================================
--- trunk/src/MsgBus.cxx 2009-04-08 07:35:06 UTC (rev 32)
+++ trunk/src/MsgBus.cxx 2009-04-08 07:35:50 UTC (rev 33)
@@ -19,6 +19,8 @@
#include <asycxx/MsgBus.h>
#include <asycxx/MsgHandler.h>
+using namespace asycxx;
+
MsgBus::MsgBus (MsgHandler *handler)
{
ASSERT ((handler != NULL), "cannot use a NULL MsgHandler");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:35:08
|
Revision: 32
http://asycxx.svn.sourceforge.net/asycxx/?rev=32&view=rev
Author: joe_steeve
Date: 2009-04-08 07:35:06 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
refactored class:TCPTransport to derive from StreamTransport
Since most of the I/O code is the same as the one in StreamTransport,
this class only provides ways to close the transport properly
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/TCPTransport.h
trunk/src/TCPTransport.cxx
Modified: trunk/include/asycxx/TCPTransport.h
===================================================================
--- trunk/include/asycxx/TCPTransport.h 2009-04-08 07:34:17 UTC (rev 31)
+++ trunk/include/asycxx/TCPTransport.h 2009-04-08 07:35:06 UTC (rev 32)
@@ -18,21 +18,23 @@
#include "Error.h"
#include "Reactor.h"
#include "DataBuffer.h"
-#include "Transport.h"
+#include "StreamTransport.h"
-class TCPTransport : public Transport
+namespace asycxx
{
-public:
- TCPTransport (Reactor *reactor, int fd);
- virtual ~TCPTransport ();
-
-protected:
- Result doWrite (void);
- Result doRead (DataBuffer *data);
- void doDisconnect (void);
-
-};
+ class TCPTransport : public StreamTransport
+ {
+ public:
+ TCPTransport (Reactor *reactor, int fd) : StreamTransport (reactor, fd) {}
+ virtual ~TCPTransport ();
+ /* methods to satisfy the 'Transport' interface */
+ void Close (void);
+ void closeReader (void);
+ void closeWriter (void);
+ };
+}
+
#endif /* __HIPRO_ASYCXX__TCP_TRANSPORT_H__ */
/*
Modified: trunk/src/TCPTransport.cxx
===================================================================
--- trunk/src/TCPTransport.cxx 2009-04-08 07:34:17 UTC (rev 31)
+++ trunk/src/TCPTransport.cxx 2009-04-08 07:35:06 UTC (rev 32)
@@ -28,140 +28,59 @@
#include <asycxx/Protocol.h>
#include <asycxx/TCPTransport.h>
+using namespace asycxx;
-TCPTransport::TCPTransport (Reactor *reactor, int fd)
- : Transport (reactor, fd)
+
+TCPTransport::~TCPTransport ()
{
+ Close ();
}
-TCPTransport::~TCPTransport ()
+void
+TCPTransport::Close (void)
{
+ closeReader ();
+ closeWriter ();
}
-Result
-TCPTransport::doRead (DataBuffer *data)
+void
+TCPTransport::closeReader (void)
{
- ASSERT ((data != NULL), "checking parameters");
- ssize_t rlen;
-
- __doRead__again:
- rlen = read (m_Fd, data->Data(), data->BufferLen());
- if (rlen == -1)
+ stopReading(); // first unhook from the reactor
+ if (isReaderOpen())
{
- if (errno == EINTR)
- {
- goto __doRead__again;
- }
- else if (errno == EAGAIN)
+ int ret;
+ ret = shutdown (Fd(), SHUT_RD);
+ if (ret == -1)
{
- data->Len(0);
- return Result_Success;
+ ERR ("%s: shutting-down read end of TCP connection, %d",
+ strerror(errno), Fd());
}
- else
- {
- ERR ("%s: reading from fd=%d", strerror(errno), m_Fd);
- return Result_Error;
- }
+ markReaderAsClosed();
}
-
- /* check for end-of-file */
- if (rlen == 0)
- {
- ERR ("EoF on fd=%d", m_Fd);
- return Result_Error;
- }
- data->Len(rlen);
-
- return Result_Success;
}
-Result
-TCPTransport::doWrite (void)
+void
+TCPTransport::closeWriter (void)
{
- ssize_t wrote;
- ssize_t wlen, to_wlen;
- DataBuffer *data;
- void *bfr;
-
- wrote = 0;
- while (m_writeBuffers.size() > 0)
+ stopWriting (); // first unhook from the reactor
+ if (isWriterOpen())
{
- data = m_writeBuffers[0];
- to_wlen = data->Len() - data->Processed();
- bfr = data->UnProcessed ();
-
- wlen = write (m_Fd, bfr, to_wlen);
- if (wlen == -1)
+ int ret;
+ ret = shutdown (Fd(), SHUT_WR);
+ if (ret == -1)
{
- if (errno == EINTR) { continue; }
- else if (errno == EAGAIN) { return Result_Pending; }
- else
- {
- ERR ("%s: writing DataBuffer<%p>::data<%p>,len=%d to fd=%d",
- strerror (errno), data, bfr, to_wlen, m_Fd);
- return Result_Error;
- }
+ ERR ("%s: shutting-down write end of TCP connection, %d",
+ strerror(errno), Fd());
}
-
- /* update pointers */
- data->Processed((data->Processed() + wlen));
- wrote += wlen;
-
- if (data->Processed() == data->Len())
- {
- m_writeBuffers.pop_front();
- data->DisOwn();
- }
+ markWriterAsClosed();
}
-
- return Result_Success;
}
-void
-TCPTransport::doDisconnect (void)
-{
- int ret;
- ret = shutdown (m_Fd, SHUT_RDWR);
- if (ret == -1)
- {
- ERR ("%s: shutting down connection", strerror(errno));
- }
-
-}
-
-// Result
-// TCPTransport::configureTCPNoDelay (void)
-// {
-// /** \todo using setsockopt should configure TCP_NODELAY. This disables
-// nagle's algorithm and increase small packets on the network. */
-// ASSERT ((m_Fd != -1), "sanity checks");
-
-// int iret;
-// int optval = 1;
-// iret = setsockopt (m_Fd, IPPROTO_TCP, TCP_NODELAY, (void *)&optval,
-// sizeof (optval));
-// if (iret != 0)
-// {
-
-// }
-// }
-
-
-// Result
-// TCPTransport::configureTCPKeelAlive (int idle_time, int probe_count,
-// int probe_interval)
-// {
-// /** \todo using setsockopt should configure TCP_KEEPCNT */
-
-// /** \todo using setsockopt should configure TCP_KEEPIDLE */
-
-// /** \todo using setsockopt should configure TCP_KEEPINTVL */
-// }
-
/*
Local Variables:
mode: c++
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: Joe S. <js...@hi...> - 2009-04-08 07:34:40
|
I have heavily refactored and redesigned various parts of asycxx. Sorry for the commit bomb that is going to come through :P Summary: - Deferreds are gone for ever - We have Stream based transports, protocols and factories now. These are different from 'datagram' based transports, protocols and factories. - Anything that the reactor can wait on is called a 'Selectable'. So, transports and listeners are not 'Selectable's -- Joe Steeve HiPro IT Solutions Pvt. Ltd. http://hipro.co.in/ |
|
From: <joe...@us...> - 2009-04-08 07:34:23
|
Revision: 31
http://asycxx.svn.sourceforge.net/asycxx/?rev=31&view=rev
Author: joe_steeve
Date: 2009-04-08 07:34:17 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
added class:StreamProtocolFactory to produce 'StreamProtocols'
From: Joe Steeve <js...@hi...>
Added Paths:
-----------
trunk/include/asycxx/StreamProtocolFactory.h
Added: trunk/include/asycxx/StreamProtocolFactory.h
===================================================================
--- trunk/include/asycxx/StreamProtocolFactory.h (rev 0)
+++ trunk/include/asycxx/StreamProtocolFactory.h 2009-04-08 07:34:17 UTC (rev 31)
@@ -0,0 +1,47 @@
+
+/********************************************************************
+ * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
+ * rights reserved.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms described in the LICENSE file which accompanies
+ * this distribution. If the LICENSE file was not attached to this
+ * distribution or for further clarifications, please contact
+ * le...@hi....
+ *
+ *******************************************************************/
+
+#ifndef __HIPRO_ASYCXX__STREAM_PROTOCOL_FACTORY_H__
+#define __HIPRO_ASYCXX__STREAM_PROTOCOL_FACTORY_H__
+
+#ifdef HAVE_CONFIG_H
+#include <asycxx-config.h>
+#endif
+
+#include "Error.h"
+#include "Reactor.h"
+#include "ProtocolFactory.h"
+#include "StreamProtocol.h"
+#include "StreamTransport.h"
+
+namespace asycxx
+{
+ class StreamProtocolFactory : public ProtocolFactory
+ {
+ public:
+ StreamProtocolFactory (Reactor *reactor) : ProtocolFactory (reactor) {}
+ virtual ~StreamProtocolFactory () {}
+
+ virtual StreamProtocol *GetProtocol (StreamTransport *trans) = 0;
+ };
+}
+#endif /* __HIPRO_ASYCXX__STREAM_PROTOCOL_FACTORY_H__ */
+
+/*
+ Local Variables:
+ mode: c++
+ indent-tabs-mode: nil
+ tab-width: 4
+ c-file-style: "gnu"
+ End:
+*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:33:47
|
Revision: 30
http://asycxx.svn.sourceforge.net/asycxx/?rev=30&view=rev
Author: joe_steeve
Date: 2009-04-08 07:33:40 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
added class:StreamProtocol to provide a base for 'stream' protocols
This contains code that was previously in class:Protocol. This class
should serve as a base for all 'stream'/'connection' based protocols.
From: Joe Steeve <js...@hi...>
Added Paths:
-----------
trunk/include/asycxx/StreamProtocol.h
trunk/src/StreamProtocol.cxx
Added: trunk/include/asycxx/StreamProtocol.h
===================================================================
--- trunk/include/asycxx/StreamProtocol.h (rev 0)
+++ trunk/include/asycxx/StreamProtocol.h 2009-04-08 07:33:40 UTC (rev 30)
@@ -0,0 +1,77 @@
+
+/********************************************************************
+ * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
+ * rights reserved.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms described in the LICENSE file which accompanies
+ * this distribution. If the LICENSE file was not attached to this
+ * distribution or for further clarifications, please contact
+ * le...@hi....
+ *
+ *******************************************************************/
+
+#ifndef __HIPRO_ASYCXX__STREAM_PROTOCOL_H__
+#define __HIPRO_ASYCXX__STREAM_PROTOCOL_H__
+
+#ifdef HAVE_CONFIG_H
+#include <asycxx-config.h>
+#endif
+
+#include "Error.h"
+#include "Reactor.h"
+#include "DataBuffer.h"
+#include "Protocol.h"
+
+
+namespace asycxx
+{
+ class StreamProtocolFactory;
+ class StreamTransport;
+
+ class StreamProtocol : public Protocol
+ {
+ public:
+ StreamProtocol (Reactor *reactor, StreamProtocolFactory *factory,
+ StreamTransport *transport);
+ virtual ~StreamProtocol () {}
+
+ /**
+ * \brief Called when there is data available
+ *
+ * \details This method is called by the attached
+ * 'StreamTransport' when there is data available. The given
+ * 'DataBuffer' is owned by the 'StreamTransport'. The 'Protocol'
+ * should claim it if it needs it for further processing.
+ */
+ virtual void DataAvailable (DataBuffer *data);
+
+ /**
+ * \brief Called when the connection is lost
+ *
+ * \details This method is called by the attached
+ * 'StreamTransport' when it loses connection. The 'Protocol' will
+ * be deleted after this.
+ */
+ virtual void ConnectionLost (void);
+
+ /**
+ * \brief get the current Transport
+ */
+ StreamTransport * getTransport (void) { return m_Transport; }
+
+ private:
+ StreamTransport * m_Transport;
+ };
+}
+
+#endif /* __HIPRO_ASYCXX__STREAM_PROTOCOL_H__ */
+
+/*
+ Local Variables:
+ mode: c++
+ indent-tabs-mode: nil
+ tab-width: 4
+ c-file-style: "gnu"
+ End:
+*/
Added: trunk/src/StreamProtocol.cxx
===================================================================
--- trunk/src/StreamProtocol.cxx (rev 0)
+++ trunk/src/StreamProtocol.cxx 2009-04-08 07:33:40 UTC (rev 30)
@@ -0,0 +1,58 @@
+
+/********************************************************************
+ * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
+ * rights reserved.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms described in the LICENSE file which accompanies
+ * this distribution. If the LICENSE file was not attached to this
+ * distribution or for further clarifications, please contact
+ * le...@hi....
+ *
+ *******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <asycxx-config.h>
+#endif
+
+
+#include "asycxx-common.h"
+#include <asycxx/Error.h>
+#include <asycxx/StreamProtocol.h>
+#include <asycxx/StreamTransport.h>
+
+using namespace asycxx;
+
+StreamProtocol::StreamProtocol (Reactor *reactor,
+ StreamProtocolFactory *factory,
+ StreamTransport *transport)
+ : Protocol (reactor, (ProtocolFactory *)factory)
+{
+ ASSERT ((transport != NULL), "NULL transport?");
+ m_Transport = transport;
+ m_Transport->startReading();
+}
+
+/* default protocol methods. should be overridden by the derived
+ classes */
+void
+StreamProtocol::DataAvailable (DataBuffer *data)
+{
+ ERR ("data-available but not handled. lame protocol");
+}
+
+
+void
+StreamProtocol::ConnectionLost (void)
+{
+ ERR ("connection-lost not handled. lame protocol");
+}
+
+/*
+ Local Variables:
+ mode: c++
+ indent-tabs-mode: nil
+ tab-width: 4
+ c-file-style: "gnu"
+ End:
+*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:33:03
|
Revision: 29
http://asycxx.svn.sourceforge.net/asycxx/?rev=29&view=rev
Author: joe_steeve
Date: 2009-04-08 07:32:54 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
converted class:Protocol to a simple base class
Since 'stream' protocols and 'datagram' protocols behave completely
differently, the class:Protocol now contains only the bare minimum.
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/Protocol.h
trunk/src/Protocol.cxx
Modified: trunk/include/asycxx/Protocol.h
===================================================================
--- trunk/include/asycxx/Protocol.h 2009-04-08 07:32:11 UTC (rev 28)
+++ trunk/include/asycxx/Protocol.h 2009-04-08 07:32:54 UTC (rev 29)
@@ -17,37 +17,54 @@
#include "Error.h"
#include "Reactor.h"
#include "DataBuffer.h"
-#include "Transport.h"
-#include "Factory.h"
#define ASYCXX_DEFAULT_PROTOCOL_BUFSIZE 1024
-class Protocol
+namespace asycxx
{
-public:
- Protocol (Reactor *reactor, Factory *factory, Transport *transport);
- virtual ~Protocol ();
+ class ProtocolFactory;
- void BuildProtocol (void);
- /* Methods exposed for the 'transport' to send msgs to the
- Protocol */
- virtual void DataAvailable (DataBuffer *data);
- virtual void ConnectionLost (void);
- virtual void ReadTimeout (h_msecs_t excess_time);
- virtual void ReadError (void);
- virtual void WriteTimeout (h_msecs_t excess_time);
- virtual void WriteError (void);
-
-protected:
- Reactor *m_Reactor;
- Factory *m_Factory;
- Transport *m_Transport;
+ class Protocol
+ {
+ public:
+ Protocol (Reactor *reactor, ProtocolFactory *factory);
+ virtual ~Protocol () {}
- /* Interface that should be implemented by all protocol
- sub-classes */
- virtual Result InitProtocol (void);
-};
+ /**
+ * \brief Get the 'Reactor' that is being used
+ */
+ Reactor * getReactor (void) { return m_Reactor; }
+ /**
+ * \brief Get the 'Factory' that created this 'Protocol'
+ */
+ ProtocolFactory * getFactory (void) { return m_Factory; }
+
+ /**
+ * \brief Method used by the 'Transport' to notify read-timeout
+ */
+ virtual void ReadTimeout (asycxx_msecs_t excess_time);
+
+ /**
+ * \brief Method used by the 'Transport' to notify read-error
+ */
+ virtual void ReadError (void);
+
+ /**
+ * \brief Method used by the 'Transport' to notify write-timeout
+ */
+ virtual void WriteTimeout (asycxx_msecs_t excess_time);
+
+ /**
+ * \brief Method used by the 'Transport' to notify write-error
+ */
+ virtual void WriteError (void);
+
+ private:
+ Reactor *m_Reactor;
+ ProtocolFactory *m_Factory;
+ };
+}
#endif /* __HIPRO_ASYCXX__PROTOCOL_H__ */
/*
Modified: trunk/src/Protocol.cxx
===================================================================
--- trunk/src/Protocol.cxx 2009-04-08 07:32:11 UTC (rev 28)
+++ trunk/src/Protocol.cxx 2009-04-08 07:32:54 UTC (rev 29)
@@ -20,63 +20,23 @@
#include <asycxx/Error.h>
#include <asycxx/Protocol.h>
+using namespace asycxx;
-Protocol::Protocol (Reactor *reactor, Factory *factory, Transport *transport)
+Protocol::Protocol (Reactor *reactor, ProtocolFactory *factory)
{
ASSERT ((reactor != NULL), "checking parameters");
ASSERT ((factory != NULL), "checking parameters");
- ASSERT ((transport != NULL), "checking parameters");
-
+
m_Reactor = reactor;
m_Factory = factory;
- m_Transport = transport;
- m_Transport->SetProtocol (this);
}
-Protocol::~Protocol ()
-{
-}
-void
-Protocol::BuildProtocol (void)
-{
- Result ret;
- ret = InitProtocol ();
- if (ret == Result_Success)
- {
- return;
- }
-
- /* looks like init-protocol was not overloaded. should configure
- sane defaults */
-}
-
-Result
-Protocol::InitProtocol (void)
-{
- return Result_Error;
-}
-
-
/* default protocol methods. should be overridden by the derived
classes */
void
-Protocol::DataAvailable (DataBuffer *data)
+Protocol::ReadTimeout (asycxx_msecs_t excess_time)
{
- ERR ("data-available but not handled. lame protocol");
-}
-
-
-void
-Protocol::ConnectionLost (void)
-{
- ERR ("connection-lost not handled. lame protocol");
-}
-
-
-void
-Protocol::ReadTimeout (h_msecs_t excess_time)
-{
ERR ("read timed out (excess=%lld) but not handled. lame protocol",
excess_time);
}
@@ -88,7 +48,7 @@
}
void
-Protocol::WriteTimeout (h_msecs_t excess_time)
+Protocol::WriteTimeout (asycxx_msecs_t excess_time)
{
ERR ("write timed out (excess=%lld) but not handled. lame protocol",
excess_time);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:32:12
|
Revision: 28
http://asycxx.svn.sourceforge.net/asycxx/?rev=28&view=rev
Author: joe_steeve
Date: 2009-04-08 07:32:11 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
moved one-liners in Listener.cxx to Listener.h
* moved class:Listeners to 'asycxx' namespace
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/Listener.h
Removed Paths:
-------------
trunk/src/Listener.cxx
Modified: trunk/include/asycxx/Listener.h
===================================================================
--- trunk/include/asycxx/Listener.h 2009-04-08 07:31:24 UTC (rev 27)
+++ trunk/include/asycxx/Listener.h 2009-04-08 07:32:11 UTC (rev 28)
@@ -16,16 +16,18 @@
#include "Error.h"
#include "Reactor.h"
+#include "Selectable.h"
-class Listener
+namespace asycxx
{
-
-public:
- Listener ();
- virtual ~Listener ();
+ class Listener : public Selectable
+ {
+ public:
+ Listener () {}
+ virtual ~Listener () {}
+ };
+}
-};
-
#endif /* __HIPRO_ASYCXX__LISTENER_H__ */
/*
Deleted: trunk/src/Listener.cxx
===================================================================
--- trunk/src/Listener.cxx 2009-04-08 07:31:24 UTC (rev 27)
+++ trunk/src/Listener.cxx 2009-04-08 07:32:11 UTC (rev 28)
@@ -1,41 +0,0 @@
-
-/********************************************************************
- * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
- * rights reserved.
- *
- * This program and the accompanying materials are made available
- * under the terms described in the LICENSE file which accompanies
- * this distribution. If the LICENSE file was not attached to this
- * distribution or for further clarifications, please contact
- * le...@hi....
- *
- *******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <asycxx-config.h>
-#endif
-
-
-#include "asycxx-common.h"
-#include <asycxx/Error.h>
-#include <asycxx/Listener.h>
-
-
-Listener::Listener ()
-{
-
-}
-
-Listener::~Listener ()
-{
-
-}
-
-/*
- Local Variables:
- mode: c++
- indent-tabs-mode: nil
- tab-width: 4
- c-file-style: "gnu"
- End:
-*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:31:26
|
Revision: 27
http://asycxx.svn.sourceforge.net/asycxx/?rev=27&view=rev
Author: joe_steeve
Date: 2009-04-08 07:31:24 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
added class:StreamTransport to hold all connection oriented Transports
From: Joe Steeve <js...@hi...>
Added Paths:
-----------
trunk/include/asycxx/StreamTransport.h
trunk/src/StreamTransport.cxx
Added: trunk/include/asycxx/StreamTransport.h
===================================================================
--- trunk/include/asycxx/StreamTransport.h (rev 0)
+++ trunk/include/asycxx/StreamTransport.h 2009-04-08 07:31:24 UTC (rev 27)
@@ -0,0 +1,127 @@
+
+/********************************************************************
+ * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
+ * rights reserved.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms described in the LICENSE file which accompanies
+ * this distribution. If the LICENSE file was not attached to this
+ * distribution or for further clarifications, please contact
+ * le...@hi....
+ *
+ *******************************************************************/
+
+#ifndef __HIPRO_ASYCXX__STREAM_TRANSPORT_H__
+#define __HIPRO_ASYCXX__STREAM_TRANSPORT_H__
+
+#include "Error.h"
+#include "Transport.h"
+#include "DataBuffer.h"
+#include "StreamProtocol.h"
+
+#define ASYCXX_TRANSPORT_DEFAULT_READ_BUFSIZE 1024
+namespace asycxx
+{
+ class StreamTransport : public Transport
+ {
+ public:
+ /**
+ * \brief CTOR
+ *
+ * \param[in] reactor Pointer to a Reactor
+ * \param[in] fd A valid file-descriptor to build the transport on
+ */
+ StreamTransport (Reactor *reactor, int fd);
+ virtual ~StreamTransport ();
+
+ /**
+ * \brief Queues the provided data-buffer for writing
+ *
+ * \param[in] data The DataBuffer object that should be written
+ *
+ * \details This method queues the given DataBuffer to the
+ * m_writeBuffers queue. This queue is flushed out when the
+ * file-descriptor becomes writable next. This class assumes
+ * ownership of the provided DataBuffer.
+ */
+ void Write (DataBuffer *data);
+
+ /**
+ * \brief Mark the transport for destruction
+ *
+ * \details This method marks the transport for destruction. This
+ * should be used by the protocol to notify the transport to
+ * destory itself. The Transport will do the destruction once it
+ * regains control from the event handlers that it has called.
+ */
+ void loseConnection (void);
+
+ /**
+ * \brief set the size of the read-buffer
+ *
+ * \details This method configures the size of the read-buffer to
+ * the given size. This is an upper limit on the amount of data
+ * read at any given time. If available data is more than this
+ * length, then it is read in multiple parts (chunks).
+ */
+ void configureReadBufferSize (size_t len);
+
+ /**
+ * \brief configure a timeout for the 'wait for readable'
+ * operation
+ */
+ void configureReadTimeout (asycxx_msecs_t timeout);
+
+ /**
+ * \brief configure a timeout for the 'wait for writable'
+ * operation
+ */
+ void configureWriteTimeout (asycxx_msecs_t timeout);
+
+ /**
+ * \brief Attach the given protocol to the Transport
+ */
+ StreamProtocol * getProtocol (void)
+ {
+ return (StreamProtocol *) Transport::getProtocol();
+ }
+
+ /**
+ * \brief Get the currently attached protocol
+ */
+ void setProtocol (StreamProtocol *protocol)
+ {
+ Transport::setProtocol ((Protocol *)protocol);
+ }
+
+ /* Methods to provide 'Selectable' interface. Lookup 'Selectable'
+ * for documentation */
+ virtual void Readable (void);
+ virtual void Writable (void);
+ virtual void Close (void);
+ virtual void closeReader (void);
+ virtual void closeWriter (void);
+
+ protected:
+ asycxx_msecs_t m_writeTimeout; /* the timeout used for writing */
+ asycxx_msecs_t m_readTimeout; /* the timeout used for reading */
+ size_t m_readBufSize; // max buffer size to read
+
+ std::list<DataBuffer *> m_writeBuffers;
+ bool m_bDisconnectAndDie;
+
+ /* methods to be implemented by the derived sub-classes */
+ virtual RetCode doWrite (void);
+ virtual RetCode doRead (DataBuffer *data);
+ };
+}
+#endif /* __HIPRO_ASYCXX__STREAM_TRANSPORT_H__ */
+
+/*
+ Local Variables:
+ mode: c++
+ indent-tabs-mode: nil
+ tab-width: 4
+ c-file-style: "gnu"
+ End:
+*/
Added: trunk/src/StreamTransport.cxx
===================================================================
--- trunk/src/StreamTransport.cxx (rev 0)
+++ trunk/src/StreamTransport.cxx 2009-04-08 07:31:24 UTC (rev 27)
@@ -0,0 +1,311 @@
+
+/********************************************************************
+ * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
+ * rights reserved.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms described in the LICENSE file which accompanies
+ * this distribution. If the LICENSE file was not attached to this
+ * distribution or for further clarifications, please contact
+ * le...@hi....
+ *
+ *******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <asycxx-config.h>
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+#include "asycxx-common.h"
+#include <asycxx/Error.h>
+#include <asycxx/StreamTransport.h>
+#include <asycxx/StreamProtocol.h>
+
+using namespace asycxx;
+
+
+/*
+ * CTOR
+ */
+StreamTransport::StreamTransport (Reactor *reactor, int fd)
+ : Transport (reactor, fd)
+{
+ m_bDisconnectAndDie = false;
+
+ /* default configuration */
+ configureReadTimeout (0L);
+ configureWriteTimeout (0L);
+ configureReadBufferSize (ASYCXX_TRANSPORT_DEFAULT_READ_BUFSIZE);
+}
+
+
+/*
+ * DTOR
+ */
+StreamTransport::~StreamTransport ()
+{
+ DataBuffer *data;
+
+ /* discard the DataBuffers in the pending queue */
+ std::list<DataBuffer *>::iterator it;
+ for (it = m_writeBuffers.begin(); it != m_writeBuffers.end(); it++)
+ {
+ data = *it;
+ ERR ("Transport<%p> dumping write-buffer <%p>, len=%d",
+ this, data->Data(), data->Len());
+ data->DisOwn ();
+ }
+}
+
+
+void
+StreamTransport::configureReadBufferSize (size_t len)
+{
+ ASSERT ((len != 0), "zero length read-buffer??");
+ m_readBufSize = len;
+}
+
+
+/* TODO: setup a timer to handle timeout and inform the protocol about
+ * the timeout */
+void
+StreamTransport::configureReadTimeout (asycxx_msecs_t timeout)
+{
+ m_readTimeout = timeout;
+}
+
+void
+StreamTransport::configureWriteTimeout (asycxx_msecs_t timeout)
+{
+ m_writeTimeout = timeout;
+}
+
+
+/* Method to Write a buffer. This method should queue the buffer for
+ * writing. The actual writing should happen later when the
+ * file-handle becomes writable. */
+void
+StreamTransport::Write (DataBuffer *data)
+{
+ ASSERT ((data != NULL), "given data-buffer is NULL");
+ /* If we are not on the reactor's writers list, then add ourselves
+ to the reactor's writers list */
+ startWriting();
+ /* add the DataBuffer to the queue */
+ m_writeBuffers.push_back (data);
+ /* assume ownership of the given data-buffer. we do this last so
+ that any exception in the middle does not cause a leak */
+ data->Own ();
+}
+
+
+/* Mark the transport for destruction */
+void
+StreamTransport::loseConnection (void)
+{
+ m_bDisconnectAndDie = true;
+}
+
+
+/* This method is called by the reactor when the transport becomes
+ readable */
+void
+StreamTransport::Readable (void)
+{
+ DataBuffer *data;
+ RetCode ret;
+ StreamProtocol *proto;
+ proto = getProtocol ();
+
+ /** \todo: should use ioctl(m_Fd, SIOCINQ) to find the amount of
+ * unread data in the socket and then construct the DataBuffer. This
+ * should be done in the 'doRead' coz, Transport does not know what
+ * kind of file-descriptor we have with us. */
+
+ /* Read till there is no more */
+ while (1)
+ {
+ data = new DataBuffer (m_readBufSize);
+
+ /* call the sub-classes read-method to fill up the
+ data-buffer */
+ ret = doRead (data);
+ if (ret != RetCode_Success)
+ {
+ /* reading from transport failed */
+ data->DisOwn ();
+ proto->ReadError ();
+ goto __handlelReadable__ScreamAndDie__;
+ }
+
+ if (data->Len() == 0)
+ {
+ /* If there is no more to read, then get out */
+ data->DisOwn ();
+ break;
+ }
+
+ /* give data-buffer to the protocol. after this point, the
+ Protocol takes responsibility for the data-buffer object */
+ proto->DataAvailable (data);
+ data->DisOwn ();
+
+ /* check whether we should die */
+ if (m_bDisconnectAndDie == true)
+ {
+ goto __handlelReadable__ScreamAndDie__;
+ }
+ }
+ return;
+
+ __handlelReadable__ScreamAndDie__ :
+ Close ();
+ proto->ConnectionLost ();
+ delete this;
+}
+
+
+/* This method is called by the reactor when a 'Selectable' becomes
+ * writable. */
+void
+StreamTransport::Writable (void)
+{
+ StreamProtocol *proto;
+ proto = getProtocol ();
+ RetCode ret;
+
+ /* call the base-class method to write the pending buffers */
+ ret = doWrite ();
+ if (ret == RetCode_Error)
+ {
+ /* writing to transport failed */
+ proto->WriteError ();
+ goto __handlelWritable__ScreamAndDie__;
+ }
+ if (ret == RetCode_Success)
+ {
+ /* nothing more to write */
+ stopWriting();
+ }
+ return;
+
+ __handlelWritable__ScreamAndDie__ :
+ Close ();
+ proto->ConnectionLost ();
+ delete this;
+}
+
+
+RetCode
+StreamTransport::doRead (DataBuffer *data)
+{
+ ASSERT ((data != NULL), "checking parameters");
+ ssize_t rlen;
+
+ __doRead__again:
+ rlen = read (Fd(), data->Data(), data->BufferLen());
+ if (rlen == -1)
+ {
+ if (errno == EINTR)
+ {
+ goto __doRead__again;
+ }
+ else if (errno == EAGAIN)
+ {
+ data->Len(0);
+ return RetCode_Success;
+ }
+ else
+ {
+ ERR ("%s: reading from fd=%d", strerror(errno), Fd());
+ return RetCode_Error;
+ }
+ }
+
+ /* check for end-of-file */
+ if (rlen == 0)
+ {
+ ERR ("EoF on fd=%d", Fd());
+ return RetCode_Error;
+ }
+ data->Len(rlen);
+
+ return RetCode_Success;
+}
+
+
+RetCode
+StreamTransport::doWrite (void)
+{
+ ssize_t wrote;
+ ssize_t wlen, to_wlen;
+ DataBuffer *data;
+ void *bfr;
+ std::list<DataBuffer *>::iterator it;
+
+ wrote = 0;
+ it = m_writeBuffers.begin();
+ while (it != m_writeBuffers.end())
+ {
+ data = *it;
+ to_wlen = data->Len() - data->Processed();
+ bfr = data->UnProcessed ();
+
+ wlen = write (Fd(), bfr, to_wlen);
+ if (wlen == -1)
+ {
+ if (errno == EINTR) { continue; }
+ else if (errno == EAGAIN) { return RetCode_Pending; }
+ else
+ {
+ ERR ("%s: writing DataBuffer<%p>::data<%p>,len=%d to fd=%d",
+ strerror (errno), data, bfr, to_wlen, Fd());
+ return RetCode_Error;
+ }
+ }
+
+ /* update pointers */
+ data->Processed((data->Processed() + wlen));
+ wrote += wlen;
+
+ if (data->Processed() == data->Len())
+ {
+ it = m_writeBuffers.erase(it);
+ data->DisOwn();
+ }
+ }
+
+ return RetCode_Success;
+}
+
+
+void
+StreamTransport::Close (void)
+{
+ ERR ("I got nothing special to close");
+}
+
+void
+StreamTransport::closeReader (void)
+{
+ ERR ("I dont know how to close the reader-end");
+}
+
+
+void
+StreamTransport::closeWriter (void)
+{
+ ERR ("I dont know how to close the writer-end");
+}
+
+/*
+ Local Variables:
+ mode: c++
+ indent-tabs-mode: nil
+ tab-width: 4
+ c-file-style: "gnu"
+ End:
+*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:30:41
|
Revision: 26
http://asycxx.svn.sourceforge.net/asycxx/?rev=26&view=rev
Author: joe_steeve
Date: 2009-04-08 07:30:35 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
all Transports are now 'Selectable's
This makes sure we can add the Transport directly to the Reactor
instead of having callbacks between them.
From: Joe Steeve <js...@hi...>
Modified Paths:
--------------
trunk/include/asycxx/Transport.h
trunk/src/Transport.cxx
Modified: trunk/include/asycxx/Transport.h
===================================================================
--- trunk/include/asycxx/Transport.h 2009-04-08 07:29:52 UTC (rev 25)
+++ trunk/include/asycxx/Transport.h 2009-04-08 07:30:35 UTC (rev 26)
@@ -14,66 +14,109 @@
#ifndef __HIPRO_ASYCXX__TRANSPORT_H__
#define __HIPRO_ASYCXX__TRANSPORT_H__
+#include <list>
-#include <deque>
-
#include "Error.h"
#include "Reactor.h"
#include "DataBuffer.h"
+#include "Selectable.h"
-class Protocol;
-
-#define ASYCXX_TRANSPORT_DEFAULT_READ_BUFSIZE 1024
-class Transport
+namespace asycxx
{
+ class Protocol;
-public:
- Transport (Reactor *reactor, int fd);
- virtual ~Transport ();
+ class Transport : public Selectable
+ {
+ public:
+ /**
+ * \brief CTOR
+ *
+ * \param[in] reactor Pointer to a Reactor
+ * \param[in] fd A valid file-descriptor to build the transport on
+ */
+ Transport (Reactor *reactor, int fd);
+ virtual ~Transport ();
- /* method to write to the transport */
- void Write (DataBuffer *data);
- /* method to disconnect the transport and mark for destruction */
- void LoseConnection (void);
+ /**
+ * \brief Sets the transport ready for reading
+ */
+ void startReading (void);
- /* methods to configure the transport */
- void configureReadTimeout (h_msecs_t timeout);
- void configureWriteTimeout (h_msecs_t timeout);
- void configureReadBufferSize (size_t len);
+ /**
+ * \brief Sets the transport to stop reading
+ */
+ void stopReading (void);
- /* accessors */
- int FD (void) { return m_Fd; }
- Protocol * GetProtocol (void);
- void SetProtocol (Protocol *protocol);
-
-protected:
- Reactor *m_Reactor;
- Protocol *m_Protocol;
- int m_Fd;
+ /**
+ * \brief Sets the transport ready for writing
+ */
+ void startWriting (void);
- size_t m_readBufSize;
- h_msecs_t m_writeTimeout; /* the timeout used for reading */
- Deferred *m_readDefer; /* deferred to handle reading */
- Deferred *m_writeDefer; /* deferred to handle writing */
- std::deque<DataBuffer *> m_writeBuffers;
- bool m_bDisconnectAndDie;
+ /**
+ * \brief Sets the transport to stop writing
+ */
+ void stopWriting (void);
- /* methods to be implemented by the derived sub-classes */
- virtual Result doWrite (void) = 0;
- virtual Result doRead (DataBuffer *data) = 0;
- virtual void doDisconnect (void) = 0;
+ /**
+ * \brief Attach the given protocol to the Transport
+ */
+ Protocol * getProtocol (void) { return m_Protocol; }
- /* handler methods */
- static void handleReadable (void *obj);
- static void handleReadTimeout (void *obj, h_msecs_t excess_time);
- static void handleWritable (void *obj);
- static void handleWriteTimeout (void *obj, h_msecs_t excess_time);
+ /**
+ * \brief Get the currently attached protocol
+ */
+ void setProtocol (Protocol *protocol);
-private:
- void KillMeIfYouMust (void);
+ /**
+ * \brief Get the reactor to which the Transport is hooked to
+ */
+ Reactor * getReactor (void) { return m_Reactor; }
-};
+ /**
+ * \brief Query whether the 'read end' is open
+ */
+ bool isReaderOpen (void) { return m_bReaderOpen; }
+ /**
+ * \brief Query whether the 'write end' is open
+ */
+ bool isWriterOpen (void) { return m_bWriterOpen; }
+
+ /**
+ * \brief Close the transport completely
+ */
+ virtual void Close (void) = 0;
+
+ /**
+ * \brief close the read-end of the transport
+ */
+ virtual void closeReader (void) = 0;
+
+ /**
+ * \brief close the write-end of the transport
+ */
+ virtual void closeWriter (void) = 0;
+
+ protected:
+ /**
+ * \brief Mark that the reader has been closed
+ */
+ void markReaderAsClosed (void) { m_bReaderOpen = false; }
+
+ /**
+ * \brief Mark that the writer has been closed
+ */
+ void markWriterAsClosed (void) { m_bWriterOpen = false; }
+
+ private:
+ Reactor *m_Reactor;
+ Protocol *m_Protocol;
+ bool m_bAddedToReaders;
+ bool m_bAddedToWriters;
+ bool m_bReaderOpen;
+ bool m_bWriterOpen;
+ };
+}
#endif /* __HIPRO_ASYCXX__TRANSPORT_H__ */
/*
Modified: trunk/src/Transport.cxx
===================================================================
--- trunk/src/Transport.cxx 2009-04-08 07:29:52 UTC (rev 25)
+++ trunk/src/Transport.cxx 2009-04-08 07:30:35 UTC (rev 26)
@@ -22,333 +22,91 @@
#include <asycxx/Transport.h>
#include <asycxx/Protocol.h>
-/**
- * \brief ctor
- *
- * \param[in] reactor Pointer to a Reactor
- * \param[in] fd A valid file-descriptor to build the transport on
+
+using namespace asycxx;
+
+
+/*
+ * CTOR
*/
Transport::Transport (Reactor *reactor, int fd)
{
ASSERT ((reactor != NULL), "cannot marry a <NULL> Reactor");
ASSERT ((fd != -1), "bad file-descriptor. checking parameters");
- m_Reactor = reactor;
- m_Fd = fd;
- m_bDisconnectAndDie = false;
- /* set file-descriptor as non-blocking */
- SetFDAsNonBlocking (m_Fd);
+ /* initialize */
+ m_bAddedToReaders = false;
+ m_bAddedToWriters = false;
- /* default configuration */
- m_readDefer = NULL;
- m_writeDefer = NULL;
- configureReadTimeout (0L);
- configureWriteTimeout (0L);
- configureReadBufferSize (ASYCXX_TRANSPORT_DEFAULT_READ_BUFSIZE);
+ m_bReaderOpen = true;
+ m_bWriterOpen = true;
+
+ m_Reactor = reactor;
+ m_Protocol = NULL;
+
+ /* set file-descriptor as non-blocking */
+ SetFDAsNonBlocking (fd);
+ Fd (fd);
}
-/**
- * \brief dtor
- */
+/* DTOR */
Transport::~Transport ()
{
- DataBuffer *data;
-
- /* discard the DataBuffers in the pending queue */
- while (m_writeBuffers.size() > 0)
- {
- data = m_writeBuffers[0];
- ERR ("Transport<%p> dumping write-buffer <%p>, len=%d",
- this, data->Data(), data->Len());
- m_writeBuffers.pop_front();
- data->DisOwn();
- }
-
/* un-register from the reactor */
- if (m_readDefer != NULL)
- {
- m_Reactor->UnRegister (m_readDefer);
- }
- if (m_writeDefer != NULL)
- {
- m_Reactor->UnRegister (m_writeDefer);
- }
+ stopReading();
+ stopWriting();
- /* destroy the protocol */
- if (m_Protocol != NULL)
- {
- delete m_Protocol;
- }
-
- /* we own the fd that was given to us */
- close (m_Fd);
+ /* destroy the protocol. we own it. */
+ if (m_Protocol != NULL) { delete m_Protocol; }
}
-/* accessors for protocol */
-void
-Transport::SetProtocol (Protocol *protocol)
-{
- ASSERT ((protocol != NULL), "checking parameters");
- m_Protocol = protocol;
-}
-
-
-Protocol *
-Transport::GetProtocol (void)
-{
- ASSERT ((m_Protocol != NULL), "protocol not set.");
- return m_Protocol;
-}
-
-
-/**
- * \brief Configures the reading timeout
- *
- * \param[in] timeout timeout in milli-seconds
- *
- * \details This method sets a timeout for the reading.
- */
-void
-Transport::configureReadTimeout (h_msecs_t timeout)
-{
- if (m_readDefer != NULL)
+/* Methods to add/remove the transport from the readers/writers list
+ * of the reactor */
+void Transport::startReading (void)
+{
+ if (m_bAddedToReaders == false)
{
- m_Reactor->UnRegister (m_readDefer);
+ m_Reactor->addReader(this);
+ m_bAddedToReaders = true;
}
- if (timeout > 0L)
- {
- m_readDefer = m_Reactor->OnReadable (m_Fd, timeout);
- m_readDefer->OnTimeout (Transport::handleReadTimeout, this);
- }
- else
- {
- m_readDefer = m_Reactor->OnReadable (m_Fd);
- }
- m_readDefer->OnEvent (Transport::handleReadable, this);
}
-
-/**
- * \brief Configures the writing timeout
- *
- * \param[in] timeout timeout in milli-seconds
- *
- * \details This method sets a timeout for the writing. This timeout
- * becomes effective from the next write operation
- */
-void
-Transport::configureWriteTimeout (h_msecs_t timeout)
-{
- m_writeTimeout = timeout;
-}
-
-
-/**
- * \brief Configures the size of the read-buffer
- *
- * \param[in] len Number of bytes to set the read-buffer to
- *
- * \details This method sets the read-buffer to the given length. The
- * read-buffer-len is the maximum amount of data that can be read from
- * the transport at any time. The transport does not wait till the
- * buffer of read-buffer-len is full. When data is available, utmost
- * read-buffer-len bytes can be read from it. If more data is still
- * available, they'll be read only in the next read operation.
- */
-void
-Transport::configureReadBufferSize (size_t len)
-{
- ASSERT ((len != 0), "zero length read-buffer??");
- m_readBufSize = len;
-}
-
-
-/**
- * \brief Queues the provided data-buffer for writing
- *
- * \param[in] data The DataBuffer object that should be written
- *
- * \details This method queues the given DataBuffer to the
- * m_writeBuffers queue. This queue is flushed out when the
- * file-descriptor becomes writable next. This class assumes ownership
- * of the provided DataBuffer.
- */
-void
-Transport::Write (DataBuffer *data)
-{
- ASSERT ((m_Protocol != NULL), "no protocol attached");
- ASSERT ((data != NULL), "given data-buffer is NULL");
-
- /* If we are not listening for write-events already, then hook up
- with the reactor for writable events */
- if (m_writeDefer == NULL)
+void Transport::stopReading (void)
+{
+ if (m_bAddedToReaders == true)
{
- if (m_writeTimeout == 0L)
- {
- m_writeDefer = m_Reactor->OnWritable (m_Fd);
- }
- else
- {
- m_writeDefer = m_Reactor->OnWritable (m_Fd, m_writeTimeout);
- m_writeDefer->OnTimeout (Transport::handleWriteTimeout, this);
- }
- m_writeDefer->OnEvent (Transport::handleWritable, this);
+ m_Reactor->removeReader(this);
+ m_bAddedToReaders = false;
}
- /* add the DataBuffer to the queue */
- m_writeBuffers.push_back (data);
-
- /* assume ownership of the given data-buffer. we do this last so
- that any exception in the middle does not cause a leak */
- data->Own ();
}
-
-/**
- * \brief Mark the connection to be destroyed.
- *
- * \details This method marks the transport for destruction. This
- * should be used by the protocol to notify the transport to destory
- * itself. The Transport will do the destruction once it regains
- * control from the event handlers that it has called.
- */
-void
-Transport::LoseConnection (void)
-{
- ASSERT ((m_Protocol != NULL), "no protocol attached");
- m_bDisconnectAndDie = true;
-}
-
-
-/* handlers for reactor generated events */
-
-/** \todo: should use ioctl(m_Fd, SIOCINQ) to find the amount of
- unread data in the socket and then construct the DataBuffer. This
- should be done in the 'doRead' coz, Transport does not know what
- kind of file-descriptor we have with us. */
-void
-Transport::handleReadable (void *obj)
-{
- ASSERT ((obj != NULL), "checking parameters");
-
- DataBuffer *data;
- Result ret;
- Transport *trans = (Transport *) obj;
- ASSERT ((trans->m_Protocol != NULL), "no protocol attached");
-
- /* Read till there is no more */
- while (1)
+void Transport::startWriting (void)
+{
+ if (m_bAddedToWriters == false)
{
- data = new DataBuffer (trans->m_readBufSize);
-
- /* call the sub-classes read-method to fill up the
- data-buffer */
- ret = trans->doRead (data);
- if (ret != Result_Success)
- {
- /* reading from transport failed */
- data->DisOwn ();
- trans->m_Protocol->ReadError ();
- goto __handlelReadable__ScreamAndDie__;
- }
-
- if (data->Len() == 0)
- {
- /* If there is no more to read, then get out */
- data->DisOwn ();
- break;
- }
-
- /* give data-buffer to the protocol. after this point, the
- Protocol takes responsibility for the data-buffer object */
- trans->m_Protocol->DataAvailable (data);
- data->DisOwn ();
-
- /* check whether we should die */
- if (trans->m_bDisconnectAndDie == true)
- {
- goto __handlelReadable__ScreamAndDie__;
- }
+ m_Reactor->addWriter(this);
+ m_bAddedToWriters = true;
}
- return;
-
- __handlelReadable__ScreamAndDie__ :
- trans->doDisconnect ();
- trans->m_Protocol->ConnectionLost ();
- delete trans;
- return;
}
-
-void
-Transport::handleReadTimeout (void *obj, h_msecs_t excess_time)
-{
- ASSERT ((obj != NULL), "checking parameters");
- Transport *trans = (Transport *) obj;
- ASSERT ((trans->m_Protocol != NULL), "no protocol attached");
-
- /* notify read-timeout to the protocol */
- trans->m_Protocol->ReadTimeout (excess_time);
-
- if (trans->m_bDisconnectAndDie == true)
+void Transport::stopWriting (void)
+{
+ if (m_bAddedToWriters == true)
{
- goto __handlelReadTimeout__ScreamAndDie__;
+ m_Reactor->removeWriter(this);
+ m_bAddedToWriters = false;
}
-
- __handlelReadTimeout__ScreamAndDie__:
- trans->doDisconnect ();
- trans->m_Protocol->ConnectionLost ();
- delete trans;
- return;
}
-
-void
-Transport::handleWritable (void *obj)
+void Transport::setProtocol (Protocol *protocol)
{
- ASSERT ((obj != NULL), "checking parameters");
-
- Transport *trans = (Transport *) obj;
- ASSERT ((trans->m_Protocol != NULL), "no protocol attached");
-
- /* call the base-class method to write the pending buffers */
- Result ret;
- ret = trans->doWrite ();
- if (ret == Result_Error)
- {
- /* writing to transport failed */
- trans->m_Protocol->WriteError ();
- goto __handlelWritable__ScreamAndDie__;
- }
- if (ret == Result_Success)
- {
- /* nothing more to write */
- trans->m_Reactor->UnRegister (trans->m_writeDefer);
- trans->m_writeDefer = NULL;
- }
- return;
-
- __handlelWritable__ScreamAndDie__ :
- trans->doDisconnect ();
- trans->m_Protocol->ConnectionLost ();
- delete trans;
- return;
+ ASSERT ((protocol != NULL), "checking parameters");
+ m_Protocol = protocol;
}
-void
-Transport::handleWriteTimeout (void *obj, h_msecs_t excess_time)
-{
- ASSERT ((obj != NULL), "checking parameters");
-
- Transport *trans = (Transport *) obj;
- ASSERT ((trans->m_Protocol != NULL), "no protocol attached");
-
- /* notify write-timeout to the protocol */
- trans->m_Protocol->WriteTimeout (excess_time);
-}
-
/*
Local Variables:
mode: c++
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:29:53
|
Revision: 25
http://asycxx.svn.sourceforge.net/asycxx/?rev=25&view=rev
Author: joe_steeve
Date: 2009-04-08 07:29:52 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
added 'class:Selectable'
A 'Selectable' provides a basic interface that is required by a
'Reactor'
From: Joe Steeve <js...@hi...>
Added Paths:
-----------
trunk/include/asycxx/Selectable.h
Added: trunk/include/asycxx/Selectable.h
===================================================================
--- trunk/include/asycxx/Selectable.h (rev 0)
+++ trunk/include/asycxx/Selectable.h 2009-04-08 07:29:52 UTC (rev 25)
@@ -0,0 +1,67 @@
+
+/********************************************************************
+ * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
+ * rights reserved.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms described in the LICENSE file which accompanies
+ * this distribution. If the LICENSE file was not attached to this
+ * distribution or for further clarifications, please contact
+ * le...@hi....
+ *
+ *******************************************************************/
+
+#ifndef __HIPRO_ASYCXX__SELECTABLE_H__
+#define __HIPRO_ASYCXX__SELECTABLE_H__
+
+#include <unistd.h>
+
+namespace asycxx
+{
+ /**
+ * \class Selectable
+ *
+ * \brief An abstraction over a POSIX file-descriptor
+ *
+ * \details 'Selectable' is an abstraction over a POSIX
+ * file-descriptor. The 'Selectable' should be registered with a
+ * 'Reactor' in order to recieve notification when it becomes
+ * readable/writable.
+ */
+ class Selectable
+ {
+ public:
+ Selectable () { m_Fd = -1; }
+ virtual ~Selectable ()
+ {
+ if (m_Fd != -1)
+ {
+ // we own the file-descriptor, so lets close it
+ close (m_Fd);
+ m_Fd = -1;
+ }
+ }
+
+ int Fd (void) { return m_Fd; }
+
+ virtual void Readable (void) = 0;
+ virtual void Writable (void) = 0;
+
+ protected:
+ void Fd (int fd) { m_Fd = fd; }
+
+ private:
+ int m_Fd;
+ };
+};
+
+#endif /* __HIPRO_ASYCXX__SELECTABLE_H__ */
+
+/*
+ Local Variables:
+ mode: c++
+ indent-tabs-mode: nil
+ tab-width: 4
+ c-file-style: "gnu"
+ End:
+*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:29:18
|
Revision: 24
http://asycxx.svn.sourceforge.net/asycxx/?rev=24&view=rev
Author: joe_steeve
Date: 2009-04-08 07:29:15 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
refactored Factory to ProtocolFactory
* The 'Factory' class creates 'Protocol' objects. Refactored 'Factory'
to 'ProtocolFactory' to be more specific.
* Moved ProtocolFactory to 'asycxx' namespace
From: Joe Steeve <js...@hi...>
Added Paths:
-----------
trunk/include/asycxx/ProtocolFactory.h
trunk/src/ProtocolFactory.cxx
Removed Paths:
-------------
trunk/include/asycxx/Factory.h
trunk/src/Factory.cxx
Deleted: trunk/include/asycxx/Factory.h
===================================================================
--- trunk/include/asycxx/Factory.h 2009-04-08 07:28:20 UTC (rev 23)
+++ trunk/include/asycxx/Factory.h 2009-04-08 07:29:15 UTC (rev 24)
@@ -1,41 +0,0 @@
-
-/********************************************************************
- * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
- * rights reserved.
- *
- * This program and the accompanying materials are made available
- * under the terms described in the LICENSE file which accompanies
- * this distribution. If the LICENSE file was not attached to this
- * distribution or for further clarifications, please contact
- * le...@hi....
- *
- *******************************************************************/
-
-#ifndef __HIPRO_ASYCXX__FACTORY_H__
-#define __HIPRO_ASYCXX__FACTORY_H__
-
-#include "Error.h"
-#include "Reactor.h"
-#include "Transport.h"
-
-class Factory
-{
-public:
- Factory (Reactor *reactor);
- virtual ~Factory ();
- virtual Protocol *GetProtocol (Transport *trans) = 0;
-
-protected:
- Reactor *m_Reactor;
-};
-
-#endif /* __HIPRO_ASYCXX__FACTORY_H__ */
-
-/*
- Local Variables:
- mode: c++
- indent-tabs-mode: nil
- tab-width: 4
- c-file-style: "gnu"
- End:
-*/
Copied: trunk/include/asycxx/ProtocolFactory.h (from rev 23, trunk/include/asycxx/Factory.h)
===================================================================
--- trunk/include/asycxx/ProtocolFactory.h (rev 0)
+++ trunk/include/asycxx/ProtocolFactory.h 2009-04-08 07:29:15 UTC (rev 24)
@@ -0,0 +1,42 @@
+
+/********************************************************************
+ * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
+ * rights reserved.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms described in the LICENSE file which accompanies
+ * this distribution. If the LICENSE file was not attached to this
+ * distribution or for further clarifications, please contact
+ * le...@hi....
+ *
+ *******************************************************************/
+
+#ifndef __HIPRO_ASYCXX__PROTOCOL_FACTORY_H__
+#define __HIPRO_ASYCXX__PROTOCOL_FACTORY_H__
+
+#include "Error.h"
+#include "Reactor.h"
+#include "Transport.h"
+
+namespace asycxx
+{
+ class ProtocolFactory
+ {
+ public:
+ ProtocolFactory (Reactor *reactor);
+ virtual ~ProtocolFactory () {}
+
+ protected:
+ Reactor *m_Reactor;
+ };
+}
+#endif /* __HIPRO_ASYCXX__PROTOCOL_FACTORY_H__ */
+
+/*
+ Local Variables:
+ mode: c++
+ indent-tabs-mode: nil
+ tab-width: 4
+ c-file-style: "gnu"
+ End:
+*/
Deleted: trunk/src/Factory.cxx
===================================================================
--- trunk/src/Factory.cxx 2009-04-08 07:28:20 UTC (rev 23)
+++ trunk/src/Factory.cxx 2009-04-08 07:29:15 UTC (rev 24)
@@ -1,52 +0,0 @@
-
-/********************************************************************
- * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
- * rights reserved.
- *
- * This program and the accompanying materials are made available
- * under the terms described in the LICENSE file which accompanies
- * this distribution. If the LICENSE file was not attached to this
- * distribution or for further clarifications, please contact
- * le...@hi....
- *
- *******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <asycxx-config.h>
-#endif
-
-
-#include "asycxx-common.h"
-#include <asycxx/Error.h>
-#include <asycxx/Reactor.h>
-#include <asycxx/Factory.h>
-
-
-/**
- * \author Joe Steeve, jo...@hi...
- * \class Factory
- * \brief Defines a protocol-factory
- *
- * \details This class is a factory class that produces
- * protocols. This will be used by a 'Listener'/'Connector' to produce
- * protocols to handle a new connection.
- */
-
-Factory::Factory (Reactor *reactor)
-{
- ASSERT ((reactor != NULL), "checking parameters");
- m_Reactor = reactor;
-}
-
-Factory::~Factory ()
-{
-}
-
-/*
- Local Variables:
- mode: c++
- indent-tabs-mode: nil
- tab-width: 4
- c-file-style: "gnu"
- End:
-*/
Copied: trunk/src/ProtocolFactory.cxx (from rev 23, trunk/src/Factory.cxx)
===================================================================
--- trunk/src/ProtocolFactory.cxx (rev 0)
+++ trunk/src/ProtocolFactory.cxx 2009-04-08 07:29:15 UTC (rev 24)
@@ -0,0 +1,36 @@
+
+/********************************************************************
+ * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
+ * rights reserved.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms described in the LICENSE file which accompanies
+ * this distribution. If the LICENSE file was not attached to this
+ * distribution or for further clarifications, please contact
+ * le...@hi....
+ *
+ *******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <asycxx-config.h>
+#endif
+
+#include "asycxx-common.h"
+#include <asycxx/ProtocolFactory.h>
+
+using namespace asycxx;
+
+ProtocolFactory::ProtocolFactory (Reactor *reactor)
+{
+ ASSERT ((reactor != NULL), "checking parameters");
+ m_Reactor = reactor;
+}
+
+/*
+ Local Variables:
+ mode: c++
+ indent-tabs-mode: nil
+ tab-width: 4
+ c-file-style: "gnu"
+ End:
+*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 07:28:22
|
Revision: 23
http://asycxx.svn.sourceforge.net/asycxx/?rev=23&view=rev
Author: joe_steeve
Date: 2009-04-08 07:28:20 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
Generalized Deferred dont make sense here. Removed them.
From: Joe Steeve <js...@hi...>
Removed Paths:
-------------
trunk/include/asycxx/Deferred.h
trunk/src/Deferred.cxx
Deleted: trunk/include/asycxx/Deferred.h
===================================================================
--- trunk/include/asycxx/Deferred.h 2009-04-08 04:42:11 UTC (rev 22)
+++ trunk/include/asycxx/Deferred.h 2009-04-08 07:28:20 UTC (rev 23)
@@ -1,60 +0,0 @@
-
-/********************************************************************
- * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
- * rights reserved.
- *
- * This program and the accompanying materials are made available
- * under the terms described in the LICENSE file which accompanies
- * this distribution. If the LICENSE file was not attached to this
- * distribution or for further clarifications, please contact
- * le...@hi....
- *
- *******************************************************************/
-
-#ifndef __HIPRO_ASYCXX__DEFERRED_H__
-#define __HIPRO_ASYCXX__DEFERRED_H__
-
-#include "Error.h"
-#include "_asycxx.h"
-
-typedef void (*cbDeferredOnEvent_t) (void *obj);
-typedef void (*cbDeferredOnError_t) (void *obj);
-typedef void (*cbDeferredOnTimeout_t) (void *obj, h_msecs_t excess_time);
-
-class Deferred
-{
-
-public:
- Deferred ();
- ~Deferred ();
-
- Deferred * OnEvent (cbDeferredOnEvent_t cb_fn, void *cb_obj) throw ();
- Deferred * OnError (cbDeferredOnError_t cb_fn, void *cb_obj) throw ();
- Deferred * OnTimeout (cbDeferredOnTimeout_t cb_fn, void *cb_obj) throw ();
-
- void NotifyEvent (void);
- void NotifyError (void);
- void NotifyTimeout (h_msecs_t excess_time);
-
-private:
- cbDeferredOnEvent_t m_cbOnEvent;
- void * m_cbOnEvent_obj;
-
- cbDeferredOnError_t m_cbOnError;
- void * m_cbOnError_obj;
-
- cbDeferredOnTimeout_t m_cbOnTimeout;
- void * m_cbOnTimeout_obj;
-
-};
-
-#endif // __HIPRO_ASYCXX__DEFERRED_H__
-
-/*
- Local Variables:
- mode: c++
- indent-tabs-mode: nil
- tab-width: 4
- c-file-style: "gnu"
- End:
-*/
Deleted: trunk/src/Deferred.cxx
===================================================================
--- trunk/src/Deferred.cxx 2009-04-08 04:42:11 UTC (rev 22)
+++ trunk/src/Deferred.cxx 2009-04-08 07:28:20 UTC (rev 23)
@@ -1,155 +0,0 @@
-
-/********************************************************************
- * Copyright (C) 2008,2009 HiPro IT Solutions Pvt. Ltd., Chennai. All
- * rights reserved.
- *
- * This program and the accompanying materials are made available
- * under the terms described in the LICENSE file which accompanies
- * this distribution. If the LICENSE file was not attached to this
- * distribution or for further clarifications, please contact
- * le...@hi....
- *
- *******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <asycxx-config.h>
-#endif
-
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-#include "asycxx-common.h"
-#include <asycxx/Error.h>
-#include <asycxx/Deferred.h>
-
-
-/**
- * \brief ctor
- */
-Deferred::Deferred ()
-{
-
-}
-
-
-/**
- * \brief dtor
- */
-Deferred::~Deferred ()
-{
- m_cbOnEvent = NULL;
- m_cbOnEvent_obj = NULL;
- m_cbOnError = NULL;
- m_cbOnError_obj = NULL;
- m_cbOnTimeout = NULL;
- m_cbOnTimeout_obj = NULL;
-}
-
-
-/**
- *
- *
- */
-Deferred *
-Deferred::OnEvent (cbDeferredOnEvent_t cb_fn, void *cb_obj) throw ()
-{
- if (cb_fn == NULL)
- {
- THROW (DevError, "cannot register cbDeferredOnEvent = 'NULL'");
- }
-
- m_cbOnEvent = cb_fn;
- m_cbOnEvent_obj = cb_obj;
- return this;
-}
-
-
-/**
- *
- *
- */
-Deferred *
-Deferred::OnError (cbDeferredOnError_t cb_fn, void *cb_obj) throw ()
-{
- if (cb_fn == NULL)
- {
- THROW (DevError, "cannot register cbDeferredOnError = 'NULL'");
- }
-
- m_cbOnError = cb_fn;
- m_cbOnError_obj = cb_obj;
- return this;
-}
-
-
-/**
- *
- *
- */
-Deferred *
-Deferred::OnTimeout (cbDeferredOnTimeout_t cb_fn, void *cb_obj) throw ()
-{
- if (cb_fn == NULL)
- {
- THROW (DevError, "cannot register cbDeferredOnTimeout = 'NULL'");
- }
-
- m_cbOnTimeout = cb_fn;
- m_cbOnTimeout_obj = cb_obj;
- return this;
-}
-
-
-/**
- *
- *
- *
- */
-void
-Deferred::NotifyEvent (void)
-{
- if (m_cbOnEvent != NULL)
- {
- m_cbOnEvent (m_cbOnEvent_obj);
- }
-}
-
-
-/**
- *
- *
- *
- */
-void
-Deferred::NotifyError (void)
-{
- if (m_cbOnError != NULL)
- {
- m_cbOnError (m_cbOnError_obj);
- }
-}
-
-
-/**
- *
- *
- *
- */
-void
-Deferred::NotifyTimeout (h_msecs_t excess_time)
-{
- if (m_cbOnTimeout != NULL)
- {
- m_cbOnTimeout (m_cbOnTimeout_obj, excess_time);
- }
-}
-
-/*
- Local Variables:
- mode: c++
- indent-tabs-mode: nil
- tab-width: 4
- c-file-style: "gnu"
- End:
-*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <joe...@us...> - 2009-04-08 04:42:14
|
Revision: 22
http://asycxx.svn.sourceforge.net/asycxx/?rev=22&view=rev
Author: joe_steeve
Date: 2009-04-08 04:42:11 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
Release 0.1.1
This version has preliminary CAN support.
Added Paths:
-----------
tags/releases/0.1.1/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: Karthik B. <ka...@hi...> - 2009-03-24 14:00:26
|
2009/3/24 Joe Steeve <js...@hi...> > Which of these can be integrated into the autotools build system? as in, > something like 'make dist' should produce a .deb :) I need to explore more on this. I'll drop a mail sooner -- Karthik HiPro IT Solutions Pvt. Ltd. http://hipro.co.in/ |