summaryrefslogtreecommitdiff
path: root/ACE/protocols/ace/HTBP/HTBP_Notifier.cpp
blob: f9096ce13e954c20aafd517c932321856f57736b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* -*- C++ -*- */

//=============================================================================
/**
 *  @file    HTBP_Notifier.cpp
 *
 *  @author Phil Mesnier, Priyanka Gontla
 */
//=============================================================================
#include "HTBP_Notifier.h"

#include "ace/Reactor.h"
#include "ace/Synch.h"

#include "HTBP_Channel.h"
#include "HTBP_Session.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

ACE::HTBP::Notifier::Notifier (ACE::HTBP::Channel *s)
  : channel_(s)
{
}

int
ACE::HTBP::Notifier::handle_input(ACE_HANDLE )
{
  switch (this->channel_->state())
    {
    case ACE::HTBP::Channel::Detached:
      this->channel_->pre_recv();
      break;
    case ACE::HTBP::Channel::Wait_For_Ack:
      this->channel_->recv_ack();
      break;
    default:
      this->channel_->load_buffer();
    }

  if (this->channel_->state() == ACE::HTBP::Channel::Closed)
    {
      this->unregister();
      return 0;
    }

  if (this->channel_->session_)
    {
      if (this->channel_ == this->channel_->session_->inbound())
        {
          ACE_Event_Handler *h = this->channel_->session_->handler();
          if (h && this->reactor())
            this->reactor()->notify(h,
                                    ACE_Event_Handler::READ_MASK);
          else
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("(%P|%t) ACE::HTBP::Notifier::handle_input ")
                        ACE_TEXT ("Notifier cannot notify, session has no ")
                        ACE_TEXT ("handler (%x), or reactor (%x)\n"),
                        h,this->reactor()));
        }
      else
        this->channel_->flush_buffer();
    }
  else
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("(%P|%t) ACE::HTBP::Notifier::handle_input ")
                ACE_TEXT ("Notifier has no session to notify!\n")));
  return 0;
}

int
ACE::HTBP::Notifier::handle_output (ACE_HANDLE )
{
  return -1;

}

void
ACE::HTBP::Notifier::unregister (void)
{
  if (this->reactor())
    this->reactor()->remove_handler(this,
                                    ACE_Event_Handler::READ_MASK |
                                    ACE_Event_Handler::DONT_CALL);
}

ACE_HANDLE
ACE::HTBP::Notifier::get_handle(void) const
{
  return this->channel_->ace_stream().get_handle();
}

ACE_END_VERSIONED_NAMESPACE_DECL