直接将流写出

This commit is contained in:
Pan Qiancheng 2025-04-15 15:28:59 +08:00
parent 605519fde0
commit 9b7908b326
4 changed files with 15 additions and 23 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
machine_registry: machine_registry:
endpoint: "http://localhost:9900" endpoint: "http://localhost:3001/endpoint"
log: log:
level: OFF level: OFF

View File

@ -1,11 +1,12 @@
#include "client.h" #include "client.h"
#include <errno.h>
#include <limits.h>
#include <netinet/tcp.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <netinet/tcp.h>
#define BUFFER_SIZE 4096 #define BUFFER_SIZE 4096
@ -14,14 +15,14 @@ ssize_t readMessage(int sock, char *buffer, size_t maxSize) {
uint32_t messageLen; uint32_t messageLen;
// 先读取消息长度 // 先读取消息长度
if (read(sock, &messageLen, sizeof(messageLen)) != sizeof(messageLen)) { if (read(sock, &messageLen, sizeof(messageLen)) != sizeof(messageLen)) {
return -1; return -1;
} }
// 检查buffer大小是否足够 // 检查buffer大小是否足够
if (messageLen >= maxSize) { if (messageLen >= maxSize) {
return -1; return -1;
} }
// 读取完整消息 // 读取完整消息
size_t totalRead = 0; size_t totalRead = 0;
while (totalRead < messageLen) { while (totalRead < messageLen) {
@ -44,7 +45,7 @@ int send_exec_params(const char *filename, char *const argv[],
return -1; return -1;
} }
if (logPath[0] != '/') { // 相对路径 if (logPath[0] != '/') { // 相对路径
size_t pwd_len = strlen(pwd); size_t pwd_len = strlen(pwd);
size_t log_len = strlen(logPath); size_t log_len = strlen(logPath);
if (pwd_len + log_len + 2 > PATH_MAX) { if (pwd_len + log_len + 2 > PATH_MAX) {
@ -144,7 +145,7 @@ int send_exec_params(const char *filename, char *const argv[],
close(sock); close(sock);
return -1; return -1;
} }
if (strstr(buffer, "[sthttp]")) { if (strstr(buffer, "[sthttp]")) {
started = 1; started = 1;
} }
@ -161,19 +162,10 @@ int send_exec_params(const char *filename, char *const argv[],
break; break;
} }
// 处理[res]...[wait]消息 strncpy(display_buffer, buffer, BUFFER_SIZE - 1);
char *res_start = strstr(buffer, "[res]"); display_buffer[BUFFER_SIZE - 1] = '\0';
char *wait_end = strstr(buffer, "[wait]"); printf("%s", display_buffer);
fflush(stdout);
if (res_start && wait_end) {
size_t content_len = wait_end - (res_start + strlen("[res]"));
if (content_len < BUFFER_SIZE) {
strncpy(display_buffer, res_start + strlen("[res]"), content_len);
display_buffer[content_len] = '\0';
printf("%s\n", display_buffer);
fflush(stdout);
}
}
} }
close(sock); close(sock);