|
@@ -8,6 +8,7 @@
|
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
|
#include <fcntl.h>
|
|
#include <fcntl.h>
|
|
|
#include <stdint.h>
|
|
#include <stdint.h>
|
|
|
|
|
+#include <signal.h>
|
|
|
|
|
|
|
|
#include "scufeng/engine.h"
|
|
#include "scufeng/engine.h"
|
|
|
#include "scufeng/log.h"
|
|
#include "scufeng/log.h"
|
|
@@ -36,7 +37,7 @@ static SCDArray_NetMsgType out_msgs;
|
|
|
|
|
|
|
|
SCDARRAY_IMPL(NetMsgType, NetMsgType)
|
|
SCDARRAY_IMPL(NetMsgType, NetMsgType)
|
|
|
|
|
|
|
|
-static void send_out_msgs() {
|
|
|
|
|
|
|
+static bool send_out_msgs() {
|
|
|
for (size_t i = 0; i < out_msgs.len; i++) {
|
|
for (size_t i = 0; i < out_msgs.len; i++) {
|
|
|
const NetMsgType *const type = SCDArray_NetMsgType_at(&out_msgs, i);
|
|
const NetMsgType *const type = SCDArray_NetMsgType_at(&out_msgs, i);
|
|
|
switch (*type) {
|
|
switch (*type) {
|
|
@@ -49,13 +50,17 @@ static void send_out_msgs() {
|
|
|
.r_pos_y = game_state.paddle_r.pos[1],
|
|
.r_pos_y = game_state.paddle_r.pos[1],
|
|
|
.r_dirv_y = game_state.paddle_r.dirv[1]
|
|
.r_dirv_y = game_state.paddle_r.dirv[1]
|
|
|
};
|
|
};
|
|
|
- send_msg(p1_conn, NET_MSG_PADDLE_POS, (uint8_t *) &msg);
|
|
|
|
|
|
|
+ if (!send_msg(p1_conn, NET_MSG_PADDLE_POS, (uint8_t *) &msg)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
// p2
|
|
// p2
|
|
|
msg.l_pos_y = game_state.paddle_r.pos[1];
|
|
msg.l_pos_y = game_state.paddle_r.pos[1];
|
|
|
msg.l_dirv_y = game_state.paddle_r.dirv[1];
|
|
msg.l_dirv_y = game_state.paddle_r.dirv[1];
|
|
|
msg.r_pos_y = game_state.paddle_l.pos[1];
|
|
msg.r_pos_y = game_state.paddle_l.pos[1];
|
|
|
msg.r_dirv_y = game_state.paddle_l.dirv[1];
|
|
msg.r_dirv_y = game_state.paddle_l.dirv[1];
|
|
|
- send_msg(p2_conn, NET_MSG_PADDLE_POS, (uint8_t *) &msg);
|
|
|
|
|
|
|
+ if (!send_msg(p2_conn, NET_MSG_PADDLE_POS, (uint8_t *) &msg)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
case NET_MSG_PADDLE_CHANGE_DIR:
|
|
case NET_MSG_PADDLE_CHANGE_DIR:
|
|
@@ -71,11 +76,15 @@ static void send_out_msgs() {
|
|
|
.ball_dirv_x = game_state.ball.dirv[0],
|
|
.ball_dirv_x = game_state.ball.dirv[0],
|
|
|
.ball_dirv_y = game_state.ball.dirv[1],
|
|
.ball_dirv_y = game_state.ball.dirv[1],
|
|
|
};
|
|
};
|
|
|
- send_msg(p1_conn, NET_MSG_BALL_UPDATE, (uint8_t *) &msg);
|
|
|
|
|
|
|
+ if (!send_msg(p1_conn, NET_MSG_BALL_UPDATE, (uint8_t *) &msg)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
msg.ball_pos_x = 1.0f - msg.ball_pos_x;
|
|
msg.ball_pos_x = 1.0f - msg.ball_pos_x;
|
|
|
msg.ball_dirv_x *= -1.0f;
|
|
msg.ball_dirv_x *= -1.0f;
|
|
|
- send_msg(p2_conn, NET_MSG_BALL_UPDATE, (uint8_t *) &msg);
|
|
|
|
|
|
|
+ if (!send_msg(p2_conn, NET_MSG_BALL_UPDATE, (uint8_t *) &msg)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
case NET_MSG_SCORE_UPDATE:
|
|
case NET_MSG_SCORE_UPDATE:
|
|
@@ -84,26 +93,32 @@ static void send_out_msgs() {
|
|
|
.l_score = game_state.score_l,
|
|
.l_score = game_state.score_l,
|
|
|
.r_score = game_state.score_r
|
|
.r_score = game_state.score_r
|
|
|
};
|
|
};
|
|
|
- send_msg(p1_conn, NET_MSG_SCORE_UPDATE, (uint8_t *) &msg);
|
|
|
|
|
|
|
+ if (!send_msg(p1_conn, NET_MSG_SCORE_UPDATE, (uint8_t *) &msg)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
msg.l_score = game_state.score_r;
|
|
msg.l_score = game_state.score_r;
|
|
|
msg.r_score = game_state.score_l;
|
|
msg.r_score = game_state.score_l;
|
|
|
- send_msg(p2_conn, NET_MSG_SCORE_UPDATE, (uint8_t *) &msg);
|
|
|
|
|
|
|
+ if (!send_msg(p2_conn, NET_MSG_SCORE_UPDATE, (uint8_t *) &msg)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SCDArray_NetMsgType_clear_no_resize(&out_msgs);
|
|
SCDArray_NetMsgType_clear_no_resize(&out_msgs);
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void send_game_state(FILE *conn, const bool p1) {
|
|
|
|
|
|
|
+static bool send_game_state(FILE *conn, const bool p1) {
|
|
|
GameStateMsg msg;
|
|
GameStateMsg msg;
|
|
|
GameState_to_GameStateMsg(&game_state, &msg, p1);
|
|
GameState_to_GameStateMsg(&game_state, &msg, p1);
|
|
|
- send_msg(conn, NET_MSG_GAME_STATE, (uint8_t *) &msg);
|
|
|
|
|
|
|
+ return send_msg(conn, NET_MSG_GAME_STATE, (uint8_t *) &msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void server_lobby(const int sock) {
|
|
|
|
|
|
|
+static bool server_lobby(const int sock) {
|
|
|
assert_scufcont_success(SCDArray_NetMsgType_alloc(&out_msgs));
|
|
assert_scufcont_success(SCDArray_NetMsgType_alloc(&out_msgs));
|
|
|
game_state = GameState_new(game_default_params, false);
|
|
game_state = GameState_new(game_default_params, false);
|
|
|
|
|
|
|
@@ -111,9 +126,6 @@ static void server_lobby(const int sock) {
|
|
|
if (player1 == -1) {
|
|
if (player1 == -1) {
|
|
|
LOG_FATALF("accept failed: %s", strerror(errno));
|
|
LOG_FATALF("accept failed: %s", strerror(errno));
|
|
|
}
|
|
}
|
|
|
- if (fcntl(player1, F_SETFL, O_NONBLOCK) != 0) {
|
|
|
|
|
- LOG_FATALF("fcntl failed on player1: (%d) %s", errno, strerror(errno));
|
|
|
|
|
- }
|
|
|
|
|
printf("Player 1 connected\n");
|
|
printf("Player 1 connected\n");
|
|
|
|
|
|
|
|
p1_conn = fdopen(player1, "r+");
|
|
p1_conn = fdopen(player1, "r+");
|
|
@@ -124,15 +136,16 @@ static void server_lobby(const int sock) {
|
|
|
IsPlayer1Msg p1_msg = {
|
|
IsPlayer1Msg p1_msg = {
|
|
|
.player1 = 1u
|
|
.player1 = 1u
|
|
|
};
|
|
};
|
|
|
- send_msg(p1_conn, NET_MSG_IS_PLAYER_1, (uint8_t *) &p1_msg);
|
|
|
|
|
|
|
+ if (!send_msg(p1_conn, NET_MSG_IS_PLAYER_1, (uint8_t *) &p1_msg)) {
|
|
|
|
|
+ close(player1);
|
|
|
|
|
+ SCDArray_NetMsgType_free(&out_msgs);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
int player2 = accept(sock, nullptr, nullptr);
|
|
int player2 = accept(sock, nullptr, nullptr);
|
|
|
if (player2 == -1) {
|
|
if (player2 == -1) {
|
|
|
LOG_FATALF("accept failed: %s", strerror(errno));
|
|
LOG_FATALF("accept failed: %s", strerror(errno));
|
|
|
}
|
|
}
|
|
|
- if (fcntl(player2, F_SETFL, O_NONBLOCK) != 0) {
|
|
|
|
|
- LOG_FATALF("fcntl failed on player2: (%d) %s", errno, strerror(errno));
|
|
|
|
|
- }
|
|
|
|
|
printf("Player 2 connected\n");
|
|
printf("Player 2 connected\n");
|
|
|
|
|
|
|
|
p2_conn = fdopen(player2, "r+");
|
|
p2_conn = fdopen(player2, "r+");
|
|
@@ -141,7 +154,14 @@ static void server_lobby(const int sock) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
p1_msg.player1 = 0u;
|
|
p1_msg.player1 = 0u;
|
|
|
- send_msg(p2_conn, NET_MSG_IS_PLAYER_1, (uint8_t *) &p1_msg);
|
|
|
|
|
|
|
+ if (!send_msg(p2_conn, NET_MSG_IS_PLAYER_1, (uint8_t *) &p1_msg)) {
|
|
|
|
|
+ close(player1);
|
|
|
|
|
+ close(player2);
|
|
|
|
|
+ SCDArray_NetMsgType_free(&out_msgs);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void handle_paddle_change_dir_msg(FILE *conn, const bool p1) {
|
|
static void handle_paddle_change_dir_msg(FILE *conn, const bool p1) {
|
|
@@ -157,10 +177,13 @@ static void handle_paddle_change_dir_msg(FILE *conn, const bool p1) {
|
|
|
assert_scufcont_success(SCDArray_NetMsgType_push_back(&out_msgs, &type));
|
|
assert_scufcont_success(SCDArray_NetMsgType_push_back(&out_msgs, &type));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void handle_player_input(const bool p1) {
|
|
|
|
|
|
|
+static bool handle_player_input(const bool p1) {
|
|
|
FILE *conn = p1 ? p1_conn : p2_conn;
|
|
FILE *conn = p1 ? p1_conn : p2_conn;
|
|
|
NetMsgType msg_type;
|
|
NetMsgType msg_type;
|
|
|
- if (recv_msg_type(conn, &msg_type)) {
|
|
|
|
|
|
|
+ const int res = recv_msg_type(conn, &msg_type);
|
|
|
|
|
+ switch (res) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ {
|
|
|
switch (msg_type) {
|
|
switch (msg_type) {
|
|
|
case NET_MSG_PADDLE_CHANGE_DIR:
|
|
case NET_MSG_PADDLE_CHANGE_DIR:
|
|
|
handle_paddle_change_dir_msg(conn, p1);
|
|
handle_paddle_change_dir_msg(conn, p1);
|
|
@@ -173,18 +196,61 @@ static void handle_player_input(const bool p1) {
|
|
|
case NET_MSG_SCORE_UPDATE:
|
|
case NET_MSG_SCORE_UPDATE:
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
+ case EWOULDBLOCK:
|
|
|
|
|
+ return true;
|
|
|
|
|
+ case ECONNRESET:
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void server_game() {
|
|
static void server_game() {
|
|
|
se_fps_lock_set_fps(60);
|
|
se_fps_lock_set_fps(60);
|
|
|
|
|
|
|
|
- send_msg(p1_conn, NET_MSG_GAME_START, nullptr);
|
|
|
|
|
- send_msg(p2_conn, NET_MSG_GAME_START, nullptr);
|
|
|
|
|
- send_game_state(p1_conn, true);
|
|
|
|
|
- send_game_state(p2_conn, false);
|
|
|
|
|
|
|
+ if (!send_game_state(p1_conn, true)) {
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!send_game_state(p2_conn, false)) {
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!send_msg(p1_conn, NET_MSG_GAME_START, nullptr)) {
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!send_msg(p2_conn, NET_MSG_GAME_START, nullptr)) {
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ NetMsgType msg_type;
|
|
|
|
|
|
|
|
- double last_frame_time_s = 0.0;
|
|
|
|
|
|
|
+ if (recv_msg_type(p1_conn, &msg_type) == ECONNRESET) {
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (msg_type != NET_MSG_GAME_START) {
|
|
|
|
|
+ LOG_ERRORF("Did not receive GAME_START, got: %s\n", NetMsgType_to_str(msg_type));
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (recv_msg_type(p2_conn, &msg_type) == ECONNRESET) {
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (msg_type != NET_MSG_GAME_START) {
|
|
|
|
|
+ LOG_ERRORF("Did not receive GAME_START, got: %s\n", NetMsgType_to_str(msg_type));
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (fcntl(fileno(p1_conn), F_SETFL, O_NONBLOCK) != 0) {
|
|
|
|
|
+ LOG_FATALF("fcntl failed on player1: (%d) %s", errno, strerror(errno));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fcntl(fileno(p2_conn), F_SETFL, O_NONBLOCK) != 0) {
|
|
|
|
|
+ LOG_FATALF("fcntl failed on player2: (%d) %s", errno, strerror(errno));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LOG("Game start");
|
|
|
|
|
+
|
|
|
|
|
+ double last_frame_time_s = se_get_time();
|
|
|
while (true) {
|
|
while (true) {
|
|
|
const double current_time_s = se_get_time();
|
|
const double current_time_s = se_get_time();
|
|
|
const double delta = current_time_s - last_frame_time_s;
|
|
const double delta = current_time_s - last_frame_time_s;
|
|
@@ -192,14 +258,15 @@ static void server_game() {
|
|
|
se_fps_lock_frame_start_s(current_time_s);
|
|
se_fps_lock_frame_start_s(current_time_s);
|
|
|
|
|
|
|
|
// Player input
|
|
// Player input
|
|
|
- handle_player_input(true);
|
|
|
|
|
- handle_player_input(false);
|
|
|
|
|
|
|
+ if (!handle_player_input(true)) {
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!handle_player_input(false)) {
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Tick
|
|
// Tick
|
|
|
const GameStateEvent gs_event = GameState_update(&game_state, delta);
|
|
const GameStateEvent gs_event = GameState_update(&game_state, delta);
|
|
|
- // if (gs_event != GSEVENT_NONE) {
|
|
|
|
|
- // LOGF("GameStateEvent: %s", GameStateEvent_to_str(gs_event));
|
|
|
|
|
- // }
|
|
|
|
|
switch (gs_event) {
|
|
switch (gs_event) {
|
|
|
case GSEVENT_BALL_DIR_CHANGE:
|
|
case GSEVENT_BALL_DIR_CHANGE:
|
|
|
{
|
|
{
|
|
@@ -212,6 +279,7 @@ static void server_game() {
|
|
|
case GSEVENT_L_SCORE:
|
|
case GSEVENT_L_SCORE:
|
|
|
case GSEVENT_R_SCORE:
|
|
case GSEVENT_R_SCORE:
|
|
|
{
|
|
{
|
|
|
|
|
+ LOG("Goal");
|
|
|
NetMsgType type = NET_MSG_SCORE_UPDATE;
|
|
NetMsgType type = NET_MSG_SCORE_UPDATE;
|
|
|
assert_scufcont_success(SCDArray_NetMsgType_push_back(&out_msgs, &type));
|
|
assert_scufcont_success(SCDArray_NetMsgType_push_back(&out_msgs, &type));
|
|
|
type = NET_MSG_BALL_UPDATE;
|
|
type = NET_MSG_BALL_UPDATE;
|
|
@@ -221,14 +289,24 @@ static void server_game() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Player output
|
|
// Player output
|
|
|
- send_out_msgs();
|
|
|
|
|
|
|
+ if (!send_out_msgs()) {
|
|
|
|
|
+ goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Wait
|
|
// Wait
|
|
|
se_fps_lock_wait();
|
|
se_fps_lock_wait();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+cleanup:
|
|
|
|
|
+ LOG("Cleaning up");
|
|
|
|
|
+ fclose(p1_conn);
|
|
|
|
|
+ fclose(p2_conn);
|
|
|
|
|
+ SCDArray_NetMsgType_free(&out_msgs);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
int main() {
|
|
|
|
|
+ signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
+
|
|
|
se_init(true);
|
|
se_init(true);
|
|
|
|
|
|
|
|
struct protoent *proto = getprotobyname("tcp");
|
|
struct protoent *proto = getprotobyname("tcp");
|
|
@@ -272,96 +350,18 @@ int main() {
|
|
|
while (true) {
|
|
while (true) {
|
|
|
switch (server_state) {
|
|
switch (server_state) {
|
|
|
case SS_LOBBY:
|
|
case SS_LOBBY:
|
|
|
- server_lobby(sock);
|
|
|
|
|
- server_state = SS_GAME;
|
|
|
|
|
|
|
+ LOG("SS_LOBBY");
|
|
|
|
|
+ if (server_lobby(sock)) {
|
|
|
|
|
+ server_state = SS_GAME;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
case SS_GAME:
|
|
case SS_GAME:
|
|
|
|
|
+ LOG("SS_GAME");
|
|
|
server_game();
|
|
server_game();
|
|
|
|
|
+ server_state = SS_LOBBY;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // printf("Player connected\n");
|
|
|
|
|
- //
|
|
|
|
|
- // FILE *conn_s = fdopen(conn, "r+");
|
|
|
|
|
- // if (conn_s == nullptr) {
|
|
|
|
|
- // LOG_FATALF("fdopen failed: (%d) %s", errno, strerror(errno));
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // while (true) {
|
|
|
|
|
- // printf("Reading msg_len\n");
|
|
|
|
|
- // size_t msg_len;
|
|
|
|
|
- // size_t bytes_read = fread(&msg_len, sizeof(msg_len), 1, conn_s);
|
|
|
|
|
- // if (bytes_read < 1) {
|
|
|
|
|
- // LOG_FATALF("fread failed to read msg_len %zu", bytes_read);
|
|
|
|
|
- // }
|
|
|
|
|
- // printf("msg_len: %zu\n", msg_len);
|
|
|
|
|
- //
|
|
|
|
|
- // printf("\nReading msg\n");
|
|
|
|
|
- // char *msg = (char *) malloc(msg_len + 1);
|
|
|
|
|
- // bytes_read = fread(msg, msg_len, 1, conn_s);
|
|
|
|
|
- // if (bytes_read < 1) {
|
|
|
|
|
- // LOG_FATALF("fread failed to read msg %zu", bytes_read);
|
|
|
|
|
- // }
|
|
|
|
|
- // msg[msg_len] = '\0';
|
|
|
|
|
- //
|
|
|
|
|
- // printf("msg: %s\n\n", msg);
|
|
|
|
|
- //
|
|
|
|
|
- // free(msg);
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // fclose(conn_s);
|
|
|
|
|
- // close(conn);
|
|
|
|
|
- // close(sock);
|
|
|
|
|
-
|
|
|
|
|
- // char inter_buf[1024] = {0};
|
|
|
|
|
- // const size_t inter_buf_size = sizeof(inter_buf) / sizeof(inter_buf[0]);
|
|
|
|
|
- //
|
|
|
|
|
- // size_t buf_size = sizeof(char) * 1024;
|
|
|
|
|
- // size_t buf_len = 0;
|
|
|
|
|
- // char *buf = (char *) malloc(buf_size);
|
|
|
|
|
- // if (buf == nullptr) {
|
|
|
|
|
- // LOG_FATAL("Failed to allocate buf");
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // while (true) {
|
|
|
|
|
- // int received = recv(conn, inter_buf, inter_buf_size, 0);
|
|
|
|
|
- // for (int i = 0; i < received; i++) {
|
|
|
|
|
- // printf("'%c' ", inter_buf[i]);
|
|
|
|
|
- // }
|
|
|
|
|
- // putc('\n', stdout);
|
|
|
|
|
- // if (received == -1) {
|
|
|
|
|
- // LOG_FATALF("recv failed: %d %s", errno, strerror(errno));
|
|
|
|
|
- // } else if (received == 0) {
|
|
|
|
|
- // printf("Player disconnected\n");
|
|
|
|
|
- // break;
|
|
|
|
|
- // } else {
|
|
|
|
|
- // if (buf_len + received + 1 > buf_size) {
|
|
|
|
|
- // buf_size *= 2;
|
|
|
|
|
- // buf = realloc(buf, buf_size);
|
|
|
|
|
- // if (buf == nullptr) {
|
|
|
|
|
- // LOG_FATAL("Failed to increase size of buf");
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // memcpy(buf + buf_len, inter_buf, received);
|
|
|
|
|
- // buf_len += received;
|
|
|
|
|
- // buf[buf_len] = '\0';
|
|
|
|
|
- //
|
|
|
|
|
- // printf("buf: %s\n", buf);
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // // if (received == 0) {
|
|
|
|
|
- // // printf("buf: %s\n", buf);
|
|
|
|
|
- // // buf[0] = '\0';
|
|
|
|
|
- // // break;
|
|
|
|
|
- // // } else if (received == -1) {
|
|
|
|
|
- // // LOG_FATALF("recv failed: %d %s", errno, strerror(errno));
|
|
|
|
|
- // // } else {
|
|
|
|
|
- // // buf[received] = '\0';
|
|
|
|
|
- // // }
|
|
|
|
|
- // // printf("loop buf: %s\n", buf);
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|