Question: Implement this server in C: /* myloggerd.c * Source file for thread-lab * Creates a server to log messages sent from various connections * in
Implement this server in C:
/* myloggerd.c * Source file for thread-lab * Creates a server to log messages sent from various connections * in real time. * * Student: */ #include
// forward declarations int usage( char name[] ); // a function to be executed by each thread void * recv_log_msgs( void * arg );
// globals int log_fd; // opened by main() but accessible by each thread
void * recv_log_msgs( void * arg ){ // loops to receive messages from a connection; // when read_msg returns zero, terminate the loop // and close the connection
return NULL; }
int usage( char name[] ){ printf( "Usage: " ); printf( "\t%s
int main( int argc, char * argv[] ) { if ( argc != 3 ) return usage( argv[0] ); // open the log file for appending // permit message connections // loop to wait for connection requests; // as each connection is accepted, // launch a new thread that calls // recv_log_msgs(), which receives // messages and writes them to the log file // when accept_next_connection returns -1, terminate the loop // close the listener // close the log file
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
