Beispiel #1
0
int
ACE_RMCast_Fragment_Tester::data (ACE_RMCast::Data &data)
{
  ACE_UINT32 sequence_number = data.sequence_number;
  ACE_UINT32 message_size = data.total_size;
  size_t offset = data.fragment_offset;
  ACE_Message_Block *mb = data.payload;

  if (this->received_bytes_ == 0)
    {
      this->received_.size (message_size);
      this->received_.wr_ptr (message_size);
      this->message_sequence_number_ =  sequence_number;
    }
  else
    {
      if (this->message_sequence_number_ != sequence_number)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Mismatched sequence number\n")),
                          -1);
      if (this->received_.length () != message_size)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Mismatched sequence size\n")),
                          -1);
    }

  size_t payload_size = mb->length ();
  size_t fragment_size = payload_size;
  if (payload_size > 0)
    {
      ACE_OS::memcpy (this->received_.rd_ptr () + offset,
                      mb->rd_ptr (),
                      payload_size);
      this->received_bytes_ += payload_size;
      offset += payload_size;
    }

  for (const ACE_Message_Block *i = mb->cont (); i != 0; i = i->cont ())
    {
      payload_size = i->length ();
      // ACE_DEBUG ((LM_DEBUG,
      //         "offset = %d , payload = %d\n", offset, payload_size));
      fragment_size += payload_size;
      ACE_OS::memcpy (this->received_.rd_ptr () + offset,
                      i->rd_ptr (), payload_size);
      this->received_bytes_ += payload_size;
      offset += payload_size;
    }

  if (fragment_size > this->fragment_.max_fragment_size ())
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Invalid fragment size\n")),
                      -1);

  return 0;
}
Beispiel #2
0
int
Thread_Pool::svc (void)
{
  // Keep looping, reading a message out of the queue, until we get a
  // message with a length == 0, which signals us to quit.

  for (int count = 1; ; count++)
    {
      ACE_Message_Block *mb = 0;

      int result = this->getq (mb);

      ACE_TEST_ASSERT (result != -1 || errno == ESHUTDOWN);

      if (result == -1 && errno == ESHUTDOWN)
        {
          // The queue has been deactivated, so let's bail out.
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%t) in iteration %d, queue len = %d, ")
                      ACE_TEXT ("queue deactivated, exiting\n"),
                      count,
                      this->msg_queue ()->message_count ()));

          break;
        }

      size_t length = mb->length ();

      if (length > 0)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%t) in iteration %d, queue len = %d, ")
                    ACE_TEXT ("length = %d, text = \"%*s\"\n"),
                    count,
                    this->msg_queue ()->message_count (),
                    length,
                    length - 1,
                    mb->rd_ptr ()));

      // We're responsible for deallocating this.
      mb->release ();

      if (length == 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%t) in iteration %d, queue len = %d, ")
                      ACE_TEXT ("got \"empty\" message, exiting\n"),
                      count,
                      this->msg_queue ()->message_count ()));
          break;
        }
    }

  // Note that the <ACE_Task::svc_run> method automatically removes us
  // from the <ACE_Thread_Manager> when the thread exits.
  return 0;
}
Beispiel #3
0
int
HTTP_SSL_Client_Session::on_read_complete(ACE_Message_Block& mb, const TRB_Asynch_Read_Stream::Result& result)
{
	ACE_OS::write_n(ACE_STDOUT, mb.rd_ptr(), mb.length()); //@

	//static int i = 0;
	//::printf("%d, ", i++);

	return 0;
}
Beispiel #4
0
void
JAWS_Asynch_IO::receive_file (JAWS_IO_Handler *ioh,
                              const char *filename,
                              void *initial_data,
                              unsigned int initial_data_length,
                              unsigned int entire_length)
{
  JAWS_TRACE ("JAWS_Asynch_IO::receive_file");

  ioh->idle ();

  JAWS_Asynch_IO_Handler *aioh =
    dynamic_cast<JAWS_Asynch_IO_Handler *> (ioh);

  ACE_Message_Block *mb = 0;
  ACE_Filecache_Handle *handle;

  ACE_NEW (handle, ACE_Filecache_Handle (filename, entire_length, ACE_NOMAP));

  int result = handle->error ();

  if (result == ACE_Filecache_Handle::ACE_SUCCESS)
    {
      ACE_OS::memcpy (handle->address (),
                      initial_data,
                      initial_data_length);

      int bytes_to_read = entire_length - initial_data_length;

      ACE_NEW (mb, ACE_Message_Block ((char *)handle->address ()
                                      + initial_data_length, bytes_to_read));

      if (mb == 0)
        {
          errno = ENOMEM;
          result = -1;
        }
      else
        {
          ACE_Asynch_Read_Stream ar;

          if (ar.open (*(aioh->handler ()), aioh->handle ()) == -1
              || ar.read (*mb, mb->size () - mb->length (), handle) == -1)
            result = -1;
        }
    }

  if (result != ACE_Filecache_Handle::ACE_SUCCESS)
    {
      this->handler_->receive_file_error (result);
      delete mb;
      delete handle;
    }
}
Beispiel #5
0
int RASocket::process_command (const std::string& command)
{
    if (command.length() == 0)
        return 0;

    sLog->outRemote("Got command: %s", command.c_str());

    // handle quit, exit and logout commands to terminate connection
    if (command == "quit" || command == "exit" || command == "logout")
    {
        (void) send("Bye\r\n");
        return -1;
    }

    CliCommandHolder* cmd = new CliCommandHolder(this, command.c_str(), &RASocket::zprint, &RASocket::commandFinished);
    sWorld->QueueCliCommand(cmd);

    // wait for result
    ACE_Message_Block* mb;
    for (;;)
    {
        if (getq(mb) == -1)
            return -1;

        if (mb->msg_type() == ACE_Message_Block::MB_BREAK)
        {
            mb->release();
            break;
        }

        if (size_t(peer().send(mb->rd_ptr(), mb->length())) != mb->length())
        {
            mb->release();
            return -1;
        }

        mb->release();
    }

    return 0;
}
Beispiel #6
0
static void *
consumer (void *args)
{
  ACE_Message_Queue<ACE_MT_SYNCH> *msg_queue =
    reinterpret_cast<ACE_Message_Queue<ACE_MT_SYNCH> *> (args);

  u_long cur_priority = 27;
  ACE_UNUSED_ARG (cur_priority);
  // To suppress ghs warning about unused local variable
  // "cur_priority".

  int local_count = 0;

  // Keep looping, reading a message out of the queue, until we get a
  // message with a length == 0, which signals us to quit.
  for (char c = 'z'; ; c--)
    {
      ACE_Message_Block *mb = 0;

      int result = msg_queue->dequeue_head (mb);

      if (result == -1)
        break;

      local_count++;

      size_t length = mb->length ();

      if (length > 0)
        {
          // This isn't a "shutdown" message, so process it
          // "normally."
          ACE_TEST_ASSERT (c == *mb->rd_ptr ());
          ACE_TEST_ASSERT (mb->msg_priority () < cur_priority);
          cur_priority = mb->msg_priority ();
        }

      // Free up the buffer memory and the Message_Block. Note that
      // the destructor of Message Block will delete the the actual
      // buffer.
      mb->release ();

      if (length == 0)
        // This was a "shutdown" message, so break out of the loop.
        break;
    }

  ACE_TEST_ASSERT (local_count == message_count);
  return 0;
}
Beispiel #7
0
int
ACE_RMCast_Reassembly_Tester::data (ACE_RMCast::Data &data)
{
  ACE_Message_Block *mb = data.payload;

  ACE_Message_Block *pointer;
  ACE_OS::memcpy (&pointer, mb->rd_ptr (), sizeof(pointer));

  size_t l = mb->length ();
  pointer->size (l);
  pointer->wr_ptr (pointer->rd_ptr () + l);
  ACE_OS::memcpy (pointer->rd_ptr (), mb->rd_ptr (), l);
  return 0;
}
Beispiel #8
0
int
Sender::initiate_write_stream ()
{
  if (this->flg_cancel_ != 0)
    {
      return -1;
    }

  if (this->get_ref_cnt_w() != 0)
    {
      return 0; // todo: queue it
    }


  u_int blksize = this->config().s_blksize();
  u_int limit   = this->config().xfer_limit();
  u_int winsize = this->config().w_size();

  if (limit != 0 && this->total_snd_ >= limit)
    {
      this->shutdown_i ();
      return 0;
    }

  u_long delta = this->total_snd_- this->total_rcv_;
  if (delta > winsize)
     return 0;

  ACE_Message_Block *mb = 0;

  ACE_NEW_RETURN (mb,
                  ACE_Message_Block (blksize+1),
                  -1);

  mb->copy(complete_message);
  mb->copy("\0");
  mb->wr_ptr(mb->base() + blksize);
 

  if (this->stream_.write (*mb, mb->length ()) == -1)
    {
      mb->release ();
      this->cancel_i();
      return -1;
    }

  this->ref_cnt_w_++;
  this->total_w_++;
  return 0;
}
Beispiel #9
0
void
DSession::handle_user_operation(const TRB_Asynch_User_Result& result)
{
  ACE_Message_Block *mb =result.get_message_block_ptr ();

  ACE_ASSERT (mb != 0);
  ACE_ASSERT (this->index() == (int) result.act ());

  {
    ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->lock_);

    this->post_count_--;

      {
        LogLocker log_lock;


        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%t) **** %s=%d handle_message() ****\n"),
                    this->get_name(),
                    this->index()));

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("%s = %d\n"),
                    ACE_TEXT ("length"),
                    mb->length()));

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("%s = %d\n"),
                    ACE_TEXT ("act"),
                    (int) result.act ()));

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("%s = %s\n"),
                    ACE_TEXT ("message_block"),
                    mb->rd_ptr ()));
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("**** end of message ****************\n")));
      }

    mb->release();
  
    if (this->io_count_r_ != 0 || 
        this->io_count_w_ != 0 ||
        this->post_count_ != 0 )
      return;
  }

  delete this;
}
Beispiel #10
0
// Listing 6 code/ch07
int
ClientService::handle_output (ACE_HANDLE)
{
  ACE_Message_Block *mb;
  ACE_Time_Value nowait (ACE_OS::gettimeofday ());
  while (-1 != this->getq (mb, &nowait))
    {
      ssize_t send_cnt =
        this->peer ().send (mb->rd_ptr (), mb->length ());
      if (send_cnt == -1)
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("(%P|%t) %p\n"),
                    ACE_TEXT ("send")));
      else
        mb->rd_ptr (static_cast<size_t> (send_cnt));
      if (mb->length () > 0)
        {
          this->ungetq (mb);
          break;
        }
      mb->release ();
    }
  return (this->msg_queue ()->is_empty ()) ? -1 : 0;
}
Beispiel #11
0
int TCPConnectionHandler::sendBuffers ()
{
  int result = 0;

  if (buffers_)
    if (0 < (result = peer_.send_n (buffers_))) // remove sent blocks
      {
        totalSent_ += result;
        while (buffers_ &&
               static_cast< size_t > (result) >= buffers_->length ())
          {
            ACE_Message_Block *buffer = buffers_;
            result -= buffers_->length ();
            buffers_= buffers_->cont ();
            buffer->cont (0);
            buffer->release ();
          }

        if (buffers_) // some buffers were not sent, truncate data
          buffers_->rd_ptr (result);
      }

  return result;
}
Beispiel #12
0
int
Receiver::on_data_sent(ACE_Message_Block & mb,
                       const ACE_INET_Addr & remote)
{
  ACE_UNUSED_ARG(remote);

  int nbytes = mb.length ();

  mb.release();

  if ( nbytes > 0 && this->io_count_r_ == 0)
    this->initiate_read();

  return 0;
}
int Test_Service_Handler::send()
{
  ACE_Guard<ACE_Recursive_Thread_Mutex> guard(mtx_);

  ACE_DEBUG ((LM_DEBUG, 
      ACE_TEXT("(%t) %s_Handler(%@)::send() fd=%d\n"),
      is_caller_ ? "Client" : "Server" ,
      this,
      this->handle()));

  //AL:
  if (!cancel_called_)
  {
     //AL: not thread safe
     //static std::string pkt = pkt_header;
     //pkt += pkt_payload;

     size_t len_header  = ACE_OS::strlen(pkt_header);
     size_t len_payload = ACE_OS::strlen(pkt_payload);

     ACE_Message_Block *mb = 0;

     ACE_NEW_RETURN(mb, ACE_Message_Block(len_header+len_payload), -1);

     mb->copy(pkt_header, len_header);
     mb->copy(pkt_payload, len_payload);
    
     int ret = writer_.write(*mb, mb->length());
     if (ret == 0)
     {
        write_count_++;
        return 0;
     }

     mb->release();

  }

  ACE_DEBUG ((LM_DEBUG,
      ACE_TEXT("(%t) %s_Handler(%@)::send failed\n"),
      is_caller_ ? "Client" : "Server" ,
      this));

  //AL: delete_if_reqd();
  this->cancel();

  return -1;
}
Beispiel #14
0
// New stuff added to the message queue.  Try to dequeue a message.
int
Peer_Handler::handle_output (ACE_HANDLE)
{
  ACE_Message_Block *mb = 0;

  ACE_Time_Value tv (ACE_Time_Value::zero);

  // Forward the message to the remote peer receiver.
  if (this->getq (mb, &tv) != -1)
    {
      if (this->wr_stream_.write (*mb,
                                  mb->length ()) == -1)
        ACE_ERROR_RETURN ((LM_ERROR, "%p Write initiate.\n", "Peer_Handler"), -1);
    }
  return 0;
}
    template<> ACE_Message_Block *
    lifecycle_frame_serializer::pack( const LifeCycleData& v )
    {
	ACE_OutputCDR ace_cdr;
	OutputCDR cdr(ace_cdr);
	
	LifeCycleFrame frame( boost::apply_visitor( internal::lifecycle_command_visitor(), v ) );
	
	internal::lifecycle_serializer::serialize(cdr, frame);
	unsigned int size = boost::apply_visitor( internal::lifecycle_serializer_visitor(cdr), v );
	ACE_UNUSED_ARG(size);
	
	ACE_Message_Block * mb = cdr.begin()->clone();
	mb->length( cdr.length() );
	return mb;
    }
