1 Star 0 Fork 1

THEWON/hello_erpc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server.cpp 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
thewon 提交于 2022-08-03 13:46 . fix a server bug
#include <iostream>
#include <sstream>
#include <sys/time.h>
#include <time.h>
#include <chrono>
#include <iomanip>
#include <string.h>
#include <erpc_server_setup.h>
#include "hello_server.h"
binary_t *sayHello(const binary_t *input)
{
struct timeval t_val;
struct tm* tm_l = NULL;
time_t tim_t;
size_t len = 0;
char *buf;
std::cout << "ServerHello called" << std::endl;
buf = (char *)malloc(input->dataLength + 21);
strncpy(buf, (const char *)input->data, input->dataLength);
gettimeofday(&t_val, NULL);
tim_t = t_val.tv_sec;
tm_l = localtime(&tim_t);
len = strftime(&buf[input->dataLength], 21, "@%Y-%m-%d %H:%M:%S", tm_l);
len = strlen(buf);
printf("data: %lu; %s\n", len, buf);
return new binary_t{(uint8_t*)buf, (uint32_t)len};
}
int main(int argc, char *argv[])
{
erpc_transport_t transport = erpc_transport_tcp_init("127.0.0.1", 5555, true);
erpc_mbf_t message_buffer_factory = erpc_mbf_dynamic_init();
erpc_server_init(transport, message_buffer_factory);
erpc_add_service_to_server(create_Hello_service());
while(1){
erpc_server_run();
}
erpc_transport_tcp_close();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/thewon/hello_erpc.git
git@gitee.com:thewon/hello_erpc.git
thewon
hello_erpc
hello_erpc
master

搜索帮助