Fix compilation errors for non-test builds
Fixed build errors in tinydfs_server and example_client targets caused by missing timeout parameter and simulation client references. **Changes:** **main_server.c:** - Added int timeout variable declaration in metadata_server_main() - Added int timeout variable declaration in chunk_server_main() - Pass &timeout to metadata_server_init() call - Pass &timeout to metadata_server_step() call - Pass &timeout to chunk_server_init() call - Pass &timeout to chunk_server_step() call **system.c:** - Guarded simulation_client.h include with #ifdef BUILD_TEST - Guarded PROCESS_TYPE_CLIENT enum value with #ifdef BUILD_TEST - Guarded SimulationClient member in Process union with #ifdef BUILD_TEST - Guarded is_client() function with #ifdef BUILD_TEST - Guarded client detection logic in spawn_simulated_process() - Guarded PROCESS_TYPE_CLIENT cases in all switch statements: - spawn_simulated_process() init switch - free_process() cleanup switch - update_simulation() step switch **Result:** - tinydfs_server.out now compiles successfully - example_client.out now compiles successfully - tinydfs_test.out continues to work correctly - Simulation client code only included when BUILD_TEST is defined - All three build targets pass compilation with only pre-existing warnings The simulation_client code is now properly isolated to test builds only, preventing linker errors when building the real server and example client.
This commit is contained in:
+6
-4
@@ -18,14 +18,15 @@ int metadata_server_main(int argc, char **argv)
|
|||||||
void *contexts[MAX_CONNS+1];
|
void *contexts[MAX_CONNS+1];
|
||||||
struct pollfd polled[MAX_CONNS+1];
|
struct pollfd polled[MAX_CONNS+1];
|
||||||
int num_polled;
|
int num_polled;
|
||||||
|
int timeout;
|
||||||
MetadataServer state;
|
MetadataServer state;
|
||||||
num_polled = metadata_server_init(
|
num_polled = metadata_server_init(
|
||||||
&state, argc, argv, contexts, polled);
|
&state, argc, argv, contexts, polled, &timeout);
|
||||||
if (num_polled < 0) return -1;
|
if (num_polled < 0) return -1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
POLL(polled, num_polled, -1);
|
POLL(polled, num_polled, -1);
|
||||||
num_polled = metadata_server_step(
|
num_polled = metadata_server_step(
|
||||||
&state, contexts, polled, num_polled);
|
&state, contexts, polled, num_polled, &timeout);
|
||||||
if (num_polled < 0) return -1;
|
if (num_polled < 0) return -1;
|
||||||
}
|
}
|
||||||
metadata_server_free(&state);
|
metadata_server_free(&state);
|
||||||
@@ -37,14 +38,15 @@ int chunk_server_main(int argc, char **argv)
|
|||||||
void *contexts[MAX_CONNS+1];
|
void *contexts[MAX_CONNS+1];
|
||||||
struct pollfd polled[MAX_CONNS+1];
|
struct pollfd polled[MAX_CONNS+1];
|
||||||
int num_polled;
|
int num_polled;
|
||||||
|
int timeout;
|
||||||
ChunkServer state;
|
ChunkServer state;
|
||||||
num_polled = chunk_server_init(
|
num_polled = chunk_server_init(
|
||||||
&state, argc, argv, contexts, polled);
|
&state, argc, argv, contexts, polled, &timeout);
|
||||||
if (num_polled < 0) return -1;
|
if (num_polled < 0) return -1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
POLL(polled, num_polled, -1);
|
POLL(polled, num_polled, -1);
|
||||||
num_polled = chunk_server_step(
|
num_polled = chunk_server_step(
|
||||||
&state, contexts, polled, num_polled);
|
&state, contexts, polled, num_polled, &timeout);
|
||||||
if (num_polled < 0) return -1;
|
if (num_polled < 0) return -1;
|
||||||
}
|
}
|
||||||
chunk_server_free(&state);
|
chunk_server_free(&state);
|
||||||
|
|||||||
+20
-1
@@ -5,7 +5,9 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "chunk_server.h"
|
#include "chunk_server.h"
|
||||||
#include "metadata_server.h"
|
#include "metadata_server.h"
|
||||||
|
#ifdef BUILD_TEST
|
||||||
#include "simulation_client.h"
|
#include "simulation_client.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define NATIVE_HANDLE HANDLE
|
#define NATIVE_HANDLE HANDLE
|
||||||
@@ -135,7 +137,9 @@ typedef struct {
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
PROCESS_TYPE_METADATA_SERVER,
|
PROCESS_TYPE_METADATA_SERVER,
|
||||||
PROCESS_TYPE_CHUNK_SERVER,
|
PROCESS_TYPE_CHUNK_SERVER,
|
||||||
|
#ifdef BUILD_TEST
|
||||||
PROCESS_TYPE_CLIENT,
|
PROCESS_TYPE_CLIENT,
|
||||||
|
#endif
|
||||||
} ProcessType;
|
} ProcessType;
|
||||||
|
|
||||||
struct Process {
|
struct Process {
|
||||||
@@ -152,7 +156,9 @@ struct Process {
|
|||||||
union {
|
union {
|
||||||
ChunkServer chunk_server;
|
ChunkServer chunk_server;
|
||||||
MetadataServer metadata_server;
|
MetadataServer metadata_server;
|
||||||
|
#ifdef BUILD_TEST
|
||||||
SimulationClient simulation_client;
|
SimulationClient simulation_client;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -244,6 +250,7 @@ static bool is_leader(int argc, char **argv)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUILD_TEST
|
||||||
static bool is_client(int argc, char **argv)
|
static bool is_client(int argc, char **argv)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++)
|
||||||
@@ -251,6 +258,7 @@ static bool is_client(int argc, char **argv)
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAX_ARGS 128
|
#define MAX_ARGS 128
|
||||||
|
|
||||||
@@ -299,16 +307,21 @@ int spawn_simulated_process(char *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool leader = is_leader(argc, argv);
|
bool leader = is_leader(argc, argv);
|
||||||
|
#ifdef BUILD_TEST
|
||||||
bool client = is_client(argc, argv);
|
bool client = is_client(argc, argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
Process *process = malloc(sizeof(Process));
|
Process *process = malloc(sizeof(Process));
|
||||||
if (process == NULL)
|
if (process == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Determine process type
|
// Determine process type
|
||||||
|
#ifdef BUILD_TEST
|
||||||
if (client) {
|
if (client) {
|
||||||
process->type = PROCESS_TYPE_CLIENT;
|
process->type = PROCESS_TYPE_CLIENT;
|
||||||
} else if (leader) {
|
} else
|
||||||
|
#endif
|
||||||
|
if (leader) {
|
||||||
process->type = PROCESS_TYPE_METADATA_SERVER;
|
process->type = PROCESS_TYPE_METADATA_SERVER;
|
||||||
} else {
|
} else {
|
||||||
process->type = PROCESS_TYPE_CHUNK_SERVER;
|
process->type = PROCESS_TYPE_CHUNK_SERVER;
|
||||||
@@ -334,9 +347,11 @@ int spawn_simulated_process(char *args)
|
|||||||
case PROCESS_TYPE_CHUNK_SERVER:
|
case PROCESS_TYPE_CHUNK_SERVER:
|
||||||
num_polled = chunk_server_init(&process->chunk_server, argc, argv, contexts, polled, &timeout);
|
num_polled = chunk_server_init(&process->chunk_server, argc, argv, contexts, polled, &timeout);
|
||||||
break;
|
break;
|
||||||
|
#ifdef BUILD_TEST
|
||||||
case PROCESS_TYPE_CLIENT:
|
case PROCESS_TYPE_CLIENT:
|
||||||
num_polled = simulation_client_init(&process->simulation_client, argc, argv, contexts, polled, &timeout);
|
num_polled = simulation_client_init(&process->simulation_client, argc, argv, contexts, polled, &timeout);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
num_polled = -1;
|
num_polled = -1;
|
||||||
break;
|
break;
|
||||||
@@ -368,9 +383,11 @@ static void free_process(Process *process)
|
|||||||
case PROCESS_TYPE_CHUNK_SERVER:
|
case PROCESS_TYPE_CHUNK_SERVER:
|
||||||
chunk_server_free(&process->chunk_server);
|
chunk_server_free(&process->chunk_server);
|
||||||
break;
|
break;
|
||||||
|
#ifdef BUILD_TEST
|
||||||
case PROCESS_TYPE_CLIENT:
|
case PROCESS_TYPE_CLIENT:
|
||||||
simulation_client_free(&process->simulation_client);
|
simulation_client_free(&process->simulation_client);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
free(process);
|
free(process);
|
||||||
}
|
}
|
||||||
@@ -553,9 +570,11 @@ void update_simulation(void)
|
|||||||
case PROCESS_TYPE_CHUNK_SERVER:
|
case PROCESS_TYPE_CHUNK_SERVER:
|
||||||
num_polled = chunk_server_step(¤t_process->chunk_server, contexts, polled, num_polled, &timeout);
|
num_polled = chunk_server_step(¤t_process->chunk_server, contexts, polled, num_polled, &timeout);
|
||||||
break;
|
break;
|
||||||
|
#ifdef BUILD_TEST
|
||||||
case PROCESS_TYPE_CLIENT:
|
case PROCESS_TYPE_CLIENT:
|
||||||
num_polled = simulation_client_step(¤t_process->simulation_client, contexts, polled, num_polled, &timeout);
|
num_polled = simulation_client_step(¤t_process->simulation_client, contexts, polled, num_polled, &timeout);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_polled < 0) {
|
if (num_polled < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user