int
Simple_Tester::initiate_read_file (void)
{
  // Create Message_Block
  ACE_Message_Block *mb = 0;
  ACE_NEW_RETURN (mb, ACE_Message_Block (BUFSIZ + 1), -1);

  // Inititiate an asynchronous read from the file
  if (this->rf_.read (*mb,
		      mb->size () - 1) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Asynch_Read_File::read"), -1);

  ACE_DEBUG ((LM_DEBUG,
              "Simple_Tester:initiate_read_file: Asynch Read File issued sucessfully\n"));

  return 0;
}
Beispiel #2
0
int
Receiver::initiate_read_stream (void)
{
  // Create a new <Message_Block>.  Note that this message block will
  // be used both to <read> data asynchronously from the socket and to
  // <write> data asynchronously to the file.
  ACE_Message_Block *mb = 0;
  ACE_NEW_RETURN (mb,
                  ACE_Message_Block (BUFSIZ + 1),
                  -1);

  // Inititiate read
  if (this->rs_.read (*mb,
                      mb->size () - 1) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "ACE_Asynch_Read_Stream::read"),
                      -1);
  return 0;
}
int AC_Output_Handler::svc () {
  ACE_Message_Block *chunk[ACE_IOV_MAX];
  size_t message_index = 0;
  ACE_Time_Value time_of_last_send (ACE_OS::gettimeofday ());
  ACE_Time_Value timeout;
  ACE_Sig_Action no_sigpipe ((ACE_SignalHandler) SIG_IGN);
  ACE_Sig_Action original_action;
  no_sigpipe.register_action (SIGPIPE, &original_action);

  for (;;) {
    if (message_index == 0) {
      timeout = ACE_OS::gettimeofday ();
      timeout += FLUSH_TIMEOUT;
    }
    ACE_Message_Block *mblk = 0;
    if (getq (mblk, &timeout) == -1) {
      if (errno == ESHUTDOWN) {
        if (connector_->reconnect () == -1) break;
        continue;
      } else if (errno != EWOULDBLOCK) break;
      else if (message_index == 0) continue;
    } else {
      if (mblk->size () == 0
          && mblk->msg_type () == ACE_Message_Block::MB_STOP)
        { mblk->release (); break; }
      chunk[message_index] = mblk;
      ++message_index;
    }
    if (message_index >= ACE_IOV_MAX ||
        (ACE_OS::gettimeofday () - time_of_last_send
         >= ACE_Time_Value(FLUSH_TIMEOUT))) {
      if (this->send (chunk, message_index) == -1) break;
      time_of_last_send = ACE_OS::gettimeofday ();
    }
  }

  if (message_index > 0)
    this->send (chunk, message_index);
  no_sigpipe.restore_action (SIGPIPE, original_action);
  return 0;
}
Beispiel #4
0
int
Sender::initiate_read_file (void)
{
  // Create a new <Message_Block>.  Note that this message block will
  // be used both to <read> data asynchronously from the file and to
  // <write> data asynchronously to the socket.
  ACE_Message_Block *mb = 0;
  ACE_NEW_RETURN (mb,
                  ACE_Message_Block (BUFSIZ + 1),
                  -1);

  // Inititiate an asynchronous read from the file
  if (this->rf_.read (*mb,
                      mb->size () - 1,
                      this->file_offset_) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "ACE_Asynch_Read_File::read"),
                      -1);
  return 0;
}
Beispiel #5
0
int
STDIN_Handler::svc (void)
{
  this->register_thread_exit_hook ();

  for (;;)
    {
      ACE_Message_Block *mb = new ACE_Message_Block (BUFSIZ);

      // Read from stdin into mb.
      int read_result = ACE_OS::read (ACE_STDIN,
                                      mb->rd_ptr (),
                                      mb->size ());

      // If read succeeds, put mb to peer handler, else end the loop.
      if (read_result > 0)
        {
          mb->wr_ptr (read_result);
          // Note that this call will first enqueue mb onto the peer
          // handler's message queue, which will then turn around and
          // notify the Reactor via the Notification_Strategy.  This
          // will subsequently signal the Peer_Handler, which will
          // react by calling back to its handle_output() method,
          // which dequeues the message and sends it to the peer
          // across the network.
          this->ph_.putq (mb);
        }
      else
        {
          mb->release ();
          break;
        }
    }

  // handle_signal will get called on the main proactor thread since
  // we just exited and the main thread is waiting on our thread exit.
  return 0;
}
Beispiel #6
0
static void *
producer (ACE_Message_Queue<ACE_MT_SYNCH> *msg_queue)
{
  // Keep reading stdin, until we reach EOF.

  for (int n; ; )
    {
      // Allocate a new message.
      ACE_Message_Block *mb = 0;

      ACE_NEW_RETURN (mb, ACE_Message_Block (BUFSIZ), 0);

      n = ACE_OS::read (ACE_STDIN, mb->wr_ptr (), mb->size ());

      if (n <= 0)
        {
          // Send a shutdown message to the other thread and exit.
          mb->length (0);
          if (msg_queue->enqueue_tail (mb) == -1)
            ACE_ERROR ((LM_ERROR,
                        "(%t) %p\n",
                        "put_next"));
          break;
        }
      // Send the message to the other thread.
      else
        {
          mb->msg_priority (n);
          mb->wr_ptr (n);
          if (msg_queue->enqueue_tail (mb) == -1)
            ACE_ERROR ((LM_ERROR,
                        "(%t) %p\n",
                        "put_next"));
        }
    }

  return 0;
}
Beispiel #7
0
int 
Receiver::initiate_read_stream (void)
{
  ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_);        

  ACE_Message_Block *mb = 0;
  ACE_NEW_RETURN (mb,
                  ACE_Message_Block (BUFSIZ + 1),
                  -1);

  // Inititiate read
  if (this->rs_.read (*mb, mb->size ()- 1) == -1)
    {
      mb->release ();
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "ACE_Asynch_Read_Stream::read"),
                        -1);
    }

  io_count_++;
  return 0;
}
Beispiel #8
0
int KSG_Reactor_Handler::handle_input(ACE_HANDLE handle)
{
	ACE_Message_Block *mb;
	if(!_message)
	{
		ACE_NEW_RETURN(mb,ACE_Message_Block(BUFSIZ+1),-1);
	}
	int ret;
	ssize_t bytes_read = 0;
	do
	{
		ret = 0;
		bytes_read = this->peer().recv(mb->wr_ptr(),mb->size() - mb->length());
		if(bytes_read == -1)
		{
			if(errno == EWOULDBLOCK)
			{
				break;
			}
			else
			{
				mb->release();
				mb = NULL;
				ACE_ERROR((LM_ERROR,"½ÓÊÕÊý¾Ýʧ°Ü£¡£¡"));
				ret = -1;
				break;
			}
		}
		else if(bytes_read == 0)
		{
			break;
		}
	} while(1);
	
	_message = mb;
	return ret;
}
Beispiel #9
0
template <class ROUTER, class KEY> int
Peer_Handler<ROUTER, KEY>::handle_input (ACE_HANDLE h)
{

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) input arrived on sd %d\n"), h));
//  ACE_Reactor::instance ()->remove_handler(h,
//                                          ACE_Event_Handler::ALL_EVENTS_MASK
//                                          |ACE_Event_Handler::DONT_CALL);
// this method should be called only if the peer shuts down
// so we deactivate our ACE_Message_Queue to awake our svc thread

  return 0;

#if 0
  ACE_Message_Block *db = new ACE_Message_Block (BUFSIZ);
  ACE_Message_Block *hb = new ACE_Message_Block (sizeof (KEY), ACE_Message_Block::MB_PROTO, db);
  int           n;

  if ((n = this->peer ().recv (db->rd_ptr (), db->size ())) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("recv failed")), -1);
  else if (n == 0) // Client has closed down the connection.
    {
      if (this->router_task_->unbind_peer (this->get_handle ()) == -1)
        ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
                           ACE_TEXT ("unbind failed")), -1);
      ACE_DEBUG ((LM_DEBUG, "(%t) shutting down %d\n", h));
      return -1; // Instruct the ACE_Reactor to deregister us by returning -1.
    }
  else // Transform incoming buffer into a Message and pass downstream.
    {
      db->wr_ptr (n);
      *(long *) hb->rd_ptr () = this->get_handle (); // structure assignment.
      hb->wr_ptr (sizeof (long));
      return this->router_task_->reply (hb) == -1 ? -1 : 0;
    }
#endif
}
Beispiel #10
0
static void *
consumer (void *)
{
  ACE_UPIPE_Stream c_stream;

  // Set the high water mark to size to achieve optimum performance.

  int wm = size * iterations;

  if (c_stream.control (ACE_IO_Cntl_Msg::SET_HWM,
                        &wm) == -1)
    ACE_DEBUG ((LM_DEBUG,
                "set HWM failed\n"));

  ACE_UPIPE_Addr serv_addr (ACE_TEXT("pattern"));

  // accept will wait up to 4 seconds
  ACE_UPIPE_Acceptor acc (serv_addr);

  ACE_DEBUG ((LM_DEBUG,
              "(%t) consumer spawning the supplier thread\n"));

  // Spawn the supplier thread.
  if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (supplier),
                                              (void *) 0,
                                              THR_NEW_LWP | THR_DETACHED) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "spawn"),
                      0);

  ACE_DEBUG ((LM_DEBUG,
              "(%t) consumer starting accept\n"));

  if (acc.accept (c_stream) == -1)
    ACE_ERROR ((LM_ERROR,
                "(%t) %p\n",
                "ACE_UPIPE_Acceptor.accept failed"));

  // Time measurement.
  time_t currsec;
  ACE_OS::time (&currsec);
  time_t start = (time_t) currsec;

  int received_messages = 0;

  for (ACE_Message_Block *mb = 0;
       c_stream.recv (mb) != -1 && mb->size () != 0;
       mb->release ())
    received_messages++;

  ACE_OS::time (&currsec);
  time_t secs = (time_t) currsec - start;

  ACE_DEBUG ((LM_DEBUG,
              "(%t) Transferred %d blocks of size %d\n"
              "The program ran %d seconds\n",
              received_messages, size, secs));
  c_stream.close ();
  return 0;
}
int SerialportTask::svc (void)
{
    ACE_DEBUG((LM_DEBUG,
                "Create zigbee serialport Service thread\n"));

    ACE_Time_Value last_time = ACE_OS::gettimeofday();
    ACE_Time_Value current_time = ACE_OS::gettimeofday();

    while( !thread_exit_flag)
    {
        ACE_Message_Block *b = 0;

        if (message_queue.dequeue_head(b) == -1 )
        {
            ACE_DEBUG((LM_DEBUG, "faile get block from queue\n"));
            continue;
        }

        //ACE_DEBUG((LM_DEBUG, "*** get type[%x] size[%d] ****\n", b->msg_type(),
        //message_queue.message_count()));

        switch(b->msg_type())
        {
            case ZIGBEE_SERIAL_PORT_CMD_EXIT_THREAD:
            {
                thread_exit_flag = 1;
            }
            break;

            case ZIGBEE_SERIAL_PORT_CMD_CONNECT_PORT:
            {
               owner_->connecting_serial_port();
            }
            break;

            case ZIGBEE_SERIAL_PORT_CMD_SEND_REQ:
            {
               current_time = ACE_OS::gettimeofday();

               // each command cant send togather. when the time expired
               // send it
               if ( current_time.msec() > last_time.msec() + 1500 )
               {
                    owner_->send_req((unsigned char*)b->base(), b->size());

                    last_time = ACE_OS::gettimeofday();
               }
               else
               {
                    // re-enter queue to wait time expired
                    message_queue.enqueue_tail(b);
                    b = 0;
               }

            }
            break;

            case ZIGBEE_SERIAL_PORT_CMD_GET_RES:
            {
                owner_->get_response();
            }
            break;

            default:
                break;

        }

        if (b)
        {
            b->release();
        }
    }

    ACE_DEBUG((LM_DEBUG,
                "Return from zigbee serialport Service thread\n"));

    return 0;

}
int
device_averager::handle_timeout( const ACE_Time_Value& tv, const void * )
{
    if ( state() <= device_state::state_initializing )
        doit( device_state::command_stop );

    if ( uptime_.sec() == 0 && uptime_.usec() == 0 )
        uptime_ = tv;
    
    size_t hLen = 32;
    size_t nbrSamples = 1024 * 15;
    size_t nbrAverage = 1;
    size_t sampInterval = 500;
    size_t nDelay = 12 * 1000000 / 500;
    unsigned long wellKnownEvents = 0;

	static size_t npos;

	const std::vector< TXTSpectrum > spectra = device_emulator::singleton::device_facade::instance()->test_spectra();
    const TXTSpectrum * psp = 0;
	if ( ! spectra.empty() ) {
		const TXTSpectrum& sp = spectra[0];
		nbrSamples = sp.iarray_.size();
        sampInterval = sp.sampInterval_;
        nDelay = sp.startDelay_;
		psp = &sp;
	}
	size_t wformLen = (nbrSamples * 3 / 4) + 1; // 32bit -> 24bit 

	ACE_Message_Block * mb = new ACE_Message_Block( adportable::protocol::LifeCycle::wr_offset() + ((hLen + wformLen) * sizeof(long)));
	size_t size = mb->size();
	memset( mb->wr_ptr(), 0, size );
	mb->wr_ptr( adportable::protocol::LifeCycle::wr_offset() );

	long * pmeta = reinterpret_cast<long *>(mb->wr_ptr());
	// long * pdata = pmeta + hLen;
    unsigned char * pchar = reinterpret_cast<unsigned char *>( pmeta + hLen );
	mb->wr_ptr( mb->size() );

    ACE_Time_Value tm = tv - uptime_;
    unsigned long long uptime = tm.sec() * 1000000 + tm.usec();

	*pmeta++ = TOFConstants::ClassID_ProfileData;
	*pmeta++ = npos++;
	*pmeta++ = unsigned long ( uptime & 0xffffffff ); // time since inject, to do
	*pmeta++ = unsigned long ( uptime & 0xffffffff );
	*pmeta++ = unsigned long ( uptime >> 32 );
	*pmeta++ = nbrSamples;
    *pmeta++ = nbrAverage;
	*pmeta++ = nDelay;
	*pmeta++ = sampInterval;
    *pmeta++ = wellKnownEvents;

	// simulate noise
	srand( int(tv.sec()) );

	if ( psp ) {
		double f = 1000.0 / psp->maxValue_;
		for ( size_t i = 0; i < nbrSamples; ++i ) {
            double d = psp->iarray_[i] + (psp->maxValue_ / 20.0);
			if ( d < (-psp->maxValue_ / 20) )
				d = (-psp->maxValue_ / 20);
			long x = ( d * f ) + ( double(rand()) * 10 / RAND_MAX );
			*pchar++ = x >> 16;
			*pchar++ = x >> 8;
            *pchar++ = x;
		}
	}
	// todo: overlay chemical background, and sample peak
	mb->msg_type( constants::MB_DATA_TO_CONTROLLER );
	singleton::device_facade::instance()->putq( mb );

	return 0;
}
Beispiel #13
0
int HDCCUSvrHandler::svc()
{
#define MES_DATA_HEAD_LEN 2

    ACE_DEBUG((LM_DEBUG,"ACE 打开连接............"));
    ACE_Message_Block * mb = NULL;

    ACE_Time_Value tv(5);
    if (this->getq(mb,&tv) == -1) return -1;
    HD8583STRUCT req;
    HD8583STRUCT resp;
    MESSAGETYPE msg_type;
    char * buffer = mb->rd_ptr();
    int len = 0;
    // 数据段长度超过允许范围,忽略请求
    if(UnPackResponseStruct(req,&msg_type,buffer,mb->length()) != 0)
    {
        ACE_ERROR((LM_ERROR,"数据包不合法"));
        mb->release();
        return -1;
    }

    ACE_HEX_DUMP((LM_DEBUG,mb->rd_ptr(),mb->length()));
    try
    {
        HDResponseHandler* handler = HDCCUProcessUnits::Instance().Create(msg_type);
        if(handler)
        {
            resp.Init();

            int result = handler->DoResponse(req,resp,peer().get_handle());
            if(result > 0)
            {
                // send back
                mb->reset();
                buffer = mb->wr_ptr();
                len = (int)PackRequestStruct(resp,msg_type,buffer,mb->size());
                mb->wr_ptr(len);
                ACE_HEX_DUMP((LM_DEBUG,buffer,mb->length()));
                ACE_DEBUG((LM_DEBUG,"数据包长度[%d]",mb->length()));
                if(peer().send_n(mb->rd_ptr(),mb->length()) <=0 )
                {
                    ACE_DEBUG((LM_ERROR,"发送应答包失败"));
                }

            }
            else if(result == 0)
            {
                // OK
                ACE_DEBUG((LM_DEBUG,"处理成功"));
            }
            else
            {
                // error
                ACE_DEBUG((LM_ERROR,"处理请求失败,返回码[%d]",result));
            }
        }
        else
        {
            ACE_ERROR((LM_ERROR,"不能处理请求代码[%c]",msg_type));
        }
    }
    catch(...)
    {
        // 捕获所有的异常
        ACE_ERROR((LM_ERROR,"处理请求异常,请求代码[%02x]",msg_type));
    }
    mb->release();
    return 0;
}
Beispiel #14
0
int
JAWS_Parse_Headers::parse_headers (JAWS_Header_Info *info,
                                   ACE_Message_Block &mb)
{
  for (;;)
    {
      if (mb.rd_ptr () == mb.wr_ptr ())
          break;

      char *p = mb.rd_ptr ();

      if (info->end_of_line ()
          && (*p != ' ' && *p != '\t'))
        {
          int r = this->parse_header_name (info, mb);
          if (r == 1)
            return info->end_of_headers ();
          continue;
        }
      else
        {
          int r = this->parse_header_value (info, mb);
          if (r == 1)
            {
              if (info->end_of_headers ())
                return 1;
              break;
            }
          continue;
        }
    }

  // If we arrive here, it means either there is nothing more to read,
  // or parse_header_value ran into difficulties (like maybe the
  // header value was too long).

  if (mb.rd_ptr () != mb.base ())
    {
      mb.crunch ();
      return 0;
    }
  else if (mb.length () < mb.size ())
    {
      return 0;
    }
  else if (mb.length () == mb.size ())
    {
      // This is one of those cases that should rarely ever happen.
      // If we get here, the header type name is over 8K long.  We
      // flag this as a bad thing.

      // In HTTP/1.1, I have to remember that a bad request means the
      // connection needs to be closed and the client has to
      // reinitiate the connection.

      info->status (JAWS_Header_Info::STATUS_CODE_TOO_LONG);
      return 1;
    }
  else if (mb.length () > mb.size ())
    {
      ACE_DEBUG ((LM_DEBUG, "JAWS_Parse_Headers: buffer overrun!!\n"));
      info->status (JAWS_Header_Info::STATUS_CODE_TOO_LONG);
      return 1;
    }

  ACE_DEBUG ((LM_DEBUG, "JAWS_Parse_Headers -- shouldn't be here!\n"));
  return 1;
}
Beispiel #15
0
int
Peer_Handler::handle_input (ACE_HANDLE h)
{
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) input arrived on handle %d\n"),
              h));

  ACE_Message_Block *db;

  ACE_NEW_RETURN (db, ACE_Message_Block (BUFSIZ), -1);

  ACE_Message_Block *hb = new ACE_Message_Block (sizeof (ROUTING_KEY),
                                                 ACE_Message_Block::MB_PROTO, db);
  // Check for memory failures.
  if (hb == 0)
    {
      db->release ();
      errno = ENOMEM;
      return -1;
    }

  ssize_t n = this->peer ().recv (db->rd_ptr (),
                                  db->size ());

  if (n == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p"),
                       ACE_TEXT ("recv failed")),
                      -1);
  else if (n == 0) // Client has closed down the connection.
    {
      if (this->peer_router_context_->unbind_peer (this->get_handle ()) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("%p"),
                           ACE_TEXT ("unbind failed")),
                          -1);

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) shutting down handle %d\n"), h));
      // Instruct the <ACE_Reactor> to deregister us by returning -1.
      return -1;
    }
  else
    {
      // Transform incoming buffer into an <ACE_Message_Block>.

      // First, increment the write pointer to the end of the newly
      // read data block.
      db->wr_ptr (n);

      // Second, copy the "address" into the header block.  Note that
      // for this implementation the HANDLE we receive the message on
      // is considered the "address."  A "real" application would want
      // to do something more sophisticated.
      *(ACE_HANDLE *) hb->rd_ptr () = this->get_handle ();

      // Third, update the write pointer in the header block.
      hb->wr_ptr (sizeof (ACE_HANDLE));

      // Finally, pass the message through the stream.  Note that we
      // use <Task::put> here because this gives the method at *our*
      // level in the stream a chance to do something with the message
      // before it is sent up the other side.  For instance, if we
      // receive messages in the <Supplier_Router>, it will just call
      // <put_next> and send them up the stream to the
      // <Consumer_Router> (which broadcasts them to consumers).
      // However, if we receive messages in the <Consumer_Router>, it
      // could reply to the Consumer with an error since it's not
      // correct for Consumers to send messages (we don't do this in
      // the current implementation, but it could be done in a "real"
      // application).

      if (this->peer_router_context_->peer_router ()->put (hb) == -1)
        return -1;
      else
        return 0;
    }
}
Beispiel #16
0
int
MP_Worker::svc(void)
{
	ACE_DEBUG((LM_DEBUG, ACE_TEXT ("(%t) starting up \n")));
	ACE_Message_Block* mb;

	MIME_Entity e;

	int n_eml_http_1 = 0;
	int n_eml_http_n = 0;
	int n_eml_phone = 0;
	FILE* fp;
	fp = ::fopen("d:\\_spam_\\http.log", "w");

	// pattern hash
	std::set< ACE_UINT32 > pat_set;
	int n_dup = 0;

	while(this->msg_queue()->dequeue_head(mb) != -1)
	{
		if ( ACE_OS::strlen(mb->base()) == 0 )
		{
			ACE_DEBUG(( 
				LM_DEBUG, 
				ACE_TEXT("(%t) shutting down\n")
				));
			break;
		}

		///*
		ACE_DEBUG(( 
			LM_DEBUG, 
			ACE_TEXT("(%t) %s\n"), 
			(mb->base())
			));
		//*/

		//::printf("open eml:%s\n", mb->base());
		fwrite(mb->base(), mb->size()-1, 1, fp); // mb->size()-1 to trim '\0' at the end
		fwrite("\n", 1, 1, fp);

		FILE* fp2 = ::fopen("d:\\_spam_\\_log_\\utf-8.txt", "a");
		//fwrite("\xEF\xBB\xBF", 3, 1, fp2);
		::fwrite(mb->base(), mb->size()-1, 1, fp2); // mb->size()-1 to trim '\0' at the end
		::fwrite("\r\n", 2, 1, fp2);
		::fclose(fp2);

		e.import_file(mb->base());
		//e.dump();
		//e.dump_body();

		std::set< std::string > url_set;
		//MIME_Analyzer::get_url(e, url_set);
		//MIME_Analyzer::get_phone(e);
		MIME_Analyzer::dump_body(e); // also log utf-8 txt in this function
		//getchar();

		///*
		// handle dup pattern hash
		ACE_UINT32 hash_val = MIME_Analyzer::get_hash(e);
		if ( pat_set.find(hash_val) != pat_set.end() )
		{
			std::string dup_file(ACE::basename(mb->base(), '/'));
			char prefix[10];
			::sprintf(prefix, "%.8X_", hash_val);
			prefix[9] = 0;
			dup_file = prefix + dup_file;
			dup_file = "d:/_spam_/_dup_/" + dup_file;

			//ACE_OS::rename(mb->base(), dup_file.c_str());
			ACE_OS::unlink(mb->base());

			++n_dup;
			//::printf("%s\n", dup_file.c_str());
		}
		else
		{
			pat_set.insert(hash_val);
		}
		//*/

		// display url_set
		if ( !url_set.empty() )
		{
			//printf("n_url: %d\n", url_set.size());
			std::set< std::string >::iterator iter;
			for(iter = url_set.begin(); iter != url_set.end(); ++iter)
			{
				//printf("%s\n", (*iter).c_str());
				fwrite((*iter).c_str(), (*iter).size(), 1, fp);
				fwrite("\n", 1, 1, fp);
			}
			fwrite("\n", 1, 1, fp);

			if ( url_set.size() == 1 ) ++n_eml_http_1;
			else ++n_eml_http_n;
		}
		else
		{
			//if ( MIME_Util::get_phone(e) > 0 ) ++n_eml_phone;
		}
		
		/*
		ACE_DEBUG(( 
			LM_DEBUG, 
			ACE_TEXT("(%t) %s\n"), 
			e.get_content_type().c_str()
			));
		//*/

		delete mb;

		//ACE_OS::sleep(1);
		//getchar();
	}

	printf("n_eml_http_1:%d\n", n_eml_http_1);
	printf("n_eml_http_n:%d\n", n_eml_http_n);
	printf("n_eml_http_total:%d\n", n_eml_http_1 + n_eml_http_n);
	printf("n_eml_phone:%d\n", n_eml_phone);
	fclose(fp);

	printf("n_dup:%d\n", n_dup);

	return 0;
}
int
Receiver::open_addr (const ACE_INET_Addr &localAddr)
{
  ACE_DEBUG ((LM_DEBUG,
              "%N:%l:Receiver::open_addr called\n"));

  // Create a local UDP socket to receive datagrams.
  if (this->sock_dgram_.open (localAddr) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "ACE_SOCK_Dgram::open"), -1);

  // Initialize the asynchronous read.
  if (this->rd_.open (*this,
                      this->sock_dgram_.get_handle (),
                      this->completion_key_,
                      ACE_Proactor::instance ()) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "ACE_Asynch_Read_Dgram::open"), -1);

  // Create a buffer to read into.  We are using scatter/gather to
  // read the message header and message body into 2 buffers

  // create a message block to read the message header
  ACE_Message_Block* msg = 0;
  ACE_NEW_RETURN (msg, ACE_Message_Block (1024), -1);

  // the next line sets the size of the header, even though we
  // allocated a the message block of 1k, by setting the size to 20
  // bytes then the first 20 bytes of the reveived datagram will be
  // put into this message block.
  msg->size (20); // size of header to read is 20 bytes

  // create a message block to read the message body
  ACE_Message_Block* body = 0;
  ACE_NEW_RETURN (body, ACE_Message_Block (1024), -1);
  // The message body will not exceed 1024 bytes, at least not in this test.

  // set body as the cont of msg.  This associates the 2 message
  // blocks so that a read will fill the first block (which is the
  // header) up to size (), and use the cont () block for the rest of
  // the data.  You can chain up to IOV_MAX message block using this
  // method.
  msg->cont (body);

  // ok lets do the asynch read
  size_t number_of_bytes_recvd = 0;

  int res = rd_.recv (msg,
                      number_of_bytes_recvd,
                      0,
                      PF_INET,
                      this->act_);
  switch (res)
    {
    case 0:
      // this is a good error.  The proactor will call our handler when the
      // read has completed.
      break;
    case 1:
      // actually read something, we will handle it in the handler callback
      ACE_DEBUG ((LM_DEBUG, "********************\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "%s = %d\n",
                  "bytes recieved immediately",
                  number_of_bytes_recvd));
      ACE_DEBUG ((LM_DEBUG, "********************\n"));
      res = 0;
      break;
    case -1:
      // Something else went wrong.
      ACE_ERROR ((LM_ERROR,
                  "%p\n",
                  "ACE_Asynch_Read_Dgram::recv"));
      // the handler will not get called in this case so lets clean up our msg
      msg->release ();
      break;
    default:
      // Something undocumented really went wrong.
      ACE_ERROR ((LM_ERROR,
                  "%p\n",
                  "ACE_Asynch_Read_Dgram::recv"));
      msg->release ();
      break;
    }

  return res;
}
Beispiel #18
0
int
Thread_Pool::test_empty_message_shutdown (void)
{
  if (this->open () == -1)
    return -1;

  ACE_Message_Block *mb = 0;

  // Run the main loop that generates messages and enqueues them into
  // the pool of threads managed by <ACE_Task>.

  for (size_t count = 0;
       ;
       count++)
    {
      ssize_t n = 0;

      // Allocate a new message.
      ACE_NEW_RETURN (mb,
                      ACE_Message_Block (BUFSIZ,
                                         ACE_Message_Block::MB_DATA,
                                         0,
                                         0,
                                         0,
                                         &this->lock_adapter_),
                      -1);

      if (manual)
        {
#if !defined (ACE_HAS_WINCE)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%t) enter a new message for ")
                      ACE_TEXT ("the task pool...")));
          n = ACE_OS::read (ACE_STDIN,
                            mb->wr_ptr (),
                            mb->size ());
#endif  // ACE_HAS_WINCE
        }
      else
        {
          static size_t count = 0;

          ACE_OS::sprintf (reinterpret_cast<ACE_TCHAR *> (mb->wr_ptr ()),
                           ACE_SIZE_T_FORMAT_SPECIFIER,
                           count);
          n = ACE_OS::strlen (mb->rd_ptr ());

          if (count == n_iterations)
            n = 1; // Indicate that we need to shut down.
          else
            count++;

          if (count == 0 || (count % 20 == 0))
            ACE_OS::sleep (1);
        }

      if (n > 1)
        {
          // Send a normal message to the waiting threads and continue
          // producing.
          mb->wr_ptr (n * sizeof (ACE_TCHAR));

          // Pass the message to the Thread_Pool.
          if (this->put (mb) == -1)
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT (" (%t) %p\n"),
                        ACE_TEXT ("put")));
        }
      else
        {
          // Send a shutdown message to the waiting threads and return.
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\n(%t) sending shutdown message to %d threads, ")
                      ACE_TEXT ("dump of task:\n"),
                      this->thr_count ()));
          this->dump ();

          size_t i = 0;

          // Enqueue an empty message to flag each consumer thread to
          // inform it to shutdown.
          for (i = this->thr_count ();
               i > 0;
               i--)
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%t) end of input, ")
                          ACE_TEXT ("enqueueing \"empty\" message %d\n"),
                          i));

              // Note the use of reference counting to avoid copying
              // the message contents.
              ACE_Message_Block *dup = mb->duplicate ();

              if (this->put (dup) == -1)
                ACE_ERROR ((LM_ERROR,
                            ACE_TEXT (" (%t) %p\n"),
                            ACE_TEXT ("put")));
            }

          mb->release ();

          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\n(%t) end loop, dump of task:\n")));
          this->dump ();

          return 0;
        }
    }
}
Beispiel #19
0
int
Thread_Pool::test_queue_deactivation_shutdown (void)
{
  if (this->open () == -1)
    return -1;

  ACE_Message_Block *mb = 0;

  // Run the main loop that generates messages and enqueues them into
  // the pool of threads managed by <ACE_Task>.

  for (size_t count = 0;
       ;
       count++)
    {
      ssize_t n = 0;

      // Allocate a new message.
      ACE_NEW_RETURN (mb,
                      ACE_Message_Block (BUFSIZ,
                                         ACE_Message_Block::MB_DATA,
                                         0,
                                         0,
                                         0,
                                         &this->lock_adapter_),
                      -1);

      if (manual)
        {
#if !defined (ACE_HAS_WINCE)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%t) enter a new message for ")
                      ACE_TEXT ("the task pool...")));
          n = ACE_OS::read (ACE_STDIN,
                            mb->wr_ptr (),
                            mb->size ());
#endif  // ACE_HAS_WINCE
        }
      else
        {
          static size_t count = 0;

          ACE_OS::sprintf (reinterpret_cast<ACE_TCHAR *> (mb->wr_ptr ()),
                           ACE_SIZE_T_FORMAT_SPECIFIER,
                           count);
          n = ACE_OS::strlen (mb->rd_ptr ());

          if (count == n_iterations)
            n = 1; // Indicate that we need to shut down.
          else
            count++;

          if (count == 0 || (count % 20 == 0))
            ACE_OS::sleep (1);
        }

      if (n > 1)
        {
          // Send a normal message to the waiting threads and continue
          // producing.
          mb->wr_ptr (n * sizeof (ACE_TCHAR));

          // Pass the message to the Thread_Pool.
          if (this->put (mb) == -1)
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT (" (%t) %p\n"),
                        ACE_TEXT ("put")));
        }
      else
        {
          // Release the <Message_Block> since we're shutting down and
          // don't need it anymore.

          mb->release ();
          // Deactivate the message queue and return.
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\n(%t) deactivating queue for %d threads, ")
                      ACE_TEXT ("dump of task:\n"),
                      this->thr_count ()));
          this->dump ();

          // Deactivate the queue.
          return this->msg_queue ()->deactivate ();
        }
    }
}