/* [<][>][^][v][top][bottom][index][help] */
1 /****************************************************************************
2 * Copyright (C) 2006-2008 by Jason Ansel, Kapil Arya, Gene Cooperman, *
3 * and Rohan Garg *
4 * jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu, and *
5 * rohgarg@ccs.neu.edu *
6 * *
7 * This file is part of the dmtcp/src module of DMTCP (DMTCP:dmtcp/src). *
8 * *
9 * DMTCP:dmtcp/src is free software: you can redistribute it and/or *
10 * modify it under the terms of the GNU Lesser General Public License as *
11 * published by the Free Software Foundation, either version 3 of the *
12 * License, or (at your option) any later version. *
13 * *
14 * DMTCP:dmtcp/src is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU Lesser General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU Lesser General Public *
20 * License along with DMTCP:dmtcp/src. If not, see *
21 * <http://www.gnu.org/licenses/>. *
22 ****************************************************************************/
23
24 #pragma once
25 #ifndef CONNECTION_H
26 #define CONNECTION_H
27
28 // THESE INCLUDES ARE IN RANDOM ORDER. LET'S CLEAN IT UP AFTER RELEASE. - Gene
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <sys/types.h>
32 #include <unistd.h>
33 #include "config.h"
34 #include "dmtcpalloc.h"
35 #include "jserialize.h"
36 #include "jalloc.h"
37 #include "connectionidentifier.h"
38
39 namespace dmtcp
40 {
41
42 class Connection
43 {
44 public:
45 #ifdef JALIB_ALLOCATOR
46 static void* operator new(size_t nbytes, void* p) { return p; }
47 static void* operator new(size_t nbytes) { JALLOC_HELPER_NEW(nbytes); }
48 static void operator delete(void* p) { JALLOC_HELPER_DELETE(p); }
49 #endif
50 enum ConnectionType
51 {
52 INVALID = 0x00000,
53 TCP = 0x10000,
54 RAW = 0x11000,
55 PTY = 0x20000,
56 FILE = 0x21000,
57 STDIO = 0x22000,
58 FIFO = 0x24000,
59 EPOLL = 0x30000,
60 EVENTFD = 0x31000,
61 SIGNALFD = 0x32000,
62 INOTIFY = 0x34000,
63 POSIXMQ = 0x40000,
64 TYPEMASK = TCP | RAW | PTY | FILE | STDIO | FIFO | EPOLL | EVENTFD |
65 SIGNALFD | INOTIFY | POSIXMQ
66 };
67
68 Connection() {}
69 virtual ~Connection() {}
70
71 void addFd(int fd);
72 void removeFd(int fd);
73 uint32_t numFds() const { return _fds.size(); }
74 const vector<int32_t>& getFds() const { return _fds; }
75 uint32_t conType() const { return _type & TYPEMASK; }
76 uint32_t subType() const { return _type; }
77 bool hasLock() { return _hasLock; }
78 bool isStdio() { return conType() == STDIO; }
79
80 void checkLocking();
81 const ConnectionIdentifier& id() const { return _id; }
82
83 virtual void saveOptions();
84 virtual void doLocking();
85 virtual void drain() = 0;
86 virtual void preCkpt() {}
87 virtual void refill(bool isRestart) = 0;
88 virtual void resume(bool isRestart) {};
89 virtual void postRestart() = 0;
90 virtual bool isPreExistingCTTY() const { return false; }
91
92 virtual void restoreOptions();
93
94 virtual string str() = 0;
95
96 void serialize(jalib::JBinarySerializer& o);
97 protected:
98 virtual void serializeSubClass(jalib::JBinarySerializer& o) = 0;
99 protected:
100 //only child classes can construct us...
101 Connection(uint32_t t);
102 protected:
103 ConnectionIdentifier _id;
104 uint32_t _type;
105 int64_t _fcntlFlags;
106 int64_t _fcntlOwner;
107 int64_t _fcntlSignal;
108 bool _hasLock;
109 vector<int32_t> _fds;
110 };
111 }
112
113 #endif