examevalserv.c File Reference

#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 Documentation

#define BUFFER_SIZE   4096

Definition at line 17 of file examevalserv.c.

Referenced by sendques().

#define LEN   1000

Definition at line 23 of file examevalserv.c.

Referenced by main(), search(), and sendques().

#define NUM_STUDENTS   1000

Definition at line 20 of file examevalserv.c.

Referenced by main().

#define SERVER_PORT   8000

Definition at line 19 of file examevalserv.c.


Function Documentation

void close_properly ( int  signal  ) 

To shut down a signal properly.

Parameters:
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.

Returns:
nothing.
Parameters:
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.

Returns:
Marks for the specified level.
Parameters:
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.

Returns:
the question number generated by random function.
Parameters:
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.

Returns:
zero to calling program on success, else 1.
Parameters:
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.

Parameters:
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().


Variable Documentation

MYSQL* connection1

Definition at line 27 of file examevalserv.c.

Referenced by display_row(), main(), and search().

MYSQL* connection2

Definition at line 28 of file examevalserv.c.

int connection_file_descriptor[NUM_STUDENTS]

Definition at line 34 of file examevalserv.c.

Referenced by main(), and sendques().

Definition at line 33 of file examevalserv.c.

Referenced by close_properly(), and main().

Definition at line 26 of file examevalserv.c.

Referenced by main().

int NUM_QS

Definition at line 24 of file examevalserv.c.

Referenced by main(), and sendques().

MYSQL_RES* result1

Definition at line 29 of file examevalserv.c.

Referenced by search().

MYSQL_RES* result2

Definition at line 30 of file examevalserv.c.

MYSQL_ROW sqlrow

Definition at line 31 of file examevalserv.c.

Referenced by display_row(), and search().

int TOTAL_QS

Definition at line 25 of file examevalserv.c.

Referenced by found(), and main().


Generated on Wed Apr 7 23:01:43 2010 for project by  doxygen 1.5.8