blob: a27937fa1339eaeedb58381324cb0e691c257204 (
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
|
/**
* $Id$
*
* Home Automation Status server. Sample code from The ACE Programmer's Guide,
* copyright 2003 Addison-Wesley. All Rights Reserved.
*/
#ifndef __HASTATUS_H_
#define __HASTATUS_H_
#include "ace/OS.h"
#include "ace/Acceptor.h"
#include "ace/INET_Addr.h"
#include "ace/SOCK_Stream.h"
#include "ace/SOCK_Acceptor.h"
#include "ace/Service_Object.h"
#include "ace/Svc_Handler.h"
#include "HASTATUS_export.h"
// Listing 10
class ClientHandler :
public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
public:
typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> super;
ClientHandler()
: super()
{
// Exclude 10
ACE_DEBUG(( LM_INFO,
"ClientHandler ctor\n"
));
// Exclude 10
}
// Listing 10
~ClientHandler()
{
ACE_DEBUG(( LM_INFO,
"ClientHandler dtor\n"
));
}
// Listing 13
int handle_input (ACE_HANDLE)
{
char buf[64];
int bytesReceived;
if( (bytesReceived =
this->peer_.recv( buf, sizeof(buf)-1 )) < 1 )
{
ACE_DEBUG(( LM_INFO,
"ClientHandler handle_input: "
"Received %d bytes. Leaving.\n",
bytesReceived
));
return -1;
}
buf[bytesReceived] = 0;
ACE_DEBUG(( LM_INFO,
"ClientHandler handle_input: %s\n",
buf
));
return 0;
}
};
// Listing 13
class HASTATUS_Export HA_Status : public ACE_Service_Object
{
public:
virtual int init (int argc, ACE_TCHAR *argv[]);
private:
ACE_Acceptor<ClientHandler, ACE_SOCK_ACCEPTOR> acceptor_;
ACE_INET_Addr listen_addr_;
};
#endif /* __HASTATUS_H_ */
|