当前位置: 首页>>代码示例>>C++>>正文


C++ ACE_Message_Block::space方法代码示例

本文整理汇总了C++中ACE_Message_Block::space方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Message_Block::space方法的具体用法?C++ ACE_Message_Block::space怎么用?C++ ACE_Message_Block::space使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ACE_Message_Block的用法示例。


在下文中一共展示了ACE_Message_Block::space方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: new

int
HTTP_SSL_Server_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()); //@

	HTTP::Responser http;

	if ( mb.space() == 0 || (mb.length() > 4 && ACE_OS::strncmp(mb.wr_ptr()-4, "\r\n\r\n", 4) == 0) )
	{
		//ACE_Time_Value tv(0, 1 * 1000);
		//timespec_t t  = (timespec_t) tv;
		//ACE_OS::nanosleep(&t);

		int n_err = 0;
		if ( mb.space() == 0 ) n_err = HTTP::Response::Request_Entity_Too_Large;
		
		ACE_Message_Block* out = new (std::nothrow) ACE_Message_Block(BUFSIZE);
		int n_res = http.parse_header(&mb, out, n_err);

		write(*out);
	}
	else
	{
		read(mb);
		return 1;
	}

	return 0;
}
开发者ID:ancrux,项目名称:cpp-ex,代码行数:29,代码来源:HTTP_Session.cpp

示例2: io_result

int
JAWS_IO_Reactive_Transmit::handle_output_source (ACE_HANDLE handle)
{
  ACE_Message_Block *mb = this->source_buf_;

  // Try to read data into the mb if data is still available.
  if (mb->space () && this->source_ != ACE_INVALID_HANDLE)
    {
      ssize_t count;
      count = ACE_OS::read (this->source_, mb->wr_ptr (), mb->space ());

      if (count < 0)
        {
          this->source_ = ACE_INVALID_HANDLE;
          this->source_buf_ = 0;

          if (this->bytes_ == 0)
            {
              JAWS_Event_Result io_result ( 0
                                          , JAWS_Event_Result::JE_ERROR
                                          , JAWS_Event_Result::JE_TRANSMIT_FAIL
                                          );
              this->io_result_ = io_result;
            }
          else if (this->bytes_ > 0)
            {
              JAWS_Event_Result io_result ( this->bytes_
                                          , JAWS_Event_Result::JE_ERROR
                                          , JAWS_Event_Result::JE_TRANSMIT_SHORT
                                          );
              this->io_result_ = io_result;
            }

          return -1;
        }
      else if (count == 0)
        this->source_ = ACE_INVALID_HANDLE;
      else
        mb->wr_ptr (count);
    }

  int result = 0;

  if (mb->length () > 0)
    result = this->handle_output_mb (handle, mb);

  if (result < 0)
    {
      this->source_ = ACE_INVALID_HANDLE;
      this->source_buf_ = 0;
    }
  else if (mb == 0 && this->source_ == ACE_INVALID_HANDLE)
    this->source_buf_ = 0;
  else
    this->source_buf_->crunch ();

  return result;
}
开发者ID:binghuo365,项目名称:BaseLab,代码行数:58,代码来源:Reactive_IO.cpp

示例3: get_file

