Net/net.cpp

92 lines
2.0 KiB
C++
Raw Normal View History

2019-01-12 18:25:36 +00:00
//
// net.cpp
// Net
//
// Created by 胡一兵 on 2019/1/13.
// Copyright © 2019年 Bakantu. All rights reserved.
//
2019-01-13 12:48:58 +00:00
#include "net.h"
#include "cpart.h"
2019-01-14 13:25:56 +00:00
#include "cmap.h"
#include "cthread.h"
2019-01-13 12:48:58 +00:00
2019-01-15 13:50:46 +00:00
extern list<CThread *> daemon_list;
2019-01-16 10:08:59 +00:00
extern list<server_clock> server_list;
2019-01-15 17:36:22 +00:00
static struct itimerval oitrl, itrl;
2019-01-15 13:50:46 +00:00
2019-01-15 10:35:20 +00:00
void init(void){
signal(SIGALRM, threadsClock);
setThreadsClock();
}
2019-01-12 18:25:36 +00:00
2019-01-15 17:36:22 +00:00
//设置全局线程时钟
void setThreadsClock(void){
itrl.it_interval.tv_sec = 0;
itrl.it_interval.tv_usec = 500000;
itrl.it_value.tv_sec = 0;
itrl.it_value.tv_usec = 500000;
setitimer(ITIMER_REAL, &itrl, &oitrl);
}
//时钟滴答调用函数
void threadsClock(int n){
2019-01-16 10:08:59 +00:00
//printf("Clock click.\n");
2019-01-15 17:36:22 +00:00
for(auto i = daemon_list.begin(); i != daemon_list.end(); i++){
(*i)->Daemon();
}
2019-01-16 10:08:59 +00:00
// 服务器守护程序
for(auto i = server_list.begin(); i != server_list.end(); i++){
if(--(*i).click == 0){
(*i).psvr->Deamon();
}
}
for(auto i = server_list.begin(); i != server_list.end();){
if((*i).click == 0){
i = server_list.erase(i);
}
else i++;
}
2019-01-15 17:36:22 +00:00
daemon_list.clear();
}
2019-01-12 18:25:36 +00:00
int main(void){
2019-01-15 10:35:20 +00:00
init();
2019-01-16 10:08:59 +00:00
Server srvr("127.0.0.1");
//srvr.Deamon();
vector<int> fargs = {1,0,0,1};
vector<void *>args;
CPart::addArg<double>(&args, 12.63);
CPart::addArg<int>(&args, 10);
CPart::addArg<int>(&args, 6);
CPart::addArg<double>(&args, 8.2);
// 输入过程
struct compute_result cpur = {"Test",&args,&args,&fargs,&fargs};
packet pkt = srvr.CPURS2Packet(cpur);
raw_data rwd = srvr.Packet2Rawdata(pkt);
// 输出过程
srvr.Rawdata2Packet(rwd);
while(1){
sleep(100);
}
return 0;
}
void CPMT(void){
2019-01-13 16:57:56 +00:00
CMap map("./PCS");
2019-01-14 09:19:45 +00:00
CThread thread(&map);
thread.AddArgs<int>("B", 4);
2019-01-14 13:25:56 +00:00
thread.AddArgs<double>("B", 9.0);
thread.AddArgs<int>("C", 1.0);
thread.AddArgs<double>("C", 3.0);
thread.Analyse();
thread.DoLine();
2019-01-15 13:50:46 +00:00
thread.SetDaemon();
thread.CancelChildPCS(0);
2019-01-12 18:25:36 +00:00
}