Beispiel #16
0
int
PConnection::do_initiate_write_stream (ACE_Message_Block &mb)
{
    size_t nbytes = mb.length();

    if (this->start_asynch_write (mb, nbytes) == 0)
    {
        this->ref_cnt_w_++;
        this->total_w_++;
        return 0;
    }

    this->free_msg (&mb);
    this->cancel ();
    return -1;
}
Beispiel #17
0
template <class BARRIER> int
Worker_Task<BARRIER>::svc (void)
{
  // Note that the <ACE_Task::svc_run> method automatically adds us to
  // the Thread_Manager when the thread begins.

  // Keep looping, reading a message out of the queue, until we get a
  // message with a length == 0, which signals us to quit.

  for (int iter = 1; ;iter++)
    {
      ACE_Message_Block *mb = 0;

      int result = this->getq (mb);

      if (result == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      "(%t) in iteration %d\n",
                      "error waiting for message in iteration",
                      iter));
          break;
        }

      size_t length = mb->length ();
      this->service (mb,iter);

      if (length == 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "(%t) in iteration %d got quit, exit!\n",
                      iter));
                      mb->release ();
          break;
        }

      this->barrier_.wait ();
      this->output (mb);

      mb->release ();
    }

  // Note that the <ACE_Task::svc_run> method automatically removes us
  // from the Thread_Manager when the thread exits.

  return 0;
}
Beispiel #18
0
int
Peer_Handler::await_events (void)
{
  ACE_Message_Block *mb = 0;

  ssize_t n = this->recv (mb);

  switch (n)
    {
    case 0:
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("gatewayd has closed down\n")),
                        -1);
      /* NOTREACHED */
    case -1:
      if (errno == EWOULDBLOCK)
        // A short-read, we'll come back and finish it up later on!
        return 0;
      else
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("%p\n"),
                           ACE_TEXT ("recv")),
                          -1);
      /* NOTREACHED */
    default:
      {
        // We got a valid event, so let's process it now!  At the
        // moment, we just print out the event contents...

        Event *event = (Event *) mb->rd_ptr ();
        this->total_bytes_ += mb->length ();

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("route id = %d, cur len = %d, total len = %d\n"),
                    event->header_.connection_id_,
                    event->header_.len_,
                    this->total_bytes_));
        if (Options::instance ()->enabled (Options::VERBOSE))
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("data_ = %*s\n"),
                      event->header_.len_ - 2,
                      event->data_));
        mb->release ();
        return 0;
      }
    }
}
Beispiel #19
0
int
Producer::svc (void)
{
    // Keep reading stdin, until we reach EOF.

    for (int n; ; )
    {
        // Allocate a new message (add one to avoid nasty boundary
        // conditions).

        ACE_Message_Block *mb = 0;

        ACE_NEW_RETURN (mb,
                        ACE_Message_Block (BUFSIZ + 1),
                        -1);

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

        if (n <= 0)
        {
            // Send a shutdown message to the other thread and exit.
            mb->length (0);

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

        // Send the message to the other thread.
        else
        {
            mb->wr_ptr (n);
            // NUL-terminate the string (since we use strlen() on it
            // later).
            mb->rd_ptr ()[n] = '\0';

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

    return 0;
}
Beispiel #20
0
void ProactorService::SendInternal(char* pBuffer, int bufferSize)
{			
	ACE_Message_Block* pBlock = NULL;

	ACE_NEW_NORETURN(pBlock, ACE_Message_Block(bufferSize));

	pBlock->copy((const char*)pBuffer, bufferSize);

	if(NULL == pBlock->cont())
	{
		m_AsyncWriter.write(*pBlock, pBlock->length());
	}
	else
	{
		m_AsyncWriter.writev(*pBlock, pBlock->total_length());
	}	
}
void
HTTP_Client_Connection::on_write_some(ACE_Message_Block& mb, size_t bytes_transferred)
{
	// keep writing
	if ( mb.length() > 0 )
	{
		this->write(mb);
		return;
	}
	// write completed
	else
	{
		buf_.resize(0);

		mb.reset();
		this->read(mb);
	}	
}
Beispiel #22
0
int 
Sender::initiate_write_stream (void)
{
  ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_);   

  welcome_message_.rd_ptr(welcome_message_.base ());
  welcome_message_.wr_ptr(welcome_message_.base ());
  welcome_message_.wr_ptr (ACE_OS::strlen (data));
	
  if (this->ws_.write (welcome_message_,
                       welcome_message_.length ()) == -1)
    ACE_ERROR_RETURN((LM_ERROR,
                      "%p\n",
                      "ACE_Asynch_Write_Stream::write"),
                     -1);
  io_count_++;
  return 0;
}
Beispiel #23
0
int RealmSocket::handle_output(ACE_HANDLE)
{
    if (closing_)
        return -1;

    ACE_Message_Block* mb = 0;

    if (msg_queue()->is_empty())
    {
        reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
        return 0;
    }

    if (msg_queue()->dequeue_head(mb, (ACE_Time_Value *)(&ACE_Time_Value::zero)) == -1)
        return -1;

    ssize_t n = noblk_send(*mb);

    if (n < 0)
    {
        mb->release();
        return -1;
    }
    else if (size_t(n) == mb->length())
    {
        mb->release();
        return 1;
    }
    else
    {
        mb->rd_ptr(n);

        if (msg_queue()->enqueue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
        {
            mb->release();
            return -1;
        }

        return 0;
    }

    ACE_NOTREACHED(return -1);
}
Beispiel #24
0
int
IMAP4_SSL_Client_Session::on_write_complete(ACE_Message_Block& mb, const TRB_Asynch_Write_Stream::Result& result)
{
	//ACE_Time_Value tv(0, 10 * 1000);
	//timespec_t t  = (timespec_t) tv;
	//ACE_OS::nanosleep(&t);

	ACE_OS::write_n(ACE_STDOUT, mb.rd_ptr(), mb.length()); //@

	ACE_Message_Block* mb_read = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
	if ( !mb_read ) return -1;
	if ( read(*mb_read) != 0 ) return -1;

	// initialize a new read
	++step_;
	io_.read_reset();

	return 0;
}
Beispiel #25
0
int
DSession::initiate_write (ACE_Message_Block &mb,
                          const ACE_INET_Addr & addr)
{

  size_t nbytes = mb.length();

  if (cfg.loglevel() <= 1)
      {
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%t) %s=%d Initiate WRITE %u bytes\n"),
                    this->get_name (),
                    this->index (),
                    nbytes));
      }

  if (nbytes == 0)
    {
      mb.release ();
      this->stream_.cancel_and_close();
      return -1;
    }

  if (this->stream_.send(mb,
                         nbytes,
                         0, 
                         addr) == -1)
    {
      mb.release ();
      this->stream_.cancel_and_close();

      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT ("(%t) %s=%d attempt WRITE failed\n"),
                        this->get_name(),
                        this->index()),
                        -1);
    }

  this->io_count_w_++;
  this->total_w_++;
  return 0;
}
Beispiel #26
0
int
Receiver::on_data_received(ACE_Message_Block & mb,
                           const ACE_INET_Addr & remote)
{
  int nbytes = mb.length ();

  if (nbytes == 0)
    {
      mb.release();
      return 0;
    }

  if (this->io_count_r_ == 0)
    this->initiate_read();

  if (this->initiate_write (mb, remote) != 0)
    return -1;

  return 0;
}
void
SBRS_Server_Connection::write(ACE_Message_Block& mb, long timeout)
{
	ACE_GUARD(ACE_Thread_Mutex, guard, lock_);

	socket_.async_write_some(buffer(mb.rd_ptr(), mb.length()), strand_.wrap(boost::bind(
		&SBRS_Server_Connection::handle_write,
		this,
		placeholders::error,
		placeholders::bytes_transferred)));

	if ( timeout > 0 )
	{
		timer_.expires_from_now(boost::posix_time::seconds(timeout));
		timer_.async_wait(strand_.wrap(boost::bind(
			&SBRS_Server_Connection::handle_socket_timeout,
			this,
			placeholders::error)));
	}
}
Beispiel #28
0
int
PConnection::initiate_write_stream (ACE_Message_Block &mb)
{
    size_t nbytes = mb.length();

    int rc = 0;

    if (nbytes == 0)
    {
        this->free_msg (&mb);
        this->cancel ();
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT ("(%t) %s PConnection: attempt write 0 bytes\n"),
                          this->get_name()),
                         -1);
    }

    if (this->get_ref_cnt_w() != 0)
    {
        ACE_Time_Value tv = ACE_Time_Value::zero;

        if (out_mq_.enqueue_tail (&mb, &tv) < 0)
        {
            this->free_msg (&mb);
            this->cancel ();
            ACE_ERROR_RETURN((LM_ERROR,
                              ACE_TEXT ("(%t) %s PConnection: attempt to queue failed\n"),
                              this->get_name()),
                             -1);
        }
        this->total_snd_ += nbytes;
        return 0;
    }


    if (do_initiate_write_stream (mb) != 0)
        return -1;

    this->total_snd_ += nbytes;
    return 0;
}
Beispiel #29
0
/*virtual*/ int BufferedSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
{
    ACE_Message_Block* mb = 0;

    if (this->msg_queue()->is_empty())
    {
        // if no more data to send, then cancel notification
        this->reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
        return 0;
    }

    if (this->msg_queue()->dequeue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
        return -1;

    ssize_t n = this->noblk_send(*mb);

    if (n < 0)
    {
        mb->release();
        return -1;
    }
    else if (n == mb->length())
    {
        mb->release();
        return 1;
    }
    else
    {
        mb->rd_ptr(n);

        if (this->msg_queue()->enqueue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
        {
            mb->release();
            return -1;
        }

        return 0;
    }

    ACE_NOTREACHED(return -1);
}
Beispiel #30
0
int RASocket::process_command(const std::string& command)
{
    if (command.length() == 0)
        return 0;

    TC_LOG_INFO(LOG_FILTER_REMOTECOMMAND, "Received command: %s", command.c_str());

    // handle quit, exit and logout commands to terminate connection
    if (command == "quit" || command == "exit" || command == "logout") {
        (void) send("Bye\r\n");
        return -1;
    }

    _commandExecuting = true;
    CliCommandHolder* cmd = new CliCommandHolder(this, command.c_str(), &RASocket::zprint, &RASocket::commandFinished);
    sWorld->QueueCliCommand(cmd);

    // wait for result
    ACE_Message_Block* mb;
    for (;;)
    {
        if (getq(mb) == -1)
            return -1;

        if (mb->msg_type() == ACE_Message_Block::MB_BREAK)
        {
            mb->release();
            break;
        }

        if (send(std::string(mb->rd_ptr(), mb->length())) == -1)
        {
            mb->release();
            return -1;
        }

        mb->release();
    }

    return 0;
}