//get file and store it into ACE message block.
bool ZIP_Wrapper::get_file (char* archive_path, char* filename,
                            ACE_Message_Block &file)
{
  bool return_code = true;
  unzFile uf=0;
  uf = unzOpen(archive_path);
  /* locate the desired file in the zip file and set it as current file*/
  int j=unzLocateFile(uf, filename, 0);
  if (j==UNZ_END_OF_LIST_OF_FILE)
    {
      DANCE_ERROR (DANCE_LOG_ERROR,
                   (LM_DEBUG, ACE_TEXT("File not found in zip archive")));
      return false;
    }
  else if (j==UNZ_OK)
    {
      int k=unzOpenCurrentFile(uf);
      if (k!=UNZ_OK)
        {
          DANCE_ERROR (DANCE_LOG_ERROR,
                       (LM_DEBUG, ACE_TEXT("Error in opening the current")
                        ACE_TEXT(" file using unzOpenCurrentFile")));
          return false;
        }
      else
        {
          int num_read = 0;
          ACE_Message_Block* head = &file;

          //read the file into the ACE_Message_Block
          do
            {
              if (head->space () == 0)
                {
                  ACE_Message_Block* next = 0;
                  ACE_NEW_RETURN (next, ACE_Message_Block (BUFSIZ), false);
                  head = head->cont ();
                }
              num_read = unzReadCurrentFile(archive_path, head->wr_ptr(),
                                                  head->space());
              if (num_read > 0)
                head->wr_ptr (num_read);
            } while (num_read > 0);
          if (num_read < 0)
            return_code = false;
          unzCloseCurrentFile(uf);
          unzClose(uf);
          return return_code;
        }
    }
  return return_code;
}
开发者ID:DOCGroup,项目名称:DAnCE,代码行数:53,代码来源:ZIP_Wrapper.cpp

示例4: assert

bool P2pEndpoint::readMessage(ACE_INET_Addr& peerAddr,
    ACE_Message_Block& mblock)
{
    assert(mblock.size() >= P2pConfig::defaultMtu);

    const ssize_t recvSize =
        udp_->recv(mblock.wr_ptr(), mblock.space(), peerAddr);
    if (recvSize == 0) {
        return false;
    }

    if (recvSize < 0) {
        const int error = ACE_OS::last_error();
        if (error == EWOULDBLOCK) {
            return false;
        }
        //if (error == ECONNRESET) {
        //    return false;
        //}

        NSRPC_LOG_ERROR4(
            ACE_TEXT("P2pEndpoint::readMessage(from: %s:%d) FAILED!!!(%d,%m)"),
            peerAddr.get_host_addr(), peerAddr.get_port_number(),
            ACE_OS::last_error());
        return false;
    }
    mblock.wr_ptr(recvSize);

    return true;
}
开发者ID:jcloudpld,项目名称:srpc,代码行数:30,代码来源:P2pEndpoint.cpp

示例5: read

int
AIO_SSL_Client_Session::read(ACE_Message_Block& mb)
{
	if ( ssl_ )
	{
		if ( is_cancelling_ ) return -1;
		if ( n_op_r_ != 0 ) // > 0
		{
			mb.release();
			return n_op_r_; // don't start second read, and return # of pending read
		}

		// Inititiate read
		if ( this->ssl_stream_.read(mb, mb.space()) == -1)
		{
			mb.release();
			if ( !is_cancelling_ ) { is_cancelling_ = 1; ssl_stream_.cancel(); }
			return -1;
		}

		++n_op_r_;

		return 0;
	}
	else
	{
		return AIO_Session::read(mb);
	}
}
开发者ID:ancrux,项目名称:cpp-ex,代码行数:29,代码来源:AIO_SSL_Client_Session.cpp

示例6: defined

//***************************************************************************
//
//    Method:          handle_write_file
//
//    Description:   Callback used when a write completes
//
// Inputs:        write file result structure containing message block
//
// Returns:       none
//
//***************************************************************************
void
FileIOHandler::handle_write_file(const ACE_Asynch_Write_File::Result &result)
{
  ACE_DEBUG((LM_INFO, ACE_TEXT("Finished write\n")));
  // When the write completes, we get the message block. It's been sent,
  // so we just deallocate it.
  result.message_block().release();
#if defined (ACE_WIN32)
  // to circumvent problems on older Win32 (see above) we schedule a read here if none
  // is pending yet.
  if (!this->read_pending_)
  {
    ACE_Message_Block *mb;
    ACE_NEW_NORETURN(mb, ACE_Message_Block(FILE_FRAME_SIZE));
    if (reader_.read(*mb, mb->space(),
                     (this->block_count_ - 1) * FILE_FRAME_SIZE) != 0)
    {
      int errnr = ACE_OS::last_error ();
      ACE_DEBUG(
          (LM_INFO, ACE_TEXT("%p [%d]\n"), ACE_TEXT("FileIOHandler read after write failed"), errnr));
      mb->release();
    }
    else
    {
      this->read_pending_ = true;
    }
  }
#endif
}
开发者ID:esohns,项目名称:ATCD,代码行数:40,代码来源:Proactor_File_Test.cpp

