Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sogou/workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Aug 15, 2023
2 parents ba442be + 69cbd91 commit dec2f58
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
16 changes: 8 additions & 8 deletions docs/about-conditional.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ public:
这就相当于实现了观察者模式。

# 示例
还是上面的延迟计算示例,我们增加到两个计算任务并用观察者模式来实现。用slot1作为条件任务名。
还是上面的延迟计算示例,我们增加到两个计算任务并用观察者模式来实现。用"slot1"作为条件任务名。
~~~cpp
int main()
{
WFGoTask *task1 = WFTaskFactory::create_go_task("test, [](){ printf(test1 done\n"); });
WFGoTask *task2 = WFTaskFactory::create_go_task("test, [](){ printf(test2 done\n"); });
WFConditional *cond1 = WFTaskFactory::create_conditional(slot1, task1);
WFConditional *cond2 = WFTaskFactory::create_conditional(slot1, task2);
WFGoTask *task1 = WFTaskFactory::create_go_task("test", [](){ printf("test1 done\n"); });
WFGoTask *task2 = WFTaskFactory::create_go_task("test", [](){ printf("test2 done\n"); });
WFConditional *cond1 = WFTaskFactory::create_conditional("slot1", task1);
WFConditional *cond2 = WFTaskFactory::create_conditional("slot1", task2);
WFTimerTask *timer = WFTaskFactory::create_timer_task(1, 0, [](void *){
WFTaskFactory::signal_by_name(slot1, NULL);
WFTaskFactory::signal_by_name("slot1", NULL);
});
timer->start();
cond1->start();
Expand All @@ -93,9 +93,9 @@ Workflow里的任何任务,如果创建之后不想运行,都可以通过dis
int main()
{
WFEmptyTask *task = WFTaskFactory::create_empty_task();
WFConditional *cond = WFTaskFactory::create_conditional(slot1, task);
WFConditional *cond = WFTaskFactory::create_conditional("slot1", task);
WFTimerTask *timer = WFTaskFactory::create_timer_task(0, 0, [](void *) {
WFTaskFactory::signal_by_name(slot1);
WFTaskFactory::signal_by_name("slot1");
});
timer->start();
cond->dismiss(); // 取消任务
Expand Down
5 changes: 5 additions & 0 deletions src/kernel/Communicator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,11 @@ CommSession::~CommSession()
{
pos = target->idle_list.next;
entry = list_entry(pos, struct CommConnEntry, list);
list_del(pos);

errno_bak = errno;
mpoller_del(entry->sockfd, entry->mpoller);
entry->state = CONN_STATE_CLOSING;
errno = errno_bak;
}

Expand Down Expand Up @@ -1816,7 +1819,9 @@ int Communicator::shutdown(CommSession *session)
if (!list_empty(&target->idle_list))
{
entry = list_entry(target->idle_list.next, struct CommConnEntry, list);
list_del(&entry->list);
ret = mpoller_del(entry->sockfd, entry->mpoller);
entry->state = CONN_STATE_CLOSING;
}
else
{
Expand Down
2 changes: 0 additions & 2 deletions src/protocol/DnsMessage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#define DNS_LABELS_MAX 63
#define DNS_MESSAGE_MAX_UDP_SIZE 512
#define DNS_HEADER_SIZE sizeof (struct dns_header)

namespace protocol
{
Expand Down Expand Up @@ -77,7 +76,6 @@ int DnsMessage::encode_reply()
size_t len;

msgbuf.clear();
msgbuf.reserve(DNS_HEADER_SIZE);
msgsize = 0;

// TODO encode other field
Expand Down
9 changes: 4 additions & 5 deletions src/protocol/dns_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#define DNS_LABELS_MAX 63
#define DNS_NAMES_MAX 256
#define DNS_MSGBASE_INIT_SIZE 514 // 512 + 2(leading length)
#define DNS_HEADER_SIZE sizeof (struct dns_header)
#define MAX(x, y) ((x) <= (y) ? (y) : (x))

struct __dns_record_entry
Expand Down Expand Up @@ -706,7 +705,7 @@ void dns_parser_init(dns_parser_t *parser)
parser->bufsize = 0;
parser->complete = 0;
parser->single_packet = 0;
memset(&parser->header, 0, DNS_HEADER_SIZE);
memset(&parser->header, 0, sizeof (struct dns_header));
memset(&parser->question, 0, sizeof (struct dns_question));
INIT_LIST_HEAD(&parser->answer_list);
INIT_LIST_HEAD(&parser->authority_list);
Expand Down Expand Up @@ -769,16 +768,16 @@ int dns_parser_parse_all(dns_parser_t *parser)
parser->cur = (const char *)parser->msgbase;
h = &parser->header;

if (parser->msgsize < DNS_HEADER_SIZE)
if (parser->msgsize < sizeof (struct dns_header))
return -2;

memcpy(h, parser->msgbase, DNS_HEADER_SIZE);
memcpy(h, parser->msgbase, sizeof (struct dns_header));
h->id = ntohs(h->id);
h->qdcount = ntohs(h->qdcount);
h->ancount = ntohs(h->ancount);
h->nscount = ntohs(h->nscount);
h->arcount = ntohs(h->arcount);
parser->cur += DNS_HEADER_SIZE;
parser->cur += sizeof (struct dns_header);

ret = __dns_parser_parse_question(parser);
if (ret < 0)
Expand Down
2 changes: 2 additions & 0 deletions src/protocol/dns_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum
* request or response packet, but the byte order is not
* transformed.
*/
#pragma pack(1)
struct dns_header
{
uint16_t id;
Expand Down Expand Up @@ -112,6 +113,7 @@ struct dns_header
uint16_t nscount;
uint16_t arcount;
};
#pragma pack()

struct dns_question
{
Expand Down

0 comments on commit dec2f58

Please sign in to comment.