Exemplo n.º 1
0
Arquivo: m.c Projeto: aclark4life/CS
void main(int argc) {
        if (argc!=1) { exit(-1); }
        else {
		get_mn();
		get_mem();
		get_mtrx();
	}
}
Exemplo n.º 2
0
int mn_recv(int sock, char *client_message, int *mn, struct mes_buf mesbuf[100], struct timeval *timeout, fd_set *readset){
    char msg_with_n[BUFLEN], tmp[BUFLEN];
    int read_size, new_mn, buf_read_size, reason;

    while(reason = select(sock+1, readset, NULL, NULL, timeout) > 0){

    if( (read_size = recv(sock , msg_with_n, BUFLEN , 0)) > 0){
        if(strncmp(msg_with_n,"BEY",3) == 0){
            return -1;           
        }
        new_mn = get_mn(msg_with_n);
        if( (buf_read_size = get_from_buf(*mn+1, mesbuf, tmp)) > 0){
            *mn = *mn + 1;
            strcpy(client_message, tmp);
            return buf_read_size;
        }
        else{
            strcpy(tmp, msg_with_n+4);
            if( new_mn == *mn + 1){
                *mn = *mn + 1;
                strcpy(client_message, tmp);
                return strlen(client_message);
            }
            else{
                if(new_mn > *mn + 1){
                    add_to_buf(new_mn, tmp, &mesbuf[100]);
                }
                if(new_mn < *mn + 1) puts("duplicated message");
            }
        }
    }

    }
    
    if( (buf_read_size = get_from_buf(*mn+1, mesbuf, tmp)) > 0){
        *mn = *mn + 1;
        return buf_read_size;
    }
    
    return reason;

}