Fixed uninitialized timeout variables in metadata_server_main() and chunk_server_main() functions by setting default value to -1. **Changes:** - metadata_server_main(): Changed `int timeout;` to `int timeout = -1;` - chunk_server_main(): Changed `int timeout;` to `int timeout = -1;` This ensures the timeout parameter has a defined default value before being passed to init functions, which is important for predictable behavior even though the init functions set the value themselves. All build targets (tinydfs_server.out, example_client.out, tinydfs_test.out) compile and run successfully.
73 lines
1.7 KiB
C
73 lines
1.7 KiB
C
#ifdef BUILD_SERVER
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef _WIN32
|
|
#include <winsock2.h>
|
|
#define POLL WSAPoll
|
|
#else
|
|
#include <poll.h>
|
|
#define POLL poll
|
|
#endif
|
|
|
|
#include "chunk_server.h"
|
|
#include "metadata_server.h"
|
|
|
|
int metadata_server_main(int argc, char **argv)
|
|
{
|
|
void *contexts[MAX_CONNS+1];
|
|
struct pollfd polled[MAX_CONNS+1];
|
|
int num_polled;
|
|
int timeout = -1;
|
|
MetadataServer state;
|
|
num_polled = metadata_server_init(
|
|
&state, argc, argv, contexts, polled, &timeout);
|
|
if (num_polled < 0) return -1;
|
|
for (;;) {
|
|
POLL(polled, num_polled, -1);
|
|
num_polled = metadata_server_step(
|
|
&state, contexts, polled, num_polled, &timeout);
|
|
if (num_polled < 0) return -1;
|
|
}
|
|
metadata_server_free(&state);
|
|
return 0;
|
|
}
|
|
|
|
int chunk_server_main(int argc, char **argv)
|
|
{
|
|
void *contexts[MAX_CONNS+1];
|
|
struct pollfd polled[MAX_CONNS+1];
|
|
int num_polled;
|
|
int timeout = -1;
|
|
ChunkServer state;
|
|
num_polled = chunk_server_init(
|
|
&state, argc, argv, contexts, polled, &timeout);
|
|
if (num_polled < 0) return -1;
|
|
for (;;) {
|
|
POLL(polled, num_polled, -1);
|
|
num_polled = chunk_server_step(
|
|
&state, contexts, polled, num_polled, &timeout);
|
|
if (num_polled < 0) return -1;
|
|
}
|
|
chunk_server_free(&state);
|
|
return 0;
|
|
}
|
|
|
|
bool is_leader(int argc, char **argv)
|
|
{
|
|
for (int i = 1; i < argc; i++)
|
|
if (!strcmp(argv[i], "--leader") || !strcmp(argv[i], "-l"))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
if (is_leader(argc, argv))
|
|
return metadata_server_main(argc, argv);
|
|
else
|
|
return chunk_server_main(argc, argv);
|
|
}
|
|
|
|
#endif
|