summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2005-11-09 15:51:49 +0000
committerBenny Prijono <bennylp@teluu.com>2005-11-09 15:51:49 +0000
commitd578e2e00a14e5faa775c51a25ddbc2f3d3a2fda (patch)
treee86117d72d8e09dbd82a41649715541ad27a985b /pjlib
parent6e1024262b48b57b771331b8c19e988e43627bd7 (diff)
Test pj++ proactor (compile only)
git-svn-id: http://svn.pjsip.org/repos/pjproject/main@37 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/include/pj++/pool.hpp21
-rw-r--r--pjlib/include/pj++/proactor.hpp33
-rw-r--r--pjlib/src/pjlib++-test/main.cpp14
3 files changed, 55 insertions, 13 deletions
diff --git a/pjlib/include/pj++/pool.hpp b/pjlib/include/pj++/pool.hpp
index 611cd7a7..c1991d5b 100644
--- a/pjlib/include/pj++/pool.hpp
+++ b/pjlib/include/pj++/pool.hpp
@@ -15,8 +15,19 @@ class Pj_Object
{
public:
void *operator new(unsigned int class_size, Pj_Pool *pool);
- void operator delete(void*);
- void operator delete(void*, Pj_Pool*);
+ void *operator new(unsigned int class_size, Pj_Pool &pool);
+
+ void operator delete(void*)
+ {
+ }
+
+ void operator delete(void*, Pj_Pool*)
+ {
+ }
+
+ void operator delete(void*, Pj_Pool&)
+ {
+ }
//
// Inline implementations at the end of this file.
@@ -220,11 +231,9 @@ inline void *Pj_Object::operator new(unsigned int class_size, Pj_Pool *pool)
{
return pool->alloc(class_size);
}
-inline void Pj_Object::operator delete(void *ptr)
-{
-}
-inline void Pj_Object::operator delete(void *ptr, Pj_Pool*)
+inline void *Pj_Object::operator new(unsigned int class_size, Pj_Pool &pool)
{
+ return pool.alloc(class_size);
}
//
diff --git a/pjlib/include/pj++/proactor.hpp b/pjlib/include/pj++/proactor.hpp
index 7021a5a0..891dd75d 100644
--- a/pjlib/include/pj++/proactor.hpp
+++ b/pjlib/include/pj++/proactor.hpp
@@ -23,6 +23,15 @@ class Pj_Async_Op : public pj_ioqueue_op_key_t
{
public:
//
+ // Construct with null handler.
+ // App must call set_handler() before use.
+ //
+ Pj_Async_Op()
+ : handler_(NULL)
+ {
+ }
+
+ //
// Constructor.
//
explicit Pj_Async_Op(Pj_Event_Handler *handler)
@@ -32,6 +41,14 @@ public:
}
//
+ // Set handler.
+ //
+ void set_handler(Pj_Event_Handler *handler)
+ {
+ handler_ = handler;
+ }
+
+ //
// Check whether operation is still pending for this key.
//
bool is_pending();
@@ -97,7 +114,7 @@ public:
}
//
- // Receive data.
+ // Start async receive.
//
pj_status_t recv( Pj_Async_Op *op_key,
void *buf, pj_ssize_t *len,
@@ -108,7 +125,7 @@ public:
}
//
- // Recvfrom()
+ // Start async recvfrom()
//
pj_status_t recvfrom( Pj_Async_Op *op_key,
void *buf, pj_ssize_t *len, unsigned flags,
@@ -120,7 +137,7 @@ public:
}
//
- // send()
+ // Start async send()
//
pj_status_t send( Pj_Async_Op *op_key,
const void *data, pj_ssize_t *len,
@@ -130,7 +147,7 @@ public:
}
//
- // sendto()
+ // Start async sendto()
//
pj_status_t sendto( Pj_Async_Op *op_key,
const void *data, pj_ssize_t *len, unsigned flags,
@@ -142,7 +159,7 @@ public:
#if PJ_HAS_TCP
//
- // connect()
+ // Start async connect()
//
pj_status_t connect(const Pj_Inet_Addr &addr)
{
@@ -150,7 +167,7 @@ public:
}
//
- // accept.
+ // Start async accept().
//
pj_status_t accept( Pj_Async_Op *op_key,
Pj_Socket *sock,
@@ -272,6 +289,8 @@ public:
cb_.on_write_complete = &write_complete_cb;
cb_.on_accept_complete = &accept_complete_cb;
cb_.on_connect_complete = &connect_complete_cb;
+
+ create(pool, max_fd, max_timer_entries);
}
//
@@ -304,7 +323,7 @@ public:
return NULL;
}
- status;
+ return status;
}
//
diff --git a/pjlib/src/pjlib++-test/main.cpp b/pjlib/src/pjlib++-test/main.cpp
index 4a6d0aaa..99b7f8d5 100644
--- a/pjlib/src/pjlib++-test/main.cpp
+++ b/pjlib/src/pjlib++-test/main.cpp
@@ -9,6 +9,14 @@
#include <pj++/timer.hpp>
#include <pj++/tree.hpp>
+class My_Async_Op : public Pj_Async_Op
+{
+};
+
+class My_Event_Handler : public Pj_Event_Handler
+{
+};
+
int main()
{
Pjlib lib;
@@ -24,6 +32,12 @@ int main()
plsem = new(pool) Pj_Semaphore_Lock(pool);
delete plsem;
+ Pj_Proactor proactor(pool, 100, 100);
+
+ My_Event_Handler *event_handler = new(the_pool) My_Event_Handler;
+ proactor.register_socket_handler(pool, event_handler);
+ proactor.unregister_handler(event_handler);
+
return 0;
}