/
5-16.C
55 lines (52 loc) · 1.33 KB
/
5-16.C
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
/* Copyright (c) 1992 by AT&T Bell Laboratories. */
/* Advanced C++ Programming Styles and Idioms */
/* James O. Coplien */
/* All rights reserved. */
#include <stddef.h>
#include <memory.h>
class LAPD {
friend class LAPDMemoryManager;
friend class Conn;
public:
virtual int size() { return 0; }
void *operator new(size_t);
void operator delete(void *);
LAPD(char *const);
protected:
LAPD() { /* no-op */ }
private:
int:8;
union {
struct {
unsigned char flag;
unsigned int sapi:6;
unsigned int commandResponse:1;
unsigned int zero:1;
unsigned int tei:7;
unsigned int ext:1;
unsigned char control;
} header;
struct {
LAPD *linkf, *linkb;
unsigned short size;
} minfo;
};
unsigned char tag; // minfo system allocated tag
int performCRCCheck() { /* . . . */ return 0; }
};
class Conn: public LAPD {
friend LAPD;
private:
struct ConnPacketBody {
unsigned char rep[4096];
} *body;
int bodySize;
int size() { return sizeof(Conn) + bodySize; }
Conn(const char *m): LAPD() {
// . . . .
::memcpy(bodyStorage, m+sizeof(header), bodySize);
body = (ConnPacketBody*) bodyStorage;
manager.allocateResizeBlock( size() );
}
char bodyStorage[1];
};