PostgreSQL Source Code: src/fe_utils/cancel.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

18

20

24

25

26

27

28

29

30

31#define write_stderr(str) \

32 do { \

33 const char *str_ = (str); \

34 int rc_; \

35 rc_ = write(fileno(stderr), str_, strlen(str_)); \

36 (void) rc_; \

37 } while (0)

38

39

40

41

42

44

45

46

47

48

51

52

53

54

55

56

57

58

60

61#ifdef WIN32

62static CRITICAL_SECTION cancelConnLock;

63#endif

64

65

66

67

69

70

71

72

73

74

75

76void

78{

80

81#ifdef WIN32

82 EnterCriticalSection(&cancelConnLock);

83#endif

84

85

87

88

90

91 if (oldCancelConn != NULL)

93

95

96#ifdef WIN32

97 LeaveCriticalSection(&cancelConnLock);

98#endif

99}

100

101

102

103

104

105

106void

108{

110

111#ifdef WIN32

112 EnterCriticalSection(&cancelConnLock);

113#endif

114

116

117

119

120 if (oldCancelConn != NULL)

122

123#ifdef WIN32

124 LeaveCriticalSection(&cancelConnLock);

125#endif

126}

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144#ifndef WIN32

145

146

147

148

149

150

151

152static void

154{

155 char errbuf[256];

156

158

161

162

164 {

166 {

168 }

169 else

170 {

173 }

174 }

175}

176

177

178

179

180

181

182void

184{

188

190}

191

192#else

193

194static BOOL WINAPI

195consoleHandler(DWORD dwCtrlType)

196{

197 char errbuf[256];

198

199 if (dwCtrlType == CTRL_C_EVENT ||

200 dwCtrlType == CTRL_BREAK_EVENT)

201 {

203

206

207

208 EnterCriticalSection(&cancelConnLock);

210 {

212 {

214 }

215 else

216 {

219 }

220 }

221

222 LeaveCriticalSection(&cancelConnLock);

223

224 return TRUE;

225 }

226 else

227

228 return FALSE;

229}

230

231void

233{

237

238 InitializeCriticalSection(&cancelConnLock);

239

240 SetConsoleCtrlHandler(consoleHandler, TRUE);

241}

242

243#endif

volatile sig_atomic_t CancelRequested

static void(* cancel_callback)(void)

void ResetCancelConn(void)

static const char * cancel_sent_msg

void SetCancelConn(PGconn *conn)

static PGcancel *volatile cancelConn

#define write_stderr(str)

static const char * cancel_not_sent_msg

void setup_cancel_handler(void(*query_cancel_callback)(void))

static void handle_sigint(SIGNAL_ARGS)

PGcancel * PQgetCancel(PGconn *conn)

int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)

void PQfreeCancel(PGcancel *cancel)

static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)