示例7:

int
PSession::initiate_read (u_long offset_low, u_long offset_high, ACE_Message_Block & mb)
{
    size_t nbytes = mb.space();

    if (nbytes == 0)
    {
        mb.release ();
        this->do_cancel ();

        ACE_ERROR_RETURN((LM_ERROR,
            ACE_TEXT ("(%t) %s Attempt to read 0 bytes\n"),
            this->get_name()),
            -1);
    }

    int rc = this->file_read_.read (mb, nbytes, offset_low, offset_high);

    if (rc < 0)
    {
        mb.release();
        this->do_cancel ();
        return -1;
    }

    this->ref_cnt_r_++;
    this->total_r_++;
    return 0;
}
开发者ID:binghuo365,项目名称:BaseLab,代码行数:29,代码来源:PSession.cpp

示例8:

void
TCP_Client_Connection::read(ACE_Message_Block& mb)
{
	//ACE_GUARD(ACE_Thread_Mutex, guard, lock_);

	if ( timeout_ > 0 )
	{
		timer_.expires_from_now(boost::posix_time::seconds(timeout_));
		timer_.async_wait(
			strand_.wrap(boost::bind(
				&TCP_Client_Connection::handle_socket_timeout,
				this,
				placeholders::error,
				(int) READ,
				timeout_
			)));
	}

	if ( is_ssl_ )
	{
		socket_->async_read_some(
			buffer(mb.wr_ptr(), mb.space()),
			make_custom_alloc_handler(allocator_,
			strand_.wrap(boost::bind(
				&TCP_Client_Connection::handle_read,
				this,
				placeholders::error,
				placeholders::bytes_transferred
			))));
	}
	else
	{
		socket().async_read_some(
			buffer(mb.wr_ptr(), mb.space()),
			make_custom_alloc_handler(allocator_,
			strand_.wrap(boost::bind(
				&TCP_Client_Connection::handle_read,
				this,
				placeholders::error,
				placeholders::bytes_transferred
			))));
	}
}
开发者ID:ancrux,项目名称:cpp-ex,代码行数:43,代码来源:TCP_Client_Connection.cpp

示例9: PostRecv

void ProactorService::PostRecv()
{
	ACE_Message_Block* pBlock;

	ACE_NEW_NORETURN(pBlock, ACE_Message_Block (2048));
	if(this->m_AsyncReader.read(*pBlock, pBlock->space()) != 0)
	{
		pBlock->release();
		ReserveClose();
	}
}
开发者ID:codemaru,项目名称:CGSF,代码行数:11,代码来源:ProactorService.cpp

示例10: open

int
HTTP_Client_Session::on_open(ACE_Message_Block& mb_open)
{
	ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t) AIO_Session open(this: %@)\n"), this));//@

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

	int n = 0;
	n = ACE_OS::snprintf(mb->wr_ptr(), mb->space(), HTTP::Header::_Request_, "GET", "/no_content.htm", 1.0); mb->wr_ptr(n);
	//n = ACE_OS::snprintf(mb->wr_ptr(), mb->space(), HTTP::Header::Connection, "keep-alive"); mb->wr_ptr(n);
	//n = ACE_OS::snprintf(mb->wr_ptr(), mb->space(), HTTP::Header::Host, "localhost"); mb->wr_ptr(n);
	n = ACE_OS::snprintf(mb->wr_ptr(), mb->space(), HTTP::Header::_End_); mb->wr_ptr(n);

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

	if ( write(*mb) != 0 ) return -1;

	return 0;
}
开发者ID:ancrux,项目名称:cpp-ex,代码行数:20,代码来源:HTTP_Session.cpp

