直接将流写出

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:
endpoint: "http://localhost:9900"
log:
endpoint: "http://localhost:3001/endpoint"
log:
level: OFF

View File

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