#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#define PORT 3498
#define DISP 1
#define DEST (-1)
#define MAX_RETRIES 5 /*the client will try up to MAX_RETRIES times to connect
to the dispatcher.*/
#define MAX_QUEUE 5
//#define BUSY 1
//#define IDLE 0
#define RETRY_DELAY 1
#define DELAY 30
/*define a structure of the node in the server's list.
including the information of the ip address, port
number and services provided by servers.*/
typedef struct serverlist
{
char addr[50]; /*server's ip address.*/
int port; /*server's port no.*/
int sid; /*services provied by the server.*/
struct serverlist *next;
}s_list;
/*function prototypes*/
void roundrobin(s_list **);
void searchlist(s_list **);
void addlist(s_list **,s_list *);
void deletelist(s_list **,char*, int );
int connect_remote(char *,int,int *,struct sockaddr_in *);
int bind_remote(int,int *,struct sockaddr_in *);
int operation(char *,int,int,int*);
int sum(int,int,int*);
int product(int,int,int *);
void myhandler(int);
int provide_service(char *);