示例11:

void
SBRS_Server_Connection::read(ACE_Message_Block& mb, long timeout)
{
	ACE_GUARD(ACE_Thread_Mutex, guard, lock_);

	socket_.async_read_some(buffer(mb.wr_ptr(), mb.space()), strand_.wrap(boost::bind(
		&SBRS_Server_Connection::handle_read,
		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)));
	}
}
开发者ID:ancrux,项目名称:cpp-ex,代码行数:20,代码来源:SBRS_Server_Connection.cpp

示例12:

int
PConnection::initiate_read_stream (void)
{
    if (this->get_ref_cnt_r() != 0)
        return 0;

    ACE_Message_Block * mb = this->alloc_msg();

    if (mb == 0)
        return -1;

    // Inititiate read
    if (this->start_asynch_read(*mb, mb->space()) == -1)
    {
        this->free_msg(mb);
        this->cancel();
        return -1;
    }

    this->ref_cnt_r_++;
    this->total_r_++;
    return 0;
}
开发者ID:binghuo365,项目名称:BaseLab,代码行数:23,代码来源:PConnection.cpp

示例13: open

void Reciever::open (ACE_HANDLE h, ACE_Message_Block&)  
{  
	//ACE_DEBUG LOG here,print ip,port,establish time

	//client_address.addr_to_string(peer_name, sizeof(peer_name) / sizeof(ACE_TCHAR));
	//ACE_DEBUG((LM_DEBUG, "%s", "\nOne User has established a connection.\n"));
	//ACE_DEBUG((LM_DEBUG,ACE_TEXT("IP Address:%s \n"),peer_name));
	ACE_OS::printf("One User has established a connection.\n");
	ACE_OS::printf("Current time:%s",this->curTime());

	//get remote ip and port
	/*ACE_INET_Addr addr;
	ACE_SOCK_SEQPACK_Association ass = ACE_SOCK_SEQPACK_Association(h); 
	size_t addr_size = 1; 
	ass.get_local_addrs(&addr,addr_size);*/

    this->handle(h);
    if (this->reader_.open(*this) != 0 )  
        {  
            delete this;  
            return;  
        }  
        if (this->writer_.open(*this) != 0 )  
        {  
            delete this;  
            return;  
		}

        ACE_Message_Block *mb = new ACE_Message_Block(buffer,MAX_MSG_LEN);  
        if (this->reader_.read (*mb, mb->space()) != 0)  
        {  
            //ACE_OS::printf("Begin read failed!\n");  
            delete this;  
            return;
        }
        return;  
}  
开发者ID:wudippda,项目名称:ACE_Server,代码行数:37,代码来源:Reciever.cpp

示例14: handle_input

int TCPConnectionHandler::handle_input (ACE_HANDLE handle)
{
  ACE_UNUSED_ARG (handle);
  ACE_Message_Block *buffer = new ACE_Message_Block (TCPBytesToSend);
  int bytesReceived = peer_.recv (buffer->wr_ptr (), buffer->space ());

  if (bytesReceived > 0)
    {
      totalReceived_ += bytesReceived;
      if (serverSide_ || --pingsNo_ > 0) // echo received buffer
        {
          buffer->wr_ptr (bytesReceived);
          int result = scheduleSend (buffer);
          if (0 > result)
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT (" (%P) %p\n"),
                               ACE_TEXT ("Cannot schedule TCP reply")),
                              -1);
        }
      else
        buffer->release ();

      return 0;
    }

  if (errno != EWOULDBLOCK)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P:%p (%d)\n"),
                       ACE_TEXT ("TCPConnectionHandler::handle_input call with no data on handle "), handle),
                      -1);

  ACE_ERROR ((LM_WARNING,
              ACE_TEXT (" (%P:%p (%d)\n"),
              ACE_TEXT ("TCPConnectionHandler::handle_input call with no data on handle "), handle));

  return 0;
}
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:37,代码来源:QtReactor_Test.cpp

