Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <ctype.h>
- #include <sys/stat.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- #include <string.h>
- #include <signal.h>
- #include <sys/shm.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <time.h>
- #include <pthread.h>
- #include <errno.h>
- typedef struct fic{
- char nome[50];
- struct fic * next;
- }fic;
- typedef struct config{
- int server_port;
- char* scheduling;
- int threadpool;
- fic allowed[SIZE_BUF];
- }config;
- config* cfg;
- int shm;
- int main(int argc, char ** argv)
- {
- }
- void init(){
- // Criar e mapear memória partilhada
- shm = shmget(1234,sizeof(config),IPC_CREAT|0777);
- cfg = (config *)shmat(shm,NULL,0);
- config_inicial();
- // criar buffer
- b_requests = (request_buffer*)malloc( sizeof(request_buffer));
- b_requests->next = NULL;
- // alocar memória para a estrutura da mesage queue (mudar para memória partilhada)
- statistics = (statistics_gerais*)malloc( sizeof(statistics_gerais));
- }
- void config_inicial(){
- FILE * fp;
- char line[1024];
- char split[2] = " ";
- int i;
- char *token;
- fic * ptr = cfg->allowed;
- fic * novo;
- i=0;
- if((fp=fopen("config.txt","rt"))==NULL) {
- // ficheiro not found
- printf("Ficheiro de configuracao nao encontrado. DEFAULT CONFIG\n");
- cfp->server_port = port;
- cfg->scheduling= "NORMAL"
- cfg->threadpool = DEFAULT_NT;
- strcpy (cfg->allowed->nome, "ALL");
- }
- else {
- // ficheiro found
- while(fgets(line, 1024, fp) != NULL){
- //printf("%s\n", line);
- if (i==0){
- if (atoi(line) != port){
- printf("O porto actual não corresponde ao porto no ficheiro de configuracao. O server vais terminar");
- exit(0);
- }
- }
- else if (i==1)
- cfg->scheduling = line;
- else if (i==2)
- cfg->threadpool = atoi(line);
- else if (i==3){
- token = strtok(line,split);
- while (token != NULL){
- novo = (fic *) malloc ( sizeof(fic));
- novo->next = NULL;
- strcpy(novo->nome, token);
- ptr->next = novo;
- ptr = novo;
- //printf("%s\n", ptr->nome);
- token = strtok(NULL,split);
- }
- }
- i++;
- }
- // Close file
- fclose(fp);
- }
- free(ptr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement