#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <time.h>
#include <signal.h>
#include <poll.h>
#include <pthread.h>
#include <mysql/mysql.h>
Go to the source code of this file.
Defines | |
#define | BUFFER_SIZE 4096 |
#define | SERVER_PORT 8000 |
#define | NUM_STUDENTS 1000 |
#define | LEN 1000 |
Functions | |
void | display_row (char ques[]) |
Display a row from the table and stores it in string. | |
void | search (int quesno, char ques[], int level) |
Searches for the specified question in the database and stores in ques. | |
int | find (int level) |
Returns the marks corresponding to particular level. | |
int | found (int levels[], int qno[], int numqs, int curlevel) |
Used to search whether the question generated by random function , rand() is already generated or not. | |
void * | sendques (void *arg) |
Thread function that is specific to each client. | |
void | close_properly (int signal) |
To shut down a signal properly. | |
int | main (int argc, char *argv[]) |
The program will listen on some port defined in LISTEN_PORT (default 8000) at top and call read with large value (default sizeof(BUFFER)). | |
Variables | |
int | NUM_QS |
int | TOTAL_QS |
int | LISTEN_PORT |
MYSQL * | connection1 |
MYSQL * | connection2 |
MYSQL_RES * | result1 |
MYSQL_RES * | result2 |
MYSQL_ROW | sqlrow |
int | listen_file_descriptor |
int | connection_file_descriptor [NUM_STUDENTS] |
#define BUFFER_SIZE 4096 |
#define LEN 1000 |
#define NUM_STUDENTS 1000 |
#define SERVER_PORT 8000 |
Definition at line 19 of file examevalserv.c.
void close_properly | ( | int | signal | ) |
To shut down a signal properly.
signal | Signal identifier. |
Definition at line 234 of file examevalserv.c.
References listen_file_descriptor.
Referenced by main().
void display_row | ( | char | ques[] | ) |
Display a row from the table and stores it in string.
ques | Takes a question. |
Definition at line 43 of file examevalserv.c.
References connection1, and sqlrow.
Referenced by search().
int find | ( | int | level | ) |
Returns the marks corresponding to particular level.
level | Level of the question. |
Definition at line 116 of file examevalserv.c.
Referenced by sendques().
int found | ( | int | levels[], | |
int | qno[], | |||
int | numqs, | |||
int | curlevel | |||
) |
Used to search whether the question generated by random function , rand() is already generated or not.
levels | Array of levels. | |
qno | Array of question numbers already sent. | |
numqs | Number of questions answered by the client till now. Current level of the client. |
Definition at line 137 of file examevalserv.c.
References TOTAL_QS.
Referenced by sendques().
int main | ( | int | argc, | |
char * | argv[] | |||
) |
The program will listen on some port defined in LISTEN_PORT (default 8000) at top and call read with large value (default sizeof(BUFFER)).
The program takes database details and no. of questions as input. It creates one thread for each client connection.
argc | number of command line arguments passed to the program including program name itself. | |
argv | array of command line arguments. |
Definition at line 261 of file examevalserv.c.
References close_properly(), connection1, connection_file_descriptor, LEN, listen_file_descriptor, LISTEN_PORT, NUM_QS, NUM_STUDENTS, sendques(), SERVER_PORT, and TOTAL_QS.
void search | ( | int | quesno, | |
char | ques[], | |||
int | level | |||
) |
Searches for the specified question in the database and stores in ques.
returns nothing.
quesno | question number to send. | |
ques | to store question from database. | |
level | level of question. |
Definition at line 75 of file examevalserv.c.
References connection1, display_row(), LEN, result1, and sqlrow.
Referenced by sendques().
void* sendques | ( | void * | arg | ) |
Thread function that is specific to each client.
Used to send question to client, reads answer and sends the result back to client. It calls functions found(),search().
arg Argument to the thread function
Definition at line 168 of file examevalserv.c.
References BUFFER_SIZE, connection_file_descriptor, find(), found(), LEN, NUM_QS, and search().
Referenced by main().
MYSQL* connection1 |
MYSQL* connection2 |
Definition at line 28 of file examevalserv.c.
int connection_file_descriptor[NUM_STUDENTS] |
int LISTEN_PORT |
int NUM_QS |
MYSQL_RES* result1 |
MYSQL_RES* result2 |
Definition at line 30 of file examevalserv.c.
MYSQL_ROW sqlrow |
int TOTAL_QS |