예제 #1
0
static int process_input()
/*
 * purpose: runs the main loop of the shell program and in each loop iteration
	    takes input from user and execute it by calling command module
*   Return : 0 as this funtion does not prpagate errors out of it. Gets the
*		the status of last command ran and reports error if any.
*   This funtion gets the input, create arguments, run command and finally
*	free memory allocated for arguments.Hence this function guarantees that 
	it will release memory it has acquired.   
*/
{
	char tempstr[1024];
	char **argv;//command arguments
	const char* prompt = getPrompt();//shell program prompt
	int argc;//number of command arguments
	while(1)
	{
		//get next command and create aruments
		if ( (argv = next_cmd(prompt,&argc)) != NULL )
		{
			//run command
			if(run_command(argc,argv) != 0)
			{
				sprintf(tempstr,"%s\r\n",my_strerr(my_errno));uprintf(tempstr);
			}
			//destroy arguments
			arguments_destroy(argc,argv);
		}
	}
	return 0;
}
예제 #2
0
void dispatch_data_task::dispatch_data(void)
{
  this->poll_before_.update();

  this->dispatch_queue_mtx_.acquire();

  int result = 0;
  size_t stopped_count = 0;
  for (dispatch_queue_itor itor = this->dispatch_queue_.begin(); 
       itor != this->dispatch_queue_.end(); )
  {
    dispatch_job *job = *itor;
    if (job->close_pending_)
      // keep checking closed or not.
    {
      if ((*itor)->transfer_agent_->close() == 0)
      {
        delete (*itor)->transfer_agent_;
        delete job;
        itor = this->dispatch_queue_.erase(itor);
        continue;
      }
      dispatch_log->trace("release an unpointed job %p", job); 
      goto LOOP_TAIL;
    }
    if (job->stopped_)
    {
      ++stopped_count;
      dispatch_log->trace("session %d stopped!", job->session_id_);
      goto LOOP_TAIL;
    }else if (this->out_of_bandwidth(job, this->poll_before_))
    {
      //dispatch_log->trace("[%d] out of bandwidth!", job->session_id_);
      goto LOOP_TAIL;
    }

    job->bytes_to_send_per_timep_ += (job->bandwidth_*1024/(1000/TIME_PIECE))/8;

    for (; job->bytes_to_send_per_timep_ > 0; )
    {
      int transfer_bytes = 0;
      result = job->transfer_agent_->transfer_data(job->client_->get_handle(),
                                                   job->bytes_to_send_per_timep_,
                                                   transfer_bytes);
      // 
      job->bytes_to_send_per_timep_ -= transfer_bytes;
      job->transfer_bytes_ += transfer_bytes;

      if (result < 0 && result != -1)
        job->client_->session_desc(my_strerr(-result));

      if (job->transfer_bytes_ == job->content_length_)
      {
        result = -1;
        dispatch_log->rinfo("[%d] transfer data end! total %lld bytes",
                            job->session_id_,
                            job->transfer_bytes_);
      }
      if (result < 0)
      {
        job->stopped_ = 1;
        this->delete_job_i(job);
        goto LOOP_TAIL;
      }else if (result == 0)
      {
        dispatch_log->trace("%d blocked ....", job->session_id_);
        // blocked.
        break;
      }
    }
LOOP_TAIL:
    ++itor;
  } // end `for (; itor != this->dispatch_queue_.end(); ...'
  if (this->dispatch_queue_.empty()
      || 
      stopped_count == this->dispatch_queue_.size())
    this->task_idle_ = 1;
  else
    this->task_idle_ = 0;

  this->dispatch_queue_mtx_.release();

  this->poll_after_.update();
  this->diff_time_ = this->poll_after_ - poll_before_;
  int msec = TIME_PIECE - this->diff_time_.msec();
  if (msec > 5)
    ndk::sleep(ndk::time_value(0, (msec-3)*1000));
  return ;
}
예제 #3
0
int main()
{
	unsigned int size;;
	init_memory(ONE_MEGA_BYTE);
	size = 4231;
	fprintf(stdout,"\nTest Case# 1: Interleaved memory allocacations/deallocations and print memory map");
	fprintf(stdout,"\n----------------------------------------------------------------------------------\n\n");
	void* ptr1 = myMalloc(size);
	fprintf(stdout,"Allocated memory of size %d at %p\n",size,ptr1);
	size = 10487;
	void* ptr2 = myMalloc(size);
	fprintf(stdout,"Allocated memory of size %d at %p\n",size,ptr2);
	size = 75934;
	void* ptr3 = myMalloc(size);
	fprintf(stdout,"Allocated memory of size %d at %p\n",size,ptr3);
	size = 532432;
	void* ptr4 = myMalloc(size);
	fprintf(stdout,"Allocated memory of size %d at %p\n",size,ptr4);
	size = 343253;
	void* ptr5 = myMalloc(size);
	fprintf(stdout,"Allocated memory of size %d at %p\n",size,ptr5);	
	myFree(ptr2);
	fprintf(stdout,"Deallocated memory %p\n",ptr2);
	myFree(ptr4);
	fprintf(stdout,"Deallocated memory %p\n",ptr4);
	size = 65762;
	void* ptr6 = myMalloc(size);
	fprintf(stdout,"Allocated memory of size %d at %p\n",size,ptr6);
	size = 43234;
	void* ptr7 = myMalloc(size);
	fprintf(stdout,"Allocated memory of size %d at %p\n",size,ptr7);
	myFree(ptr6);
	fprintf(stdout,"Deallocated memory %p\n",ptr6);
	size = 8364;
	void* ptr8 = myMalloc(size);
	fprintf(stdout,"Allocated memory of size %d at %p\n",size,ptr8);
	fprintf(stdout,"\nPrinting memory map after test case# 1\n\n");
	memoryMap();	
	fprintf(stdout,"\nTest Case# 2: Allocating memory with size in hexadecimal (0xFFFF)");
	fprintf(stdout,"\n------------------------------------------------------------------\n\n");
	size = 0xFFFF;
	void* ptr9 = myMalloc(size);
	fprintf(stdout,"Allocated memory of size %d at %p\n",size,ptr9);
	fprintf(stdout,"\nPrinting memory map after test case# 2\n\n");
	memoryMap();
	fprintf(stdout,"\nTest Case# 3: Freeing not a previously allocated memory(0xFFFFFFFF)");
	fprintf(stdout,"\n--------------------------------------------------------\n\n");
	myFree((void*)0xFFFFFFFF);
	fprintf(stderr,"%s\n",my_strerr(my_errno));
	fprintf(stdout,"\nTest Case# 4: Freeing a null pointer");
	fprintf(stdout,"\n-------------------------------------------\n\n");
	myFree(0);
	fprintf(stderr,"%s\n",my_strerr(my_errno));	
	fprintf(stdout,"\nTest Case# 5: Allocating zero sized memory");
	fprintf(stdout,"\n-------------------------------------------\n\n");
	void* ptr10 = myMalloc(0);
	fprintf(stderr,"%p\n",ptr10);	
	fprintf(stdout,"\nTest Case# 6: Allocating memory of a very big size(%d bytes)",ONE_MEGA_BYTE);
	fprintf(stdout,"\n-------------------------------------------\n\n");
	myMalloc(ONE_MEGA_BYTE);	
	fprintf(stderr,"%s\n",my_strerr(my_errno));		
	fprintf(stdout,"\nPrinting memory map after all test cases\n\n");
	memoryMap();
	return 0;
}