亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? peer.cpp

?? 一個開源的網絡開發庫ACE
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// Peer.cpp,v 4.42 2002/07/09 15:14:52 shuston Exp

#define ACE_BUILD_SVC_DLL

#include "Peer.h"

ACE_RCSID(Peer, Peer, "Peer.cpp,v 4.42 2002/07/09 15:14:52 shuston Exp")

Peer_Handler::Peer_Handler (void)
  : connection_id_ (-1),  // Maybe it's better than 0.
    msg_frag_ (0),
    total_bytes_ (0)
{
  // Set the high water mark of the <ACE_Message_Queue>.  This is used
  // to exert flow control.
  this->msg_queue ()->high_water_mark (Options::instance ()->max_queue_size ());
  first_time_ = 1;  // It will be first time to open Peer_Handler.
}

// Upcall from the <ACE_Acceptor::handle_input> that turns control
// over to our application-specific Gateway handler.

int
Peer_Handler::open (void *a)
{
  ACE_DEBUG ((LM_DEBUG,
              "handle = %d\n",
              this->peer ().get_handle ()));

  // Call down to the base class to activate and register this handler
  // with an <ACE_Reactor>.
  if (this->inherited::open (a) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "open"),
                      -1);

  if (this->peer ().enable (ACE_NONBLOCK) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "enable"),
                      -1);

  ACE_Time_Value timeout (Options::instance ()->timeout ());

  // Schedule the time between disconnects.  This should really be a
  // "tunable" parameter.
  if (ACE_Reactor::instance ()->schedule_timer
      (this, 0, timeout) == -1)
    ACE_ERROR ((LM_ERROR,
                "%p\n",
                "schedule_timer"));

  // If there are events left in the queue, make sure we enable the
  // <ACE_Reactor> appropriately to get them sent out.
  if (this->msg_queue ()->is_empty () == 0
      && ACE_Reactor::instance ()->schedule_wakeup
          (this, ACE_Event_Handler::WRITE_MASK) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "schedule_wakeup"),
                      -1);

  // First action is to wait to be notified of our connection id.
  this->do_action_ = &Peer_Handler::await_connection_id;
  return 0;
}

int
Peer_Handler::transmit (ACE_Message_Block *mb,
                        size_t n,
                        int event_type)
{
  Event *event = (Event *) mb->rd_ptr ();

  // Initialize the header.
  new (&event->header_) Event_Header (n,
                                      this->connection_id_,
                                      event_type,
                                      0);

  // Convert all the fields into network byte order.
  event->header_.encode ();

  // Move the write pointer to the end of the event.
  mb->wr_ptr (sizeof (Event_Header) + n);

  if (this->put (mb) == -1)
    {
      if (errno == EWOULDBLOCK) // The queue has filled up!
        ACE_ERROR ((LM_ERROR,
                    "%p\n",
                    "gateway is flow controlled, so we're dropping events"));
      else
        ACE_ERROR ((LM_ERROR,
                    "%p\n",
                    "transmission failure in transmit()")); // Function name fixed.
      // Caller is responsible for freeing a ACE_Message_Block
      // if failures occur.
      mb->release ();
      return -1;
    }
  return 0;
}

// Read events from stdin and send them to the gatewayd.