示例15: svc

  virtual int svc () {
    const size_t FileReadSize = 8 * 1024;
    ACE_Message_Block mblk (FileReadSize);

    for (;; mblk.crunch ()) {
      // Read as much as will fit in the message block.
      ssize_t bytes_read = logfile_.recv (mblk.wr_ptr (),
                                          mblk.space ());
      if (bytes_read <= 0)
        break;
      mblk.wr_ptr (static_cast<size_t> (bytes_read));

      // We have a bunch of data from the log file. The data is
      // arranged like so:
      //    hostname\0
      //    CDR-encoded log record
      // So, first we scan for the end of the host name, then
      // initialize another ACE_Message_Block aligned for CDR
      // demarshaling and copy the remainder of the block into it. We
      // can't use duplicate() because we need to be sure the data
      // pointer is aligned properly for CDR demarshaling.  If at any
      // point, there's not enough data left in the message block to
      // extract what's needed, crunch the block to move all remaining
      // data to the beginning and read more from the file.
      for (;;) {
        size_t name_len = ACE_OS::strnlen
                             (mblk.rd_ptr (), mblk.length ());
        if (name_len == mblk.length ()) break;

        char *name_p = mblk.rd_ptr ();
        ACE_Message_Block *rec, *head, *temp;
        ACE_NEW_RETURN
          (head, ACE_Message_Block (name_len, MB_CLIENT), 0);
        head->copy (name_p, name_len);
        mblk.rd_ptr (name_len + 1);   // Skip nul also

        size_t need = mblk.length () + ACE_CDR::MAX_ALIGNMENT;
        ACE_NEW_RETURN (rec, ACE_Message_Block (need), 0);
        ACE_CDR::mb_align (rec);
        rec->copy (mblk.rd_ptr (), mblk.length ());

        // Now rec contains the remaining data we've read so far from
        // the file. Create an ACE_InputCDR to start demarshaling the
        // log record, header first to find the length, then the data.
        // Since the ACE_InputCDR constructor increases the reference count
        // on rec, we release it upon return to prevent leaks.
        // The cdr 'read' methods return 0 on failure, 1 on success.
        ACE_InputCDR cdr (rec); rec->release ();
        ACE_CDR::Boolean byte_order;
        if (!cdr.read_boolean (byte_order)) {
          head->release (); rec->release (); break;
        }
        cdr.reset_byte_order (byte_order);

        // Now read the length of the record. From there, we'll know
        // if rec contains the complete record or not.
        ACE_CDR::ULong length;
        if (!cdr.read_ulong (length)) {
          head->release (); mblk.rd_ptr (name_p); break;
        }
        if (length > cdr.length ()) {
          head->release (); mblk.rd_ptr (name_p); break;
        }

        // The complete record is in rec... grab all the fields into
        // separate, chained message blocks.
        ACE_NEW_RETURN (temp,
                        ACE_Message_Block (length, MB_TEXT),
                        0);
        ACE_NEW_RETURN
          (temp,
           ACE_Message_Block (2 * sizeof (ACE_CDR::Long),
                              MB_TIME, temp),
           0);
        ACE_NEW_RETURN
          (temp,
           ACE_Message_Block (sizeof (ACE_CDR::Long),
                              MB_PID, temp),
           0);
        ACE_NEW_RETURN
          (temp,
           ACE_Message_Block (sizeof (ACE_CDR::Long),
                              MB_TYPE, temp),
           0);
        head->cont (temp);

        // Extract the type
        ACE_CDR::Long *lp;
        lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ());
        cdr >> *lp;
        temp->wr_ptr (sizeof (ACE_CDR::Long));
        temp = temp->cont ();

        // Extract the pid
        lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ());
        cdr >> *lp;
        temp->wr_ptr (sizeof (ACE_CDR::Long));
        temp = temp->cont ();

        // Extract the timestamp (2 Longs)
//.........这里部分代码省略.........
开发者ID:CCJY,项目名称:ACE,代码行数:101,代码来源:display_logfile.cpp


注:本文中的ACE_Message_Block::space方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。