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

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

?? peer.cpp

?? ACE編程的一本經典BIBLE的源代碼,喜歡網絡編程的別錯過
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// Peer.cpp,v 4.48 2004/09/11 11:42:24 jwillemsen Exp

#define ACE_BUILD_SVC_DLL

#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_unistd.h"
#include "ace/Signal.h"
#include "Peer.h"

ACE_RCSID(Peer, Peer, "Peer.cpp,v 4.48 2004/09/11 11:42:24 jwillemsen 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,
              ACE_TEXT ("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,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("open")),
                      -1);

  if (this->peer ().enable (ACE_NONBLOCK) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("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,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("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,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("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,
                    ACE_TEXT ("%p\n"),
                    ACE_TEXT ("gateway is flow controlled, so we're dropping events")));
      else
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%p\n"),
                    ACE_TEXT ("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,
                      ACE_TEXT ("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,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("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,
              ACE_TEXT ("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,
                  ACE_TEXT ("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,
                           ACE_TEXT ("%p\n"),
                           ACE_TEXT ("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,
                           ACE_TEXT ("%p\n"),
                           ACE_TEXT ("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,
              ACE_TEXT ("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,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("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,
                          ACE_TEXT ("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,
                            ACE_TEXT ("%p\n"),
                            ACE_TEXT ("cancel_wakeup")));
            }
        }
      return 0;
    }
  else
    // If the list is empty there's a bug!
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("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,
              ACE_TEXT ("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,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("Recv error during header read")));
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("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,
                      ACE_TEXT ("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,
                      ACE_TEXT ("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_;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99热精品国产| 亚洲精品免费一二三区| 美女网站色91| 日韩免费电影网站| 国产精品亚洲人在线观看| 欧美精品一区二区三区蜜臀| 日本va欧美va精品发布| 精品国精品国产| 成人一区二区三区在线观看 | 欧美亚男人的天堂| 亚洲人成网站在线| 精品视频在线视频| 美女国产一区二区| 日本一二三四高清不卡| 日本高清成人免费播放| 三级在线观看一区二区| 2021中文字幕一区亚洲| 波多野结衣在线aⅴ中文字幕不卡| 亚洲欧洲国产日本综合| 欧美视频日韩视频在线观看| 六月婷婷色综合| 国产精品免费视频观看| 欧美日韩你懂的| 国产精品一二三| 一区二区三区资源| 日韩精品一区二区三区swag | 日韩成人一级大片| 久久亚洲精精品中文字幕早川悠里| 成熟亚洲日本毛茸茸凸凹| 亚洲最大成人网4388xx| 日韩精品一区二区三区视频播放| www.日本不卡| 久久99久久久欧美国产| 日韩理论片网站| 精品国产免费一区二区三区四区| 99re亚洲国产精品| 免费的成人av| 亚洲午夜在线视频| 亚洲国产成人私人影院tom| 欧美男生操女生| aaa国产一区| 国产一区二区在线看| 亚洲亚洲精品在线观看| 国产精品视频线看| 欧美v国产在线一区二区三区| 色呦呦国产精品| 成人一区在线观看| 久久99精品国产.久久久久久 | 欧美军同video69gay| 福利电影一区二区三区| 麻豆精品在线看| 午夜精品福利在线| 亚洲激情自拍视频| 国产精品久久午夜夜伦鲁鲁| 日韩欧美亚洲国产另类| 欧美日韩国产综合一区二区三区| 欧美精品一区二区高清在线观看| 日本黄色一区二区| 94-欧美-setu| 成人av网站大全| 国产成人鲁色资源国产91色综| 蜜桃久久av一区| 香蕉成人啪国产精品视频综合网| 亚洲码国产岛国毛片在线| 亚洲国产经典视频| 日本一区二区三区在线观看| 精品国产伦一区二区三区免费| 欧美日本免费一区二区三区| 一本大道av伊人久久综合| www.一区二区| www.日本不卡| 99精品视频在线播放观看| 成人激情午夜影院| 成人一区二区三区视频在线观看| 国产综合久久久久久鬼色| 久热成人在线视频| 久久不见久久见免费视频1 | 久久电影网站中文字幕 | 麻豆91精品91久久久的内涵| 婷婷成人综合网| 五月婷婷综合网| 日韩成人一级片| 国内精品久久久久影院色| 国产精品一区二区无线| 国产伦精品一区二区三区在线观看| 91天堂素人约啪| 91丨九色porny丨蝌蚪| 色综合激情五月| 欧美日韩情趣电影| 欧美一区二区三区在线电影 | 久久综合色8888| 欧美—级在线免费片| 亚洲视频在线观看一区| 亚洲精品亚洲人成人网| 丝袜美腿亚洲一区| 国内精品嫩模私拍在线| 成人黄色av网站在线| 91国产免费观看| 日韩午夜电影av| 精品国产乱码久久久久久久久| 久久九九久久九九| 亚洲免费在线电影| 日韩av一区二区三区| 国产精品99久久久久久有的能看| 99久久国产综合精品女不卡| 欧美系列一区二区| 2023国产精品自拍| 亚洲精品菠萝久久久久久久| 日韩av一区二| 岛国av在线一区| 91精品国产欧美日韩| 欧美激情一区二区三区在线| 亚洲一区二区三区四区在线观看 | 欧美系列一区二区| 久久综合国产精品| 亚洲一二三四在线| 国内精品国产三级国产a久久| 色老头久久综合| 欧美变态凌虐bdsm| 亚洲精品成人在线| 国产精品羞羞答答xxdd| 欧美日韩中文一区| 中文无字幕一区二区三区| 亚洲超碰97人人做人人爱| 国产91精品精华液一区二区三区 | 精品国产成人在线影院| 日韩美女久久久| 国产伦精品一区二区三区免费迷| 91美女片黄在线观看| 久久久欧美精品sm网站 | 精品一区中文字幕| 欧美性受xxxx黑人xyx性爽| 久久婷婷成人综合色| 亚洲午夜电影在线| 国产aⅴ综合色| 欧美色图一区二区三区| 亚洲国产综合视频在线观看| 国产在线视视频有精品| 欧美日韩一区小说| 欧美激情在线一区二区| 日韩精品国产欧美| av高清不卡在线| 久久精品水蜜桃av综合天堂| 日韩电影在线看| 欧美色精品在线视频| 中文字幕欧美三区| 国产精品一区2区| 日韩欧美一区在线观看| 日韩综合小视频| 色视频成人在线观看免| 国产精品久久久久久妇女6080| 另类小说一区二区三区| 欧美一区二区日韩一区二区| 亚洲国产裸拍裸体视频在线观看乱了| 成人午夜av影视| 国产亚洲综合色| 精品在线一区二区| 久久综合久久综合久久综合| 欧美aaaaa成人免费观看视频| 欧美性三三影院| 亚洲国产毛片aaaaa无费看| 91福利在线看| 亚洲va欧美va人人爽午夜| 欧美这里有精品| 亚洲一级片在线观看| 欧美性淫爽ww久久久久无| 亚洲国产一二三| 欧美日韩精品是欧美日韩精品| 一区二区三区国产豹纹内裤在线| 91在线无精精品入口| 中文字幕日本不卡| 91老师片黄在线观看| 亚洲理论在线观看| 欧美亚一区二区| 日韩电影在线观看网站| 精品少妇一区二区三区日产乱码 | 国产精品成人在线观看| 93久久精品日日躁夜夜躁欧美| 亚洲品质自拍视频网站| 欧美性一二三区| 日韩av中文字幕一区二区| 精品日韩一区二区| 夫妻av一区二区| 亚洲一线二线三线久久久| 欧美视频一区二区在线观看| 日韩精品电影在线| 精品国产欧美一区二区| 不卡av免费在线观看| 亚洲免费观看在线视频| 欧美人与z0zoxxxx视频| 天堂蜜桃91精品| 久久久久国产精品免费免费搜索| 成人污视频在线观看| 亚洲乱码日产精品bd| 7777精品伊人久久久大香线蕉经典版下载 | 欧美精品一区二区精品网| 成人免费看黄yyy456| 有码一区二区三区| 欧美一区二区三区的| 国产成人综合在线观看|