int
Peer_Handler::transmit_stdin (void)
{
  // If return value is -1, then first_time_ must be reset to 1.
  int result = 0;
  if (this->connection_id_ != -1)
    {
      ACE_Message_Block *mb;

      ACE_NEW_RETURN (mb,
                      ACE_Message_Block (sizeof (Event)),
                      -1);

      // Cast the message block payload into an <Event> pointer.
      Event *event = (Event *) mb->rd_ptr ();

      ssize_t n = ACE_OS::read (ACE_STDIN,
                                event->data_,
                                sizeof event->data_);
      switch (n)
        {
        case 0:
          ACE_DEBUG ((LM_DEBUG,
                      "stdin closing down\n"));

          // Take stdin out of the ACE_Reactor so we stop trying to
          // send events.
          ACE_Reactor::instance ()->remove_handler
            (ACE_STDIN,
             ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::READ_MASK);
          mb->release ();
          result = 0; //
          break;
          /* NOTREACHED */
        case -1:
          mb->release ();
          ACE_ERROR ((LM_ERROR,
                      "%p\n",
                      "read"));
          result = 0; //
          break;
          /* NOTREACHED */
        default:
          // Do not return directly, save the return value.
          result = this->transmit (mb, n, ROUTING_EVENT);
          break;
          /* NOTREACHED */
        }

      // Do not return at here, but at exit of function.
      /*return 0;*/
    }
  else
  {
  ACE_DEBUG ((LM_DEBUG,
              "Must transmit over an opened channel.\n"));
    result = -1; // Save return value at here, return at exit of function.
  }
  // If transmit error, the stdin-thread will be cancelled, so should
  // reset first_time_ to 1, which will register_stdin_handler again.
  if (result == -1)
    first_time_ = 1;

  return result;
}

// Perform a non-blocking <put> of event MB.  If we are unable to send
// the entire event the remainder is re-queue'd at the *front* of the
// Message_Queue.

int
Peer_Handler::nonblk_put (ACE_Message_Block *mb)
{
  // Try to send the event.  If we don't send it all (e.g., due to
  // flow control), then re-queue the remainder at the head of the
  // <ACE_Message_Queue> and ask the <ACE_Reactor> to inform us (via
  // <handle_output>) when it is possible to try again.

  ssize_t n = this->send (mb);

  if (n == -1)
    // -1 is returned only when things have really gone wrong (i.e.,
    // not when flow control occurs).
    return -1;
  else if (errno == EWOULDBLOCK)
    {
      // We didn't manage to send everything, so requeue.
      ACE_DEBUG ((LM_DEBUG,
                  "queueing activated on handle %d to connection id %d\n",
                 this->get_handle (),
                  this->connection_id_));

      // Re-queue in *front* of the list to preserve order.
      if (this->msg_queue ()->enqueue_head
          (mb,
           (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "enqueue_head"),
                          -1);
      // Tell ACE_Reactor to call us back when we can send again.
      if (ACE_Reactor::instance ()->schedule_wakeup
          (this, ACE_Event_Handler::WRITE_MASK) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "schedule_wakeup"),
                          -1);
      return 0;
    }
  else 
    return n;
}

// Finish sending a event when flow control conditions abate.  This
// method is automatically called by the ACE_Reactor.

int
Peer_Handler::handle_output (ACE_HANDLE)
{
  ACE_Message_Block *mb = 0;

  ACE_DEBUG ((LM_DEBUG,
              "in handle_output\n"));

  if (this->msg_queue ()->dequeue_head
      (mb,
       (ACE_Time_Value *) &ACE_Time_Value::zero) != -1)
    {
      switch (this->nonblk_put (mb))
        {
        case 0:           // Partial send.
          ACE_ASSERT (errno == EWOULDBLOCK);
          // Didn't write everything this time, come back later...
          break;
          /* NOTREACHED */
        case -1:
          // Caller is responsible for freeing a ACE_Message_Block if
          // failures occur.
          mb->release ();
          ACE_ERROR ((LM_ERROR,
                      "%p\n",
                      "transmission failure in handle_output"));
          /* FALLTHROUGH */
        default: // Sent the whole thing.
          // If we succeed in writing the entire event (or we did not
          // fail due to EWOULDBLOCK) then check if there are more
          // events on the <ACE_Message_Queue>.  If there aren't, tell
          // the <ACE_Reactor> not to notify us anymore (at least
          // until there are new events queued up).

          if (this->msg_queue ()->is_empty ())
            {
              ACE_DEBUG ((LM_DEBUG,
                          "queue now empty on handle %d to connection id %d\n",
                          this->get_handle (),
                          this->connection_id_));

              if (ACE_Reactor::instance ()->cancel_wakeup
                  (this, ACE_Event_Handler::WRITE_MASK) == -1)
                ACE_ERROR ((LM_ERROR,
                            "%p\n",
                            "cancel_wakeup"));
            }
        }
      return 0;
    }
  else
    // If the list is empty there's a bug!
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "dequeue_head"),
                      0);
}

// Send an event to a peer (may block if necessary).

int
Peer_Handler::put (ACE_Message_Block *mb, ACE_Time_Value *)
{
  if (this->msg_queue ()->is_empty ())
    // Try to send the event *without* blocking!
    return this->nonblk_put (mb);
  else
    // If we have queued up events due to flow control then just
    // enqueue and return.
    return this->msg_queue ()->enqueue_tail
      (mb, (ACE_Time_Value *) &ACE_Time_Value::zero);
}

// Send an Peer event to gatewayd.

int
Peer_Handler::send (ACE_Message_Block *mb)
{
  size_t len = mb->length ();

  ssize_t n = this->peer ().send (mb->rd_ptr (), len);

  if (n <= 0)
    return errno == EWOULDBLOCK ? 0 : n;
  else if (n < (ssize_t) len)
    {
      // Re-adjust pointer to skip over the part we did send.
      mb->rd_ptr (n);
      this->total_bytes_ += n;
    }
  else // if (n == length).
    {
      // The whole event is sent, we can now safely deallocate the
      // buffer.  Note that this should decrement a reference count...
      this->total_bytes_ += n;
      mb->release ();
      errno = 0;
    }

  ACE_DEBUG ((LM_DEBUG,
              "sent %d bytes, total bytes sent = %d\n",
              n,
              this->total_bytes_));
  return n;
}

// Receive an Event from gatewayd.  Handles fragmentation.

