File: ReadHandler.h

package info (click to toggle)
ace 6.0.3%2Bdfsg-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 49,368 kB
  • sloc: cpp: 341,826; perl: 30,850; ansic: 20,952; makefile: 10,144; sh: 4,744; python: 828; exp: 787; yacc: 511; xml: 330; lex: 158; lisp: 116; csh: 48; tcl: 5
file content (92 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download | duplicates (2)
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
/*
 * ACE reactor demonstration
 *
 * $Id: ReadHandler.h 80826 2008-03-04 14:51:23Z wotte $
 * Date: 26-Jan-2006
 */

#ifndef __READHANDLER_H__
#define __READHANDLER_H__

#include <ace/Event_Handler.h>
#include <ace/SOCK_Stream.h>

/**
 * This read handler is created by the accept handler and handles all the data
 * exchange between client and server. The client makes two requests to the
 * server. The first asks the server to create a buffer which will hold the
 * data sent in the second call.
 */
class ReadHandler : public ACE_Event_Handler {

    private:

        /**
         * The stream socket used for data exchange.
         */
        ACE_SOCK_Stream mStream;

        /**
         * The size of the data array.
         */
        int mDataSize;

        /**
         * The array containing the client's data.
         */
        char *mData;

        /**
         * The call counter to distinguish between first and second call.
         */
        int mCallCounter;

        /**
         * Count the numer of invocations of handle_*(). According to the
         * docs, there should be only one invocation at any given time.
         */
        int mInvocationCounter;

    public:

        /**
         * Initialization.
         */
        ReadHandler(void);

        /**
         * Clean up data.
         */
        virtual ~ReadHandler();

        /**
         * Provide access to the internal stream socket.
         */
        ACE_SOCK_Stream &getStream(void);

        /**
         * @name Overridden methods from the ACE_Event_Handler
         */
        // @{

        /**
         * Provides the handle of mStream;
         */
        virtual ACE_HANDLE get_handle(void) const;

        /**
         * Handles the data excahnge between client and server. On the first
         * invocation, mData is allocated to the requested size and on the
         * second invocation, that buffer is filled with the client's data.
         */
        virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE);

        /**
         * Deletes this instance of the read handler.
         */
        virtual int handle_close(ACE_HANDLE, ACE_Reactor_Mask);
        // @}
};

#endif /* __READHANDLER_H__ */