summaryrefslogtreecommitdiff
path: root/docs/tutorials/015/Handler.h
blob: 73aa2573b0cc214b491ee817e5470f478e6107fb (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

// $Id$

#ifndef HANDLER_H
#define HANDLER_H

#include "ace/Svc_Handler.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/SOCK_Stream.h"
#include "Protocol_Stream.h"

/* Just your basic event handler.  We use ACE_Svc_Handler<> as a
   baseclass so that it can maintain the peer() and other details for
   us.  We're not going to activate() this object, so we can get away
   with the NULL synch choice.
*/
class Handler : public ACE_Svc_Handler < ACE_SOCK_STREAM, ACE_NULL_SYNCH >
{
public:

    Handler(void);
    ~Handler(void);

        // Called by the acceptor when we're created in response to a
        // client connection.
    int open (void *);

        // Called when it's time for us to be deleted.  We take care
        // of removing ourselves from the reactor and shutting down
        // the peer() connectin.
    void destroy (void);

        // Called when it's time for us to go away.  There are subtle
        // differences between destroy() and close() so don't try to
        // use either for all cases.
    int close (u_long);

protected:

        // Respond to peer() activity.
    int handle_input (ACE_HANDLE);

        // This will be called when handle_input() returns a failure
        // code.  That's our signal that it's time to begin the
        // shutdown process.
    int handle_close(ACE_HANDLE, ACE_Reactor_Mask _mask);

private:

        // Like the Client, we have to abide by the protocol
        // requirements.  We use a local Protocol_Stream object to
        // take care of those details.  For us, I/O then just becomes
        // a matter of interacting with the stream.
    Protocol_Stream stream_;

    Protocol_Stream & stream(void)
        {
            return this->stream_;
        }
};

#endif //  HANDLER_H