Beispiel #1
0
int main( int argc, char *argv[] )
{
	Shell *susan = new Shell();
	       susan->Run();
	delete susan;
  return 0;	
}
Beispiel #2
0
int Server::ServerProcess(){
    int fd;
    sockaddr_in cliaddr;
    int addrlen = sizeof(cliaddr); 
    if((fd = accept(sockfd, (sockaddr*)&cliaddr, (socklen_t*)&addrlen)) < 0){
		return -1;
	}
    //set_nonblock(fd);
    int id = InsertNewClient(fd, cliaddr);
    char _msg[256] = {0};
    sprintf(_msg, "*** User \'%s\' entered from %s/%d. ***\n", clients[id].nickname, clients[id].ip, clients[id].port);
	int pid = fork();
	if(pid == 0){
		dup2(fd, STDIN_FILENO);
		dup2(fd, STDOUT_FILENO);
		dup2(fd, STDERR_FILENO);
		close(fd);
		Shell sh;
        printf("%s", _msg);
        sh.Prompt();
		sh.Run(id, shm_id);
		exit(0);
	}else if(pid > 0){
        //int sem = shm_sem_open(msg[id].key);
        int sem = msg[id].id;
        shm_sem_wait(sem);
        msg[id].Init();
        shm_sem_post(sem);
        //shm_sem_close(sem);
        for(int i=1;i<MAX_CLIENT_SIZE;i++)
            if(clients[i].used && i != id)
                msg[i].Append(_msg);
        client_pid.insert(pid);
        close(fd);
		return 0;
	}else{
		return -1;
	}
}
Beispiel #3
0
int main(int argc, char *argv[])
{
	Shell shell;
	shell.Run(argc, argv);
	return 0;
}