int
Peer_Handler::recv (ACE_Message_Block *&mb)
{
  if (this->msg_frag_ == 0)
    // No existing fragment...
    ACE_NEW_RETURN (this->msg_frag_,
                    ACE_Message_Block (sizeof (Event)),
                    -1);

  Event *event = (Event *) this->msg_frag_->rd_ptr ();
  ssize_t header_received = 0;

  const size_t HEADER_SIZE = sizeof (Event_Header);
  ssize_t header_bytes_left_to_read =
    HEADER_SIZE - this->msg_frag_->length ();

  if (header_bytes_left_to_read > 0)
    {
      header_received = this->peer ().recv
        (this->msg_frag_->wr_ptr (),
         header_bytes_left_to_read);

      if (header_received == -1 /* error */
          || header_received == 0  /* EOF */)
        {
          ACE_ERROR ((LM_ERROR,
                      "%p\n",
                      "Recv error during header read"));
          ACE_DEBUG ((LM_DEBUG,
                      "attempted to read %d bytes\n",
                      header_bytes_left_to_read));
          this->msg_frag_ = this->msg_frag_->release ();
          return header_received;
        }

      // Bump the write pointer by the amount read.
      this->msg_frag_->wr_ptr (header_received);

      // At this point we may or may not have the ENTIRE header.
      if (this->msg_frag_->length () < HEADER_SIZE)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Partial header received: only %d bytes\n",
                     this->msg_frag_->length ()));
          // Notify the caller that we didn't get an entire event.
          errno = EWOULDBLOCK;
          return -1;
        }

      // Convert the header into host byte order so that we can access
      // it directly without having to repeatedly muck with it...
      event->header_.decode ();

      if (event->header_.len_ > ACE_INT32 (sizeof event->data_))
        {
          // This data_ payload is too big!
          errno = EINVAL;
          ACE_DEBUG ((LM_DEBUG,
                      "Data payload is too big (%d bytes)\n",
                      event->header_.len_));
          return -1;
        }
    }

  // At this point there is a complete, valid header in Event.  Now we
  // need to get the event payload.  Due to incomplete reads this may
  // not be the first time we've read in a fragment for this message.
  // We account for this here.  Note that the first time in here
  // <msg_frag_->wr_ptr> will point to <event->data_>.  Every time we
  // do a successful fragment read, we advance <wr_ptr>.  Therefore,
  // by subtracting how much we've already read from the
  // <event->header_.len_> we complete the
  // <data_bytes_left_to_read>...

  ssize_t data_bytes_left_to_read =
    ssize_t (event->header_.len_ - (msg_frag_->wr_ptr () - event->data_));

  // peer().recv() should not be called when data_bytes_left_to_read is 0.
  ssize_t data_received = !data_bytes_left_to_read ? 0 :
    this->peer ().recv (this->msg_frag_->wr_ptr (),
                        data_bytes_left_to_read);

  // Try to receive the remainder of the event.

  switch (data_received)
    {
    case -1:
      if (errno == EWOULDBLOCK)
        // This might happen if only the header came through.
        return -1;
      else
        /* FALLTHROUGH */;

    case 0: // Premature EOF.
      if (data_bytes_left_to_read)
      {
      this->msg_frag_ = this->msg_frag_->release ();
      return 0;
      }
      /* FALLTHROUGH */;

    default:
      // Set the write pointer at 1 past the end of the event.
      this->msg_frag_->wr_ptr (data_received);

      if (data_received != data_bytes_left_to_read)
        {
          errno = EWOULDBLOCK;
          // Inform caller that we didn't get the whole event.
          return -1;
        }
      else
        {
          // Set the read pointer to the beginning of the event.
          this->msg_frag_->rd_ptr (this->msg_frag_->base ());

          mb = this->msg_frag_;

          // Reset the pointer to indicate we've got an entire event.
          this->msg_frag_ = 0;
        }

      ACE_DEBUG ((LM_DEBUG,
                  "(%t) connection id = %d, cur len = %d, total bytes read = %d\n",

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久综合999| 久久综合一区二区| 91精品国产乱码| 国产精品日韩成人| 青青草97国产精品免费观看| 99精品视频在线观看免费| 欧美成人精品二区三区99精品| 18成人在线观看| 国产在线精品免费av| 欧美日韩视频在线一区二区 | 日韩经典一区二区| 国产精品资源网| 日韩久久久久久| 亚洲成人在线观看视频| 色一区在线观看| 国产精品进线69影院| 国产美女娇喘av呻吟久久| 欧美一区二区在线看| 亚洲va韩国va欧美va| 色欧美片视频在线观看| 中文字幕亚洲一区二区av在线| 蜜桃传媒麻豆第一区在线观看| 色视频欧美一区二区三区| 国产精品情趣视频| 成人综合在线观看| 国产欧美一区二区精品久导航| 美国av一区二区| 欧美一区二区三区精品| 日韩成人精品在线| 6080国产精品一区二区| 亚洲va欧美va国产va天堂影院| 欧美自拍偷拍午夜视频| 亚洲精品日韩专区silk| 91丨九色丨国产丨porny| 国产精品久久久久久久久图文区| 国产精品伊人色| 国产欧美中文在线| 成人av资源网站| 亚洲精品乱码久久久久久| 一本高清dvd不卡在线观看| 日韩毛片精品高清免费| 91精品1区2区| 首页国产欧美日韩丝袜| 51精品久久久久久久蜜臀| 日韩不卡在线观看日韩不卡视频| 欧美一区二区三区的| 黄色小说综合网站| 国产欧美日韩中文久久| 在线看一区二区| 午夜精品久久久久久久久久久| 欧美日韩精品一区二区三区| 日本va欧美va精品| 国产欧美日韩中文久久| 91久久精品网| av电影天堂一区二区在线观看| 国产不卡在线一区| 成人午夜短视频| 欧美三级中文字| 精品欧美乱码久久久久久| 国产精品网站一区| 伊人性伊人情综合网| 午夜av电影一区| 国产一区二区看久久| 91视频.com| 久久综合网色—综合色88| 国产精品每日更新在线播放网址| 亚洲免费观看高清| 精品综合免费视频观看| 波多野结衣一区二区三区 | 欧美精品三级在线观看| 国产不卡视频在线观看| www久久久久| 亚洲女爱视频在线| 自拍av一区二区三区| 综合网在线视频| 日本不卡的三区四区五区| 欧美一二三四在线| 欧美日韩国产小视频| 欧美视频三区在线播放| 中文字幕欧美区| 欧美视频中文字幕| 成人午夜在线播放| 亚洲.国产.中文慕字在线| 久久精品人人做人人爽人人| 欧美性高清videossexo| 激情六月婷婷久久| 亚洲午夜国产一区99re久久| 中文字幕亚洲精品在线观看| 国产一区二区成人久久免费影院| 欧美日韩一级片在线观看| 亚洲美女偷拍久久| 在线亚洲高清视频| 中文字幕不卡的av| 风间由美中文字幕在线看视频国产欧美| 91传媒视频在线播放| 亚洲欧美日韩中文播放| 欧美肥胖老妇做爰| 久久亚洲精品小早川怜子| 国产精品无圣光一区二区| 日韩欧美另类在线| 欧美四级电影在线观看| 91浏览器打开| 成人国产免费视频| 国产黄色91视频| 国产成人小视频| 国产盗摄精品一区二区三区在线| 久久精品国产久精国产| 日韩电影在线免费看| 午夜欧美2019年伦理| 一区二区三区不卡在线观看| 亚洲人成小说网站色在线| 国产精品传媒在线| 久久精品日产第一区二区三区高清版| 精品人在线二区三区| 在线不卡的av| 日韩亚洲欧美一区| 精品免费视频.| ww亚洲ww在线观看国产| 久久久天堂av| 欧美韩国一区二区| 国产精品无圣光一区二区| 中文字幕一区二区三区乱码在线| 国产亚洲一区二区在线观看| 久久蜜桃香蕉精品一区二区三区| 精品理论电影在线| 久久久亚洲精品石原莉奈| 久久精品一区二区三区四区| 中文字幕一区免费在线观看| 中文字幕一区二区三区在线不卡 | 国产精品久久久久久久久晋中| 精品国产区一区| 亚洲国产成人自拍| 亚洲一区二区三区自拍| 88在线观看91蜜桃国自产| 欧美精品国产精品| 日韩一卡二卡三卡四卡| 欧美变态tickle挠乳网站| 精品国产免费久久| 亚洲国产成人一区二区三区| 亚洲乱码一区二区三区在线观看| 亚洲午夜免费电影| 成人av电影观看| 另类欧美日韩国产在线| 国产大陆a不卡| 国产成人在线视频免费播放| 国产河南妇女毛片精品久久久| 国产呦萝稀缺另类资源| 国产精品白丝jk黑袜喷水| 欧美三级欧美一级| 国产精品综合一区二区三区| 欧美日韩激情一区二区| 欧美tk丨vk视频| 亚洲免费观看在线视频| 亚洲黄网站在线观看| 日本不卡高清视频| 9l国产精品久久久久麻豆| 91亚洲男人天堂| 日韩一区二区三区在线观看| 欧美一卡在线观看| 日本一区二区三区在线不卡| 亚洲成av人综合在线观看| 国产综合色视频| 99视频一区二区| 欧美精品一区二区在线播放| 免费日本视频一区| 99精品久久只有精品| 洋洋av久久久久久久一区| 日韩免费福利电影在线观看| 国内成人自拍视频| 国产精品久久久久9999吃药| 欧美日本一区二区三区四区| 美腿丝袜亚洲三区| 蜜桃免费网站一区二区三区| 激情五月婷婷综合| 欧美一区二区在线免费观看| 夜夜精品浪潮av一区二区三区| 国产一区二区三区免费观看| 日本欧美加勒比视频| 免费在线观看精品| 日日欢夜夜爽一区| 欧美一区二区福利视频| 国产精品乱子久久久久| 日本亚洲最大的色成网站www| 欧美日韩国产首页在线观看| 国产精品每日更新| 久久精品国产精品亚洲红杏| 欧美日韩一区二区三区视频| 欧美mv日韩mv国产网站app| 亚洲麻豆国产自偷在线| 波多野结衣在线aⅴ中文字幕不卡| 欧美精品国产精品| 午夜精品久久久久| 久久精品国产免费看久久精品| 久久97超碰色| 九九**精品视频免费播放| 久久色中文字幕| 在线免费亚洲电影| 亚洲电影在线播放| 欧美日韩精品三区| 午夜激情综合网|