报错信息
Program received signal SIGSEGV, Segmentation fault. 0xf7be0224 in rops_write_role_protocol_ws (wsi=0xf7dd3c00,
buf=0x400a2b "留言记录", len=12, wp=0xfffee68c)
at /data/data/com.termux/files/home/libws/libwebsockets/lib/roles/ws/ops-ws.c:1809 1809 buf[-pre] = (uint8_t)n;
调用部分代码
const char *start_msg = "留言记录";
if(lws_write (wsi, (unsigned char *) start_msg, strlen (start_msg), LWS_WRITE_TEXT)<0){
fclose(file);
return;
}
// 读取并发送留言板内容
char *line = NULL;
size_t len = 0;
ssize_t read;
while ((read = getline(&line, &len, file)) != -1) {
// 去除换行符
line[strcspn(line, "\n")] = 0;
// 发送当前行
printf("%s",line);
fflush(stdout);
fflush(stdin);
//getchar();getchar();
if(lws_write (wsi, (unsigned char *) line, strlen (line), LWS_WRITE_TEXT)<0){
fclose(file);
if (line) {
free(line);
}
return;
}
}
// 发送"留言完毕"消息
const char *end_msg = "留言完毕";
send_to_client_by_username (NULL, username, end_msg, strlen(end_msg));
if(lws_write (wsi, (unsigned char *) end_msg, strlen (end_msg), LWS_WRITE_TEXT)<0){
fclose(file);
if (line) {
free(line);
}
return;
}