summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/FtRtEvent/EventChannel/ConnectionHandler_T.cpp
blob: 71c6ee1169ed49be31a365f8ba98d099bf78ee04 (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
// $Id$

template <ACE_PEER_STREAM_1>
int ConnectionAcceptHandler<ACE_PEER_STREAM_2>::open (void * acceptor)
{

  ACE_TRACE("ConnectionAcceptHandler::open\n");
  ACE_INET_Addr addr;

  if (this->peer ().get_remote_addr (addr) == -1)
    return -1;

  reactor_ = static_cast<ACE_Service_Object*>(acceptor)->reactor();

  if (reactor_->register_handler (this,
    ACE_Event_Handler::READ_MASK) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
    "(%P|%t) can't register with reactor\n"),
    -1);

  ACE_DEBUG ((LM_DEBUG,
    "(%P|%t) connected with %s\n",
    addr.get_host_name ()));

  return 0;
}

template <ACE_PEER_STREAM_1>
void ConnectionAcceptHandler<ACE_PEER_STREAM_2>::destroy (void)
{
  // Remove ourselves from the reactor
  reactor_->remove_handler
    (this,
    ACE_Event_Handler::READ_MASK | ACE_Event_Handler::DONT_CALL);

  // Shut down the connection to the client.
  this->peer ().close ();

  // Free our memory.
  delete this;
}

// If somebody doesn't like us, they will close() us.  Actually, if
//  our open() method returns -1, the Acceptor<> will invoke close()
//  on us for cleanup.
template <ACE_PEER_STREAM_1>
int ConnectionAcceptHandler<ACE_PEER_STREAM_2>::close (u_long flags)
{
  ACE_UNUSED_ARG (flags);

  this->destroy ();
  return 0;
}


template <ACE_PEER_STREAM_1>
int ConnectionAcceptHandler<ACE_PEER_STREAM_2>::handle_input (ACE_HANDLE)
{
  char buf[8];
  if (this->peer().recv(buf, sizeof(buf)))
    return -1;
  return 0;
}

// Clean ourselves up when handle_input() (or handle_timer()) returns -1

template <ACE_PEER_STREAM_1>
int ConnectionAcceptHandler<ACE_PEER_STREAM_2>::handle_close (ACE_HANDLE,
                                                        ACE_Reactor_Mask)
{
  this->destroy ();
  return 0;
}


template <ACE_PEER_STREAM_1>
int ConnectionDetectHandler<ACE_PEER_STREAM_2>::handle_close (ACE_HANDLE,
                                                        ACE_Reactor_Mask)
{
  ACE_TRACE("ConnectionDetectHandler::handle_close\n");
  close();
  return 0;
}

template <ACE_PEER_STREAM_1>
int ConnectionDetectHandler<ACE_PEER_STREAM_2>::close (u_long )
{
  if (listener_)
    listener_->connection_closed();
  delete this;
  return 0;
}