Beispiel #1
0
void	client_read(t_env *env, int cs)
{
	int	ret;

	ret = recv(cs, env->fds[cs].buff_read, BUFF_SIZE, 0);
	env->fds[cs].buff_read[ret] = 0;
	if (ret <= 0)
	{
		close(cs);
		env->fds[cs].type = 0;
		env->fds[cs].fct_read = NULL;
		env->fds[cs].fct_write = NULL;
		env->fds[cs].save = NULL;
		free(env->fds[cs].nick);
		env->fds[cs].nick = NULL;
		env->fds[cs].channel = -1;
		printf("client #%d disconected\n", cs);
	}
	else
	{
		if (print_pkg(env, cs, ret))
		{
			free(env->fds[cs].save);
			env->fds[cs].save = NULL;
		}
	}
}
Beispiel #2
0
int main(int argc, char *argv[])
{
  alpm_list_t *results = NULL, *targets = NULL;
  expac_t *expac = NULL;
  int r;

  r = parse_options(&argc, &argv);
  if(r < 0) {
    return 1;
  }

  targets = process_targets(argc, argv);

  r = expac_new(&expac, opt_config_file);
  if(r < 0) {
    return 1;
  }

  results = expac_search(expac, opt_corpus, targets);
  if(results == NULL) {
    return 1;
  }

  for(alpm_list_t *i = results; i; i = i->next) {
    print_pkg(i->data, opt_format);
  }

  alpm_list_free_inner(targets, free);
  alpm_list_free(targets);
  alpm_list_free(results);
  expac_free(expac);

  return 0;
}
Beispiel #3
0
int main(int argc, char *argv[]) {
  int ret = 1;
  alpm_handle_t *alpm;
  alpm_list_t *results = NULL, *i;

  alpm = alpm_init();
  if (!alpm) {
    return ret;
  }

  ret = parse_options(argc, argv, alpm);
  if (ret != 0) {
    goto finish;
  }

  /* ensure sane defaults */
  if (!dblist && !opt_localpkg) {
    opt_local = true;
    dblist = alpm_list_add(dblist, db_local);
  }

  results = gather_packages(alpm, targets);
  if (results == NULL) {
    ret = 1;
    goto finish;
  }

  for (i = results; i; i = alpm_list_next(i)) {
    alpm_pkg_t *pkg = i->data;
    ret += print_pkg(pkg, opt_format);
  }
  ret = !!ret; /* clamp to zero/one */

  if(opt_localpkg) {
    alpm_list_free_inner(results, (alpm_list_fn_free)alpm_pkg_free);
  }
  alpm_list_free(results);

finish:
  alpm_list_free(dblist);
  alpm_list_free(targets);
  alpm_release(alpm);
  return ret;
}
Beispiel #4
0
void* tf_read(void *args) {

    int oldstate;
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);

    
    setup_termination();
    void *load;
    int nRead;
    uint8_ buf[3];
    uint8_ *pkg;
    int len;
    int iid;
    int id;
    int sender;
    struct payload_pkg_rob_command *pkg_rob_comm;
    struct payload_pkg_trajectory  *pach;

    xbee_packet_received = 0;
    xbee_ack_received = 0;

    while (1) {

        printf("------------\n");
        
        
        iid = -1;

        /* Look for a command */
        /* Lock the mutex on the job queue. */
        nRead = readport(xbee_fd_r, buf, 3);

        if (nRead == 3) {
		if (buf[0] == 0x7e) {
                printf("%02x\t%02x\n", buf[1], buf[2]);
                len = MSB_LSB_2_INT(buf + 1, 2);
                if (len > 0) {
                    printf("Len pkg: %d\t", len);
                    pkg = (uint8_ *) malloc(sizeof (uint8_)*(len + 1));
                    nRead = readport(xbee_fd_r, pkg, len + 1);
                    sender = pkg[2];
                    printf("Sender: %2x\t%d\n", pkg[2], sender);
                    ++xbee_packet_neighborhood[sender];
                    printf("Read pkg: %d\n", nRead);
                    id = pkg_dispatcher(pkg, nRead, &iid, &load);
                    if (id == rx_pack_16 && iid == pkg_1) {
                        printf("---PARSER----\n");
                        printf("Long: %ld\n", ((struct payload_pkg1 *) load)->i);
                        printf("Float: %f\n", ((struct payload_pkg1 *) load)->j);
                    }
		xbee_packet_received++;
                    switch (iid) {

			   
                        case pkg_state:
                            //printf("pkg_state\n");
			    break;
			case pkg_trajectory:
			    pach=(struct payload_pkg_trajectory*)load; 
			    v_xbee=pach->v;
			    w_xbee=pach->w;
			    fprintf(stderr,"VELOCITA' RICEVUTE DA MATLAB: line=%f ang=%f\n",pach->v,pach->w);
			    break;
                        case pkg_webcam_data:
                            printf("pkg_webcam_data\n");
                            break;

                        case pkg_rob_command:
                            printf("pkg_rob_command\n");
                            pkg_rob_comm = (struct payload_pkg_rob_command *) load;
                            console_current_command = pkg_rob_comm->command[0];
                            console_current_value1 = pkg_rob_comm->value;

                            switch (console_current_command) {
                                case 'v':
                                    printf("Command v\tValue: %d\n", console_current_value1);
                                    set_vel_2_array(pic_buffer[pic_last_vel_2_send], console_current_value1, console_current_value1);
                                    pic_last_vel_2_send %= LEN_PIC_BUFFER;
                                    break;

                                case 'p':
                                    printf("Command p\tValue: %d\n", console_current_value1);
                                    break;

                                case 'd':
                                    printf("Command d\tValue: %d\n", console_current_value1);
                                    break;
                                case 't':
                                    printf("Command d\tValue: %d\n", console_current_value1);
                                    break;
                                case 's':
                                    printf("Command s\tValue: %d\n", console_current_value1);
                                    break;
                                default:
                                    break;
                            }

                            break;

                        default:
                            break;

                    }


                    free(pkg);
                }
                printf("Len: %d\n", len);

            }
#ifdef VERBOSE_XBEE
            printf("nRead(in): %d\t", nRead);
            print_pkg(buf, nRead);
#endif
        }
#ifdef VERBOSE_XBEE
        printf("nRead(out): %d\t", nRead);
        print_pkg(buf, nRead);
#endif
    }
    pthread_exit(NULL);

}