Skip to content

Commit be0a0d4

Browse files
committed
Fix bugs & Add test codes
1 parent 8c76fe2 commit be0a0d4

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

moxt/libnet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "libnet.hpp"
22

3+
#include "common.hpp"
34
#include "libthread.hpp"
45
#include "moxt/httpx/asio_ioc.hpp"
56
#include "moxt/httpx/httpbase.hpp"
@@ -64,6 +65,10 @@ SEQ_FUNC void seq_websocket_set_on_message(WebSocket *p,
6465
p->set_on_message(callback);
6566
}
6667

68+
SEQ_FUNC AsioIOC *seq_asio_ioc() { return &AsioIOC::default_pool(); }
69+
70+
SEQ_FUNC void seq_asio_ioc_poll(AsioIOC *ioc) { ioc->poll(); }
71+
6772
void *coro_net_run(void *arg) {
6873
auto &pool = AsioIOC::default_pool();
6974
for (;;) {

moxt/libthread.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <chrono>
77
#include <cmath>
88
#include <csignal>
9+
#include <cstddef>
10+
#include <cstdio>
11+
#include <future>
912
#include <photon/common/alog.h>
1013
#include <photon/common/lockfree_queue.h>
1114
#include <photon/io/signal.h>
@@ -501,3 +504,48 @@ SEQ_FUNC bool seq_lockfree_queue_pop(CLockfreeSPSCRingQueueHandle handle,
501504
auto queue = static_cast<LockfreeSPSCRingQueue<iovec, capacity> *>(handle);
502505
return queue->pop(*data);
503506
}
507+
508+
// ¶¨Òå sample_callback_
509+
sample_callback sample_callback_ = nullptr;
510+
511+
SEQ_FUNC void seq_set_sample_callback(sample_callback callback) {
512+
sample_callback_ = callback;
513+
}
514+
515+
SEQ_FUNC void seq_sample_test() {
516+
if (sample_callback_) {
517+
sample_callback_();
518+
}
519+
}
520+
521+
// entry
522+
static void *entry(void *arg) {
523+
printf("entry\n");
524+
if (sample_callback_) {
525+
sample_callback_();
526+
}
527+
printf("entry done\n");
528+
return nullptr;
529+
}
530+
531+
static void e() {
532+
printf("e\n");
533+
if (sample_callback_) {
534+
sample_callback_();
535+
}
536+
printf("e done\n");
537+
}
538+
539+
SEQ_FUNC void seq_sample_coro_test() {
540+
printf("seq_sample_coro_test\n");
541+
if (work_pool == nullptr) {
542+
printf("work_pool is nullptr\n");
543+
return;
544+
}
545+
// work_pool->thread_migrate(photon::thread_create(entry, nullptr));
546+
547+
// Æô¶¯stdÏß³Ì(·ÇphotonÏß³Ì)
548+
std::thread *t = new std::thread(e);
549+
t->join();
550+
printf("seq_sample_coro_test done\n");
551+
}

moxt/libthread.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,6 @@ SEQ_FUNC bool seq_lockfree_queue_push(CLockfreeSPSCRingQueueHandle handle,
168168
SEQ_FUNC bool seq_lockfree_queue_pop(CLockfreeSPSCRingQueueHandle handle,
169169
iovec *data);
170170

171+
typedef void (*sample_callback)();
172+
171173
#endif

0 commit comments

Comments
 (0)