Code Search for Developers
 
 
  

tcpxfer_status.c from EmStar at Krugle


Show tcpxfer_status.c syntax highlighted



char tcpxfer_status_c_cvsid[] = "$Id: tcpxfer_status.c,v 1.6 2007/01/08 01:06:26 mlukac Exp $";


#include "tcpxfer_i.h"

int tcpxfer_status_bin(status_context_t *ctx, buf_t *buf)
{
  tcpxfer_t *txt = (tcpxfer_t *) sd_data(ctx);
  int i = 0;
  for (i = 0; i < TCPXFER_MAX_XFERS; ++i) {
    if (txt->allxfers[i] != NULL) {
      tcpxfer_data_t *tdt = txt->allxfers[i];
      tcpxfer_bin_status_t tbst = {
	currbyte: tdt->currbyte,
	totalsize: tdt->totalsize,
	status: tdt->status,
	retries: tdt->retries,
	starttime: msec_since(&(tdt->starttime)),
	retrysince: msec_since(&(tdt->retrysince)),
	totaltime: tdt->totaltime,
      };
      strcpy(tbst.justfile, tdt->justfile);
      strcpy(tbst.addr, tdt->addr);
      bufcpy(buf, &tbst, sizeof(tcpxfer_bin_status_t));

      /*
	if (txt->allxfers[i]->status == XFERFILE_SEND_DONE &&
	txt->allxfers[i]->returnedstats == 0) {
	tcpxfer_status_file_done_t tsfd = {};
	strcpy(tsfd.file, txt->allxfers[i]->file);
	memcpy(&(tsfd.stats), &(txt->allxfers[i]->stats), sizeof(tcpxfer_done_stats_packet_t));
	txt->allxfers[i]->returnedstats = 1;
	}
      */
    }
  }
  return STATUS_MSG_COMPLETE;
}


int tcpxfer_status_print(status_context_t *ctx, buf_t *buf)
{
  tcpxfer_t *txt = (tcpxfer_t *) sd_data(ctx);

  bufprintf(buf, "\n");
  bufprintf(buf, "-- Outputdir:\t%s\t ClientTimeout %i, ServerTimeout %i\n", txt->outdir,
	    txt->client_timeout, txt->server_timeout);
  bufprintf(buf, "\n");
  
  bufprintf(buf, "\t\t\t\t ---- Sending ----\n");
  int i = 0;
  for (i = 0; i < TCPXFER_MAX_XFERS; ++i) {
    if (txt->allxfers[i] != NULL) {
      tcpxfer_data_t *tdt = txt->allxfers[i];
      if (tdt->status >= 1 && tdt->status <= 5) {
	bufprintf(buf, "%s to %s -- C: %2i E:%2i ", tdt->file, tdt->addr, tdt->send_channel, tdt->return_code);
	tcpxfer_data_print_state(tdt, buf);
	bufprintf(buf, "\n");
	bufprintf(buf, "\t%.2f %% - %lld of %lld bytes xfered in %ld secs retry %i "
		  "-- %ld -- %i\n", 
		  tdt->totalsize == 0 ? 100 :
		  ((tdt->currbyte + 0.0) / (tdt->totalsize + 0.0))*100.0,
		  tdt->currbyte,
		  tdt->totalsize, 
		  msec_since(&tdt->retrysince) / 1000,
		  tdt->retries,
		  msec_since(&tdt->starttime) / 1000,
		  g_timer_time_remaining(tdt->transfer_timeout));

      }
    }
  }
  bufprintf(buf, "\n\t\t\t\t ---- Receiving ----\n");
  for (i = 0; i < TCPXFER_MAX_XFERS; ++i) {
    if (txt->allxfers[i] != NULL) {
      tcpxfer_data_t *tdt = txt->allxfers[i];
      if (tdt->status >= 6 && tdt->status <= 10) {
	bufprintf(buf, "%s from %s -- ", tdt->file, tdt->addr);
	tcpxfer_data_print_state(tdt, buf);
	bufprintf(buf, "\n");
	bufprintf(buf, "\t%.2f %% - %lld of %lld bytes xfered in %ld secs retry %i "
		  "-- %ld -- %i\n", 
		  tdt->totalsize == 0 ? 100 :
		  ((tdt->currbyte + 0.0) / (tdt->totalsize + 0.0))*100.0,
		  tdt->currbyte,
		  tdt->totalsize, 
		  msec_since(&tdt->retrysince) / 1000,
		  tdt->retries,
		  msec_since(&tdt->starttime) / 1000,
		  g_timer_time_remaining(tdt->transfer_timeout));

      }
    }
  }
  return STATUS_MSG_COMPLETE;
}


int tcpxfer_status_command(status_context_t *ctx, char *command, size_t buf_size)
{
  tcpxfer_t *txt = (tcpxfer_t *) sd_data(ctx);

  char file[4096];
  char addr[18];
  
  if (buf_size > 4096) {
    elog(LOG_WARNING, "Invalud command... to big");
    goto out;
  }

  memset(file, 0, 4096);
  memset(addr, 0, 18);

  parser_state_t *cmd_parse = misc_parse_init(command,MISC_PARSE_COLON_SCHEME);
  while (misc_parse_next_kvp(cmd_parse) >= 0) {
    if (strcmp(cmd_parse->key, "file") == 0) {
      if (cmd_parse->value != NULL && strlen(cmd_parse->value) < 4095) {
        strcpy(file,cmd_parse->value);
      } else {
        elog(LOG_ERR, "Bad file= command... invalid value");
        goto done;
      }
    } else if (strcmp(cmd_parse->key, "ip") == 0) {
      if (cmd_parse->value != NULL && strlen(cmd_parse->value) < 17) {
        strcpy(addr,cmd_parse->value);
      } else {
        elog(LOG_ERR, "Bad ip= command... invalid value");
        goto done;
      }
    }
    else {
      elog(LOG_ERR, "Unrecognized command: %s\n", cmd_parse->key);
      goto done;
    }
  }

  if (strlen(file) == 0 || strlen(addr) == 0) {
    elog(LOG_ERR, "Missing file or ip address in command");
    goto done;
  }

  /*
   * Check if xfer already happening, check file, start timer
   */
  if (tcpxfer_client_pre_init(txt, file, addr))
    tcpxfer_client_send_init(txt, file, addr, TCPXFER_SEND_CHANNEL_STATUSDEV);

 done:
  misc_parse_cleanup(cmd_parse);
 out:
  return STATUS_WRITE_DONE;

}






See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  TODO
  md5.c
  md5.h
  tcpxfer_client.c
  tcpxfer_data.c
  tcpxfer_file.c
  tcpxfer_i.h
  tcpxfer_main.c
  tcpxfer_md5.c
  tcpxfer_packet.c
  tcpxfer_query.c
  tcpxfer_send.c
  tcpxfer_server.c
  tcpxfer_status.c