Beispiel #1
0
void IniConfig::read ()
{
    char *path = NULL;
    ini_fd_t ini  = 0;
    char   *configPath;
    size_t  length;

#ifdef _WIN32
    path = (char *) getenv("USERPROFILE");
#endif
#ifdef HAVE_UNIX
    path = (char *) getenv("HOME");
#endif

    if (!path)
        goto IniConfig_read_error;

    length = strlen(path) + strlen(DIR_NAME) + strlen(FILE_NAME) + 3;
    configPath = (char *) malloc(length);
    if (! configPath)
        goto IniConfig_read_error;

    sprintf(configPath, "%s/%s", path, DIR_NAME);

#ifdef HAVE_UNIX
    // Make sure the config path exists
    if (!opendir(configPath))
        mkdir(configPath, 0755);
#endif
#ifdef _WIN32
    CreateDirectory(configPath, NULL);
#endif

    /* sprintf on top of itself fails nowadays. */
    strcat(configPath, "/");
    strcat(configPath, FILE_NAME);

    // Opens an existing file or creates a new one
    ini = ini_open (configPath, "w", ";");

    // Unable to open file?
    if (!ini)
        goto IniConfig_read_error;

    clear ();

    // This may not exist here...
    status &= readSidplay2  (ini);
    status &= readConsole   (ini);
    status &= readAudio     (ini);
    status &= readEmulation (ini);
    ini_close (ini);
return;

IniConfig_read_error:
    if (ini)
        ini_close (ini);
    clear ();
    status = false;
}
Beispiel #2
0
int main() {
	openClient(0);
	clientRedirectionCreate(getpid());
	sendData(0, fillMessageData("client", "register", ""), sizeof(Message));
	clientRedirection(0, getpid());
	getResponce(0);
	while (1) {
		readConsole();
	}
	return 1;
}
Beispiel #3
0
str
MALreader(Client c)
{
	int r = 1;

	if (c == mal_clients) {
		r = readConsole(c);
		if (r < 0 && c->fdin->eof == 0)
			r = MCreadClient(c);
		if (r > 0)
			return MAL_SUCCEED;
	} else if (MCreadClient(c) > 0)
		return MAL_SUCCEED;
	MT_lock_set(&mal_contextLock);
	c->mode = FINISHCLIENT;
	MT_lock_unset(&mal_contextLock);
	if (c->fdin)
		c->fdin->buf[c->fdin->pos] = 0;
	else
		throw(MAL, "mal.reader", RUNTIME_IO_EOF);
	return MAL_SUCCEED;
}
Beispiel #4
0
int main(int argc, char **argv) {
    int sockfd, portno, n;
    struct sockaddr_in serveraddr;
    struct hostent *server;
    char *hostname;
    char buf[BUFSIZE];
    

    hostname = argv[1];
    portno = atoi(argv[2]);
    
    /* socket: create the socket */
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0)
        error("ERROR opening socket");
    
    /* gethostbyname: get the server's DNS entry */
    server = gethostbyname(hostname);
    if (server == NULL) {
        fprintf(stderr,"ERROR, no such host as %s\n", hostname);
        exit(0);
    }
    
    /* build the server's Internet address */
    bzero((char *) &serveraddr, sizeof(serveraddr));
    serveraddr.sin_family = AF_INET;
    bcopy((char *)server->h_addr,
          (char *)&serveraddr.sin_addr.s_addr, server->h_length);
    serveraddr.sin_port = htons(portno);
    
    
    //============================================================
    /* connect: create a connection with the server */
    if (connect(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0)
        error("ERROR connecting");
    
    //================================================================================
    int listenPID=fork();
    if(listenPID==0){//child proc for listen
        listenPID = getpid();
        while(1){
            bzero(buf, BUFSIZE);
            n = read(sockfd, buf, BUFSIZE);
            if (n < 0)
                error("ERROR reading from socket");
            printf("Echo from server: %s", buf);
        }
    }
    
    while(buf[0]!=':'){

        bzero(buf, BUFSIZE);
        readConsole(buf);
        if(fork()==0){
            n = write(sockfd, buf, strlen(buf));
            if (n < 0)
                error("ERROR writing to socket");
            exit(0);
        }   
    }
    
    
    kill(listenPID,SIGKILL);
    close(sockfd);
    return 0;
    
        
    
}