Example #1
0
IRC_Session::IRC_Session(ServerProfile profile, QObject *parent = 0, QTreeWidget *sParent = 0)  : Irc::Session(parent) {

    ChanList.insert("status",new irc_channel);
    ServerItem = new QTreeWidgetItem(sParent);
    ServerItem->setText(0,profile.HostName);
    Message temp = ChanList["status"]->append("INIT","*","Initializing protocol..");
    emit init_message(this,temp);

    connect(this, SIGNAL(connected()), SLOT(on_connected()));
    connect(this, SIGNAL(disconnected()), SLOT(on_disconnected()));
    connect(this, SIGNAL(msgQuit(QString, QString)), SLOT(on_msgQuit(QString, QString)));
    connect(this, SIGNAL(msgJoined(QString, QString)), SLOT(on_msgJoined(QString, QString)));
    connect(this, SIGNAL(msgNickChanged(QString, QString)), SLOT(on_msgNickChanged(QString, QString)));
    connect(this, SIGNAL(msgParted(QString, QString, QString)), SLOT(on_msgParted(QString, QString, QString)));
    connect(this, SIGNAL(msgInvited(QString, QString, QString)), SLOT(on_msgInvited(QString, QString, QString)));
    connect(this, SIGNAL(msgCtcpReplyReceived(QString, QString)), SLOT(on_msgCtcpReplyReceived(QString, QString)));
    connect(this, SIGNAL(msgCtcpRequestReceived(QString, QString)), SLOT(on_msgCtcpRequestReceived(QString, QString)));
    connect(this, SIGNAL(msgTopicChanged(QString, QString, QString)), SLOT(on_msgTopicChanged(QString, QString, QString)));
    connect(this, SIGNAL(msgNoticeReceived(QString, QString, QString)), SLOT(on_msgNoticeReceived(QString, QString, QString)));
    connect(this, SIGNAL(msgKicked(QString, QString, QString, QString)), SLOT(on_msgKicked(QString, QString, QString, QString)));
    connect(this, SIGNAL(msgMessageReceived(QString, QString, QString)), SLOT(on_msgMessageReceived(QString, QString, QString)));
    connect(this, SIGNAL(msgUnknownMessageReceived(QString, QStringList)), SLOT(on_msgUnknownMessageReceived(QString, QStringList)));
    connect(this, SIGNAL(msgCtcpActionReceived(QString, QString, QString)), SLOT(on_msgCtcpActionReceived(QString, QString, QString)));
    connect(this, SIGNAL(msgModeChanged(QString, QString, QString, QString)), SLOT(on_msgModeChanged(QString, QString, QString, QString)));
    connect(this, SIGNAL(msgNumericMessageReceived(QString, uint, QStringList)), SLOT(on_msgNumericMessageReceived(QString, uint, QStringList)));

    temp = ChanList["status"]->append("INIT","*","Setting up server environment..");
    emit init_message(this,temp);

    setAutoJoinChannels(Profile->AutoJoinChannels);

    if(ClientProfile->RealName)
        setRealName(ClientProfile->RealName);

}
Example #2
0
mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_pubrel(mqtt_connection_t* connection, uint16_t message_id)
{
  init_message(connection);
  if(append_message_id(connection, message_id) == 0)
    return fail_message(connection);
  return fini_message(connection, MQTT_MSG_TYPE_PUBREL, 0, 1, 0);
}
Example #3
0
mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topic, const char* data, int data_length, int qos, int retain, uint16_t* message_id)
{
  init_message(connection);

  if(topic == NULL || topic[0] == '\0')
    return fail_message(connection);

  if(append_string(connection, topic, c_strlen(topic)) < 0)
    return fail_message(connection);

  if(qos > 0)
  {
    if((*message_id = append_message_id(connection, 0)) == 0)
      return fail_message(connection);
  }
  else
    *message_id = 0;

  if(connection->message.length + data_length > connection->buffer_length)
    return fail_message(connection);
  c_memcpy(connection->buffer + connection->message.length, data, data_length);
  connection->message.length += data_length;

  return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain);
}
Example #4
0
void MessageQueue::on_note(int bus, int channel, int note, int velocity) {
    assert(model);
    Message msg;
    init_message(bus,msg);
    msg.type = Message::TypeMIDI;
    msg.bus = bus;
    msg.bus_channel = channel;
    msg.channel = model->tracks[bus].midi_channel;
    if (note == NoteOff) {
        msg.command = MIDI::CommandNoteOff;
        msg.data1 = 0;
        msg.data2 = 0;
    } else if (note == ValueNone) {
        if (velocity == ValueNone)
            return;
        // aftertouch
        msg.command = MIDI::CommandAftertouch;
        msg.data1 = 0;
        msg.data2 = velocity;
    } else {
        if (velocity == ValueNone)
            velocity = 0x7f;
        msg.command = MIDI::CommandNoteOn;
        msg.data1 = note;
        msg.data2 = velocity;
    }
    push(msg);
}
Example #5
0
mqtt_message_t* mqtt_msg_pubcomp(mqtt_connection_t* connection, uint16_t message_id)
{
  init_message(connection);
  if(append_message_id(connection, message_id) == 0)
    return fail_message(connection);
  return fini_message(connection, MQTT_MSG_TYPE_PUBCOMP, 0, 0, 0);
}
Example #6
0
void videoipc_init(OhmPlugin *plugin)
{
    (void)plugin;

    init_shmem();
    init_message();
}
Example #7
0
mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topic, const char* data, int data_length, int qos, int retain, uint16_t* message_id)
{
    init_message(connection);

    if (topic == NULL || topic[0] == '\0')
        return fail_message(connection);

    if (append_string(connection, topic, strlen(topic)) < 0)
        return fail_message(connection);

    if (qos > 0)
    {
        if ((*message_id = append_message_id(connection, 0)) == 0)
            return fail_message(connection);
    }
    else
        *message_id = 0;

    if (connection->message.length + data_length > connection->buffer_length) {
        // Not enough size in buffer -> fragment this message
        connection->message.fragmented_msg_data_offset = connection->message.length;
        memcpy(connection->buffer + connection->message.length, data, connection->buffer_length - connection->message.length);
        connection->message.length = connection->buffer_length;
        connection->message.fragmented_msg_total_length = data_length + connection->message.fragmented_msg_data_offset;
    } else {
        memcpy(connection->buffer + connection->message.length, data, data_length);
        connection->message.length += data_length;
        connection->message.fragmented_msg_total_length = 0;
    }
    return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain);
}
Example #8
0
static void
erl_init(int ncpu)
{
    init_benchmarking();

#ifdef ERTS_SMP
    erts_system_block_init();
#endif

    erts_init_monitors();
    erts_init_gc();
    erts_init_time();
    erts_init_sys_common_misc();
    erts_init_process(ncpu);
    erts_init_scheduling(use_multi_run_queue,
			 no_schedulers,
			 no_schedulers_online);
    erts_init_cpu_topology(); /* Must be after init_scheduling */
    H_MIN_SIZE      = erts_next_heap_size(H_MIN_SIZE, 0);
    BIN_VH_MIN_SIZE = erts_next_heap_size(BIN_VH_MIN_SIZE, 0);

    erts_init_trace();
    erts_init_binary();
    erts_init_bits();
    erts_init_fun_table();
    init_atom_table();
    init_export_table();
    init_module_table();
    init_register_table();
    init_message();
    erts_bif_info_init();
    erts_ddll_init();
    init_emulator();
    erts_bp_init();
    init_db(); /* Must be after init_emulator */
    erts_bif_timer_init();
    erts_init_node_tables();
    init_dist();
    erl_drv_thr_init();
    init_io();
    init_copy();
    init_load();
    erts_init_bif();
    erts_init_bif_chksum();
    erts_init_bif_binary();
    erts_init_bif_re();
    erts_init_unicode(); /* after RE to get access to PCRE unicode */
    erts_delay_trap = erts_export_put(am_erlang, am_delay_trap, 2);
    erts_late_init_process();
#if HAVE_ERTS_MSEG
    erts_mseg_late_init(); /* Must be after timer (erts_init_time()) and thread
			      initializations */
#endif
#ifdef HIPE
    hipe_mode_switch_init(); /* Must be after init_load/beam_catches/init */
#endif
    packet_parser_init();
    erl_nif_init();
}
Example #9
0
static void send_id_reply(unsigned char id)
{
    init_message();
    radio_tx_buffer[MSG_BYTE_TYPE] = MSG_TYPE_ID_REPLY;
    radio_tx_buffer[MSG_BYTE_CONTENT] = id;
    radio_send_message();
    printf("ID 0x%02X sent\r\n", id);
}
Example #10
0
mqtt_message_t* mqtt_msg_subscribe_init(mqtt_connection_t* connection, uint16_t *message_id)
{
  init_message(connection);

  if((*message_id = append_message_id(connection, 0)) == 0)
    return fail_message(connection);

  return &connection->message;
}
Example #11
0
mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_pubcomp(mqtt_connection_t* connection,
		uint16_t message_id) {
	if (init_message(connection) == 0) {
		return fail_message(connection);
	}
	if (append_message_id(connection, message_id) == 0)
		return fail_message(connection);
	return fini_message(connection, MQTT_MSG_TYPE_PUBCOMP, 0, 0, 0);
}
Example #12
0
File: vram.c Project: pepone42/gngb
void init_vram(Uint32 flag)
{
  char *mousedrv=getenv("SDL_NOMOUSE");
  
  if (SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_VIDEO)<0) {
    printf("Couldn't initialize SDL: %s\n",SDL_GetError());
    exit(1);
  }
  atexit(SDL_Quit);   

  /* Define the video mode to use */
  if (conf.yuv && conf.yuv_type==0)
    cur_mode=&video_yv12;
  else if (conf.yuv && conf.yuv_type==1)
    cur_mode=&video_yuy2;
#ifdef SDL_GL
  else if (conf.gl)
    cur_mode=&video_gl;
#endif
  else
    cur_mode=&video_std;

  SDL_WM_SetCaption("Gngb",NULL); 
  if (mousedrv==NULL) 
    SDL_ShowCursor(0);

  init_message();

  conf.video_flag=flag;
  cur_mode->init(flag);

  back=SDL_CreateRGBSurface(SDL_SWSURFACE,SCREEN_X,SCREEN_Y+1,BIT_PER_PIXEL,
			    0xf800,0x7e0,0x1f,0x00);
  back_save=SDL_CreateRGBSurface(SDL_SWSURFACE,SCREEN_X,SCREEN_Y,BIT_PER_PIXEL,
				 0xf800,0x7e0,0x1f,0x00);

  if (back==NULL) {
    printf("Couldn't allocate %dx%dx%d SDL_Surface: %s\n",
	   SCREEN_X,SCREEN_Y,BIT_PER_PIXEL,SDL_GetError());
    exit(1);
  }
  

  init_pallete();
  /*
    if (conf.gb_type&COLOR_GAMEBOY) draw_screen=cur_mode->draw_col;
    else if (conf.gb_type&SUPER_GAMEBOY) draw_screen=cur_mode->draw_sgb;
    else draw_screen=cur_mode->draw_wb;
  */
  if (conf.gb_type&COLOR_GAMEBOY) draw_screen=draw_screen_col_std;
  else if (conf.gb_type&SUPER_GAMEBOY) draw_screen=draw_screen_sgb_std;
  else draw_screen=draw_screen_wb_std;
  
  //blit_screen=cur_mode->blit;

}
Example #13
0
File: variable.c Project: jheiss/nn
void
toggle_variable(char *variable)
{
    register struct variable_defs *var;

    if ((var = lookup_variable(variable)) == NULL)
	return;
    if (VAR_TYPE != V_BOOLEAN) {
	init_message("variable %s is not boolean", variable);
	return;
    }
    BOOL_VAR = !BOOL_VAR;
}
Example #14
0
mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_unsubscribe(mqtt_connection_t* connection, const char* topic, uint16_t* message_id)
{
  init_message(connection);

  if(topic == NULL || topic[0] == '\0')
    return fail_message(connection);

  if((*message_id = append_message_id(connection, 0)) == 0)
    return fail_message(connection);

  if(append_string(connection, topic, strlen(topic)) < 0)
    return fail_message(connection);

  return fini_message(connection, MQTT_MSG_TYPE_UNSUBSCRIBE, 0, 1, 0);
}
Example #15
0
/* to be called from within a protothread */
static void send_temperature()
{
    init_message();
    radio_tx_buffer[MSG_BYTE_TYPE] = MSG_TYPE_TEMPERATURE;
    int temperature = adc10_sample_temp();
    /*printf("temperature: %d, hex: ", temperature);
    printhex((char *) &temperature, 2);
    putchar('\r');
    putchar('\n');*/
    /* msp430 is little endian, convert temperature to network order */
    char *pt = (char *) &temperature;
    radio_tx_buffer[MSG_BYTE_CONTENT] = pt[1];
    radio_tx_buffer[MSG_BYTE_CONTENT + 1] = pt[0];
    printf("node_id,%d,temperature,%d.%d,rssi,%d,help,%d\r\n", node_id, temperature / 10, temperature % 10, 0, 0);
    //radio_send_message();
}
Example #16
0
void MessageQueue::on_cc(int bus, int ccindex, int ccvalue) {
    if (ccindex == ValueNone)
        return;
    if (ccvalue == ValueNone)
        return;
    assert(model);
    Message msg;
    init_message(bus,msg);
    msg.type = Message::TypeMIDI;
    msg.bus = bus;
    msg.command = MIDI::CommandControlChange;
    msg.channel = model->tracks[bus].midi_channel;
    msg.data1 = ccindex;
    msg.data2 = ccvalue;
    push(msg);
}
Example #17
0
int release_cs(const void * self) {
	if (done_count == 0) {
		inc_lamport_time();
		return 0;
	}
	Message msg;
	memset(&msg, 0, sizeof(msg));

	next_proc();
	inc_lamport_time();
	init_message(&msg, NULL, CS_RELEASE);

	for (local_id id_from = 1; id_from <= num_proc; id_from++) {
		send(NULL, id_from, &msg);
	}
	return 0;
}
Example #18
0
void MessageQueue::on_command(int bus, int channel, Message::Type command, int value, int value2, int value3) {
    if (value == ValueNone)
        return;
    if (value2 == ValueNone)
        value2 = 0;
    if (value3 == ValueNone)
        value3 = 0;
    assert(model);
    Message msg;
    init_message(bus,msg);
    msg.type = command;
    msg.bus = bus;
    msg.bus_channel = channel;
    msg.status = value;
    msg.data1 = value2;
    msg.data2 = value3;
    push(msg);
}
Example #19
0
mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_subscribe(mqtt_connection_t* connection, const char* topic, int qos, uint16_t* message_id)
{
  init_message(connection);

  if(topic == NULL || topic[0] == '\0')
    return fail_message(connection);

  if((*message_id = append_message_id(connection, 0)) == 0)
    return fail_message(connection);

  if(append_string(connection, topic, strlen(topic)) < 0)
    return fail_message(connection);

  if(connection->message.length + 1 > connection->buffer_length)
    return fail_message(connection);
  connection->buffer[connection->message.length++] = qos;

  return fini_message(connection, MQTT_MSG_TYPE_SUBSCRIBE, 0, 1, 0);
}
Example #20
0
static int init_heap(biterc_session_t *session)
{
   int result;
   int pagesize = getpagesize();

   result = take_heap_lock(session);
   if (result == -1)
      return -1;

   init_sheep(((unsigned char *) session->shm) + pagesize, session->shm_size - pagesize, 0);

   result = release_heap_lock(session);
   if (result == -1)
      return -1;


   result = init_message(session->shared_header->num_procs, &session->shared_header->msg_table_ptr, session);
   if (result == -1) {
      return -1;
   }

   return 0;
}
Example #21
0
File: variable.c Project: jheiss/nn
static struct variable_defs *
lookup_variable(char *variable)
{
    register struct variable_defs *var;
    register int    i, j, k, t;

    i = 0;
    j = TABLE_SIZE - 1;

    while (i <= j) {
	k = (i + j) / 2;
	var = &variables[k];

	if ((t = strcmp(variable, var->var_name)) > 0)
	    i = k + 1;
	else if (t < 0)
	    j = k - 1;
	else
	    return var;
    }

    init_message("unknown variable: %s", variable);
    return NULL;
}
Example #22
0
/* the main game function */
static int play_game()
{ 
   ALLEGRO_TIMER *inc_counter;
   int gameover = 0;
   int cyclenum = 0;

   /* init */
   score = 0;

   init_view();
   init_player();
   init_badguys();
   init_bullets();
   init_explode();
   init_message();

   #define TIMER_SPEED  ALLEGRO_BPS_TO_SECS(30*(cyclenum+2))

   inc_counter = al_create_timer(TIMER_SPEED);
   al_start_timer(inc_counter);

   while (!gameover) {

      /* move everyone */
      while ((al_get_timer_count(inc_counter) > 0) && (!gameover)) {
	 update_view();
	 update_bullets();
	 update_explode();
	 update_message();

	 if (update_badguys()) {
	    if (advance_view()) {
	       cyclenum++;
	       al_set_timer_count(inc_counter, 0);
	       lay_attack_wave(TRUE);
	       advance_player(TRUE);
	    }
	    else {
	       lay_attack_wave(FALSE);
	       advance_player(FALSE);
	    }
	 }

	 gameover = update_player();

	 al_set_timer_count(inc_counter, al_get_timer_count(inc_counter)-1);
      }

      /* take a screenshot? */
      if (key[ALLEGRO_KEY_PRINTSCREEN]) {
	 static int ss_count = 0;

	 char fname[80];

	 sprintf(fname, "speed%03d.tga", ++ss_count);

	 al_save_bitmap(fname, al_get_backbuffer(screen));

	 while (key[ALLEGRO_KEY_PRINTSCREEN])
	    poll_input_wait();

	 al_set_timer_count(inc_counter, 0);
      }

      /* toggle fullscreen window */
      if (key[ALLEGRO_KEY_F]) {
         int flags = al_get_display_flags(screen);
         al_set_display_flag(screen, ALLEGRO_FULLSCREEN_WINDOW,
            !(flags & ALLEGRO_FULLSCREEN_WINDOW));

         while (key[ALLEGRO_KEY_F])
            poll_input_wait();
      }

      /* draw everyone */
      draw_view();
   }

   /* cleanup */
   al_destroy_timer(inc_counter);

   shutdown_view();
   shutdown_player();
   shutdown_badguys();
   shutdown_bullets();
   shutdown_explode();
   shutdown_message();

   if (gameover < 0) {
      sfx_ping(1);
      return FALSE;
   }

   return TRUE;
}
Example #23
0
mqtt_message_t* mqtt_msg_disconnect(mqtt_connection_t* connection)
{
  init_message(connection);
  return fini_message(connection, MQTT_MSG_TYPE_DISCONNECT, 0, 0, 0);
}
Example #24
0
mqtt_message_t* mqtt_msg_pingresp(mqtt_connection_t* connection)
{
  init_message(connection);
  return fini_message(connection, MQTT_MSG_TYPE_PINGRESP, 0, 0, 0);
}
Example #25
0
void MessageQueue::status_msg() {
    Message msg;
    init_message(0,msg);
    msg.type = Message::TypeEmpty;
    push(msg);
}
Example #26
0
static void send_id_request()
{
    init_message();
    radio_tx_buffer[MSG_BYTE_TYPE] = MSG_TYPE_ID_REQUEST;
    radio_send_message();
}
Example #27
0
mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_info_t* info)
{
  struct mqtt_connect_variable_header* variable_header;

  init_message(connection);

  if(connection->message.length + sizeof(*variable_header) > connection->buffer_length)
    return fail_message(connection);
  variable_header = (void*)(connection->buffer + connection->message.length);
  connection->message.length += sizeof(*variable_header);

  variable_header->lengthMsb = 0;
  variable_header->lengthLsb = 4;
  c_memcpy(variable_header->magic, "MQTT", 4);
  variable_header->version = 4;
  variable_header->flags = 0;
  variable_header->keepaliveMsb = info->keepalive >> 8;
  variable_header->keepaliveLsb = info->keepalive & 0xff;

  if(info->clean_session)
    variable_header->flags |= MQTT_CONNECT_FLAG_CLEAN_SESSION;

  if(info->client_id != NULL && info->client_id[0] != '\0')
  {
    if(append_string(connection, info->client_id, c_strlen(info->client_id)) < 0)
      return fail_message(connection);
  }
  else
    return fail_message(connection);

  if(info->will_topic != NULL && info->will_topic[0] != '\0')
  {
    if(append_string(connection, info->will_topic, c_strlen(info->will_topic)) < 0)
      return fail_message(connection);

    if(append_string(connection, info->will_message, c_strlen(info->will_message)) < 0)
      return fail_message(connection);

    variable_header->flags |= MQTT_CONNECT_FLAG_WILL;
    if(info->will_retain)
      variable_header->flags |= MQTT_CONNECT_FLAG_WILL_RETAIN;
    variable_header->flags |= (info->will_qos & 3) << 3;
  }

  if(info->username != NULL && info->username[0] != '\0')
  {
    if(append_string(connection, info->username, c_strlen(info->username)) < 0)
      return fail_message(connection);

    variable_header->flags |= MQTT_CONNECT_FLAG_USERNAME;
  }

  if(info->password != NULL && info->password[0] != '\0')
  {
    if(append_string(connection, info->password, c_strlen(info->password)) < 0)
      return fail_message(connection);

    variable_header->flags |= MQTT_CONNECT_FLAG_PASSWORD;
  }

  return fini_message(connection, MQTT_MSG_TYPE_CONNECT, 0, 0, 0);
}
Example #28
0
mqtt_message_t* ICACHE_FLASH_ATTR mqtt_msg_pingreq(mqtt_connection_t* connection)
{
  init_message(connection);
  return fini_message(connection, MQTT_MSG_TYPE_PINGREQ, 0, 0, 0);
}
/** Program start */
int
main (int argc, char *argv[])
{
  /* MPI stuff */
  int rank = 0;
  int np = 0;
  char hostname[MPI_MAX_PROCESSOR_NAME+1];
  int namelen = 0;

  /* Output file */
  const char* outfile = "async.dat";
  FILE *fp = NULL; /* output file, only valid on rank 0 */

  /* Message buffer */
  int* msgbuf = NULL;
  const int msglen = (1 << 21); /* 2^21 words */

  double t_delay = 0; /* Current delay (seconds) */
  const double delay_step = 1e-4; /* Delay step */
  const double max_delay = 100*delay_step; /* Maximum delay */

  /* Start MPI */
#if defined(_OPENMP)
  int mpi_omp_support_level;
  MPI_Init_thread (&argc, &argv, MPI_THREAD_MULTIPLE, &mpi_omp_support_level);
#else
  MPI_Init (&argc, &argv);
#endif

  MPI_Comm_rank (MPI_COMM_WORLD, &rank);	/* Get process id */
  MPI_Comm_size (MPI_COMM_WORLD, &np);	/* Get number of processes */
  MPI_Get_processor_name (hostname, &namelen); /* Get hostname of node */
  fprintf (stderr, "[%s:rank %d of %d] Hello, world!\n", hostname, rank, np);

  /* This benchmark must be run between only two processes */
  assert (np == 2);

  if (rank == 0) {
    fprintf (stderr, "\n");
    fprintf (stderr, "Experimental parameters:\n");
    fprintf (stderr, "  Delay step: %g seconds\n", delay_step);
    fprintf (stderr, "  Maximum delay: %g seconds\n", max_delay);
#if defined (_OPENMP)
    fprintf (stderr, "  OpenMP enabled; support level: ");
    switch (mpi_omp_support_level) {
    case MPI_THREAD_SINGLE: fprintf (stderr, "MPI_THREAD_SINGLE"); break;
    case MPI_THREAD_FUNNELED: fprintf (stderr, "MPI_THREAD_FUNNELED"); break;
    case MPI_THREAD_SERIALIZED: fprintf (stderr, "MPI_THREAD_SERIALIZED"); break;
    case MPI_THREAD_MULTIPLE: fprintf (stderr, "MPI_THREAD_MULTIPLE"); break;
    default: fprintf (stderr, "(unknown)");
    }
    fprintf (stderr, "\n");
#else
    fprintf (stderr, "  OpenMP disabled.\n");
#endif
    fprintf (stderr, "  Output file: %s\n", outfile);
    fprintf (stderr, "\n");
  }

  /* Open a file for writing results */
  fprintf (stderr, "[%s:rank %d of %d] Opening output file, %s...\n",
	   hostname, rank, np, outfile);
  if (rank == 0) {
    fp = fopen (outfile, "w");
    assert (fp != NULL);
  }

  /* Create a message buffer */
  fprintf (stderr, "[%s:rank %d of %d] Creating message buffer of size %d ints (%d bytes)...\n",
	   hostname, rank, np, msglen, msglen * sizeof (int));
  msgbuf = (int *)malloc (msglen * sizeof (int));
  assert (msgbuf);

  /* Runs the asynchronous test-delay protocol */
  while (t_delay < max_delay) {
    double t_elapsed = -1;
    init_message (rank, msgbuf, msglen); /* reset the message */
    test_message (rank, msgbuf, msglen); /* redundant check */
    MPI_Barrier (MPI_COMM_WORLD);
   
    #pragma omp parallel
    #pragma omp single nowait
    t_elapsed = async_comm_test (t_delay, rank, msgbuf, msglen);

    /* Check that the msgbufs match initial values on rank 0 */
    test_message (0, msgbuf, msglen);

    /* Write out the timing result */
    if (rank == 0) {
      printf ("%g\t%g\n", t_delay, t_elapsed); fflush (stdout);
      fprintf (fp, "%g\t%g\n", t_delay, t_elapsed); fflush (fp);
    }

    t_delay += delay_step;
  } while (t_delay <= max_delay);

  fprintf (stderr, "[%s:rank %d of %d] Done! Cleaning up...\n", hostname, rank, np);
  free (msgbuf);

  if (rank == 0) {
    fclose (fp); /* Close output file */
  }
  fprintf (stderr, "[%s:rank %d of %d] Shutting down MPI...\n", hostname, rank, np);
  MPI_Finalize ();
  fprintf (stderr, "[%s:rank %d of %d] Bye bye.\n", hostname, rank, np);
  return 0;
}
Example #30
0
int main(int argc, char *argv[])
{
  //checks that enough arguments were given
  if(argc < 3)
  {
    fprintf(stderr, "Not enough arguments given \n");
    return -1;
  }
  
  init_message();

  //declare and grab all command line arguments
  char address[ADDRESS_LENGTH];
  int port;
  char file_name[BUFLEN];
  
  strcpy(address,argv[1]);
  port = atoi(argv[2]);
  strcpy(file_name, argv[3]);

  struct sockaddr_in si_other;
  int s, i, slen=sizeof(si_other);
  char buf[BUFLEN];
  int seq_num;  
  char snum[10];  

  if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
  {
      die("socket");
  }
 
  memset((char *) &si_other, 0, sizeof(si_other));
  si_other.sin_family = AF_INET;
  si_other.sin_port = htons(port);
     
  if (inet_aton(address , &si_other.sin_addr) == 0)
  {
      fprintf(stderr, "inet_aton() failed\n");
      exit(1);
  }

  memset(buf,0,sizeof(buf));      
  //send the file name to the server
  if (sendto(s, file_name, strlen(file_name) , 0 , (struct sockaddr *) &si_other, slen)==-1)
  {
    die("sendto()");
  }
         
  // Get the total number of packets from the server
  if (recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen) == -1)
  {
    die("recvfrom()");
  }

  total_number_packs = atoi(buf);
   
  for(i=0;i<total_number_packs;i++)
  {
    // Get the sequence number of the packet from the server
    if (recvfrom(s, snum, BUFLEN, 0, (struct sockaddr *) &si_other, &slen) == -1) 
    {
      printf("Packet Lost\n");
      die("recvfrom()");
    }
    else if(!strcmp(snum,"fin"))
    {
      break;
    }
    else
    {
      seq_num = atoi(snum);
      if(seq_num == -1){}
      printf("Receiving Packet: %d\n",seq_num);
    }
   
    // Get the data from the server
    if (recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen) == -1) 
    {
      printf("Packet Lost\n");
      die("recvfrom()");
    }
    else
    {
      printf("Receiving Data for Packet: %d\n",seq_num);
      strcpy(message[seq_num],buf);
    }
    //send the ack to the server
    if (sendto(s, "ack", strlen("ack") , 0 , (struct sockaddr *) &si_other, slen)==-1)
    {
      die("sendto()");
    }
  
    memset(buf,0,sizeof(buf));  //  Clear buf for the next data
    memset(snum,0,sizeof(snum));  //  Clear snum for the next seq number
  }  
    
  check_message(total_number_packs);
  close(s);

  FILE *output;
  output = fopen("recv_file","w");
  for(i=0;i<total_number_packs;i++)
  {
    
    fputs(message[i],output);
  }
  fclose(output);
  return 0;
}