summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorBruce Momjian2004-04-12 16:19:18 +0000
committerBruce Momjian2004-04-12 16:19:18 +0000
commita4c40f140d23cefbf94e00283f7688c772867f1b (patch)
treefb739f6389594f9a21b3e31c0791c9fa093da5a7 /src/include
parentabdabeb99571a093af5b063c045a65d1c1b09038 (diff)
Here's an attempt at new socket and signal code for win32.
It works on the principle of turning sockets into non-blocking, and then emulate blocking behaviour on top of that, while allowing signals to run. Signals are now implemented using an event instead of APCs, thus getting rid of the issue of APCs not being compatible with "old style" sockets functions. It also moves the win32 specific code away from pqsignal.h/c into port/win32, and also removes the "thread style workaround" of the APC issue previously in place. In order to make things work, a few things are also changed in pgstat.c: 1) There is now a separate pipe to the collector and the bufferer. This is required because the pipe will otherwise only be signalled in one of the processes when the postmaster goes down. The MS winsock code for select() must have some kind of workaround for this behaviour, but I have found no stable way of doing that. You really are not supposed to use the same socket from more than one process (unless you use WSADuplicateSocket(), in which case the docs specifically say that only one will be flagged). 2) The check for "postmaster death" is moved into a separate select() call after the main loop. The previous behaviour select():ed on the postmaster pipe, while later explicitly saying "we do NOT check for postmaster exit inside the loop". The issue was that the code relies on the same select() call seeing both the postmaster pipe *and* the pgstat pipe go away. This does not always happen, and it appears that useing WSAEventSelect() makes it even more common that it does not. Since it's only called when the process exits, I don't think using a separate select() call will have any significant impact on how the stats collector works. Magnus Hagander
Diffstat (limited to 'src/include')
-rw-r--r--src/include/libpq/pqsignal.h22
-rw-r--r--src/include/miscadmin.h5
-rw-r--r--src/include/port/win32.h47
3 files changed, 47 insertions, 27 deletions
diff --git a/src/include/libpq/pqsignal.h b/src/include/libpq/pqsignal.h
index 5ebf52bb0d..8ca5135303 100644
--- a/src/include/libpq/pqsignal.h
+++ b/src/include/libpq/pqsignal.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/libpq/pqsignal.h,v 1.25 2004/02/08 22:28:57 neilc Exp $
+ * $PostgreSQL: pgsql/src/include/libpq/pqsignal.h,v 1.26 2004/04/12 16:19:18 momjian Exp $
*
* NOTES
* This shouldn't be in libpq, but the monitor and some other
@@ -18,9 +18,7 @@
#ifndef PQSIGNAL_H
#define PQSIGNAL_H
-#ifndef WIN32
#include <signal.h>
-#endif
#ifdef HAVE_SIGPROCMASK
extern sigset_t UnBlockSig,
@@ -46,23 +44,5 @@ typedef void (*pqsigfunc) (int);
extern void pqinitmask(void);
extern pqsigfunc pqsignal(int signo, pqsigfunc func);
-extern void pg_queue_signal(int signum);
-
-#ifdef WIN32
-#define sigmask(sig) ( 1 << (sig-1) )
-
-void pgwin32_signal_initialize(void);
-extern HANDLE pgwin32_main_thread_handle;
-#define PG_POLL_SIGNALS() WaitForSingleObjectEx(pgwin32_main_thread_handle,0,TRUE);
-
-/* Signal function return values */
-#undef SIG_DFL
-#undef SIG_ERR
-#undef SIG_IGN
-#define SIG_DFL ((pqsigfunc)0)
-#define SIG_ERR ((pqsigfunc)-1)
-#define SIG_IGN ((pqsigfunc)1)
-
-#endif
#endif /* PQSIGNAL_H */
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 4aba00bb71..76f2d086ae 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.155 2004/03/24 22:40:29 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.156 2004/04/12 16:19:18 momjian Exp $
*
* NOTES
* some of the information in this file should be moved to
@@ -83,7 +83,8 @@ do { \
#else
#define CHECK_FOR_INTERRUPTS() \
do { \
- WaitForSingleObjectEx(GetCurrentThread(),0,TRUE); \
+ if (WaitForSingleObject(pgwin32_signal_event,0) == WAIT_OBJECT_0) \
+ pgwin32_dispatch_queued_signals(); \
if (InterruptPending) \
ProcessInterrupts(); \
} while(0)
diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index f2519681c2..d1e55725b9 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.20 2004/03/02 18:35:59 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.21 2004/04/12 16:19:18 momjian Exp $ */
/* undefine and redefine after #include */
#undef mkdir
@@ -98,15 +98,49 @@ int semctl(int semId, int semNum, int flag, union semun);
int semget(int semKey, int semNum, int flags);
int semop(int semId, struct sembuf * sops, int flag);
-#define sleep(sec) (Sleep(sec * 1000), /* no return value */ 0)
+/* In backend/port/win32/signal.c */
+void pgwin32_signal_initialize(void);
+extern DLLIMPORT HANDLE pgwin32_signal_event;
+void pgwin32_dispatch_queued_signals(void);
+void pg_queue_signal(int signum);
+
+#define sigmask(sig) ( 1 << (sig-1) )
+
+/* Signal function return values */
+#undef SIG_DFL
+#undef SIG_ERR
+#undef SIG_IGN
+#define SIG_DFL ((pqsigfunc)0)
+#define SIG_ERR ((pqsigfunc)-1)
+#define SIG_IGN ((pqsigfunc)1)
#ifndef FRONTEND
-/* In libpq/pqsignal.c */
#define kill(pid,sig) pqkill(pid,sig)
-int pqkill(int pid, int sig);
+extern int pqkill(int pid, int sig);
+
+#define pg_usleep(t) pgwin32_backend_usleep(t)
+void pgwin32_backend_usleep(long microsec);
#endif
+/* In backend/port/win32/socket.c */
+#ifndef FRONTEND
+#define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
+#define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
+#define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
+#define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
+#define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
+#define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
+
+SOCKET pgwin32_socket(int af, int type, int protocol);
+SOCKET pgwin32_accept(SOCKET s, struct sockaddr* addr, int* addrlen);
+int pgwin32_connect(SOCKET s, const struct sockaddr* name, int namelen);
+int pgwin32_select(int nfds, fd_set* readfs, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout);
+int pgwin32_recv(SOCKET s, char* buf, int len, int flags);
+int pgwin32_send(SOCKET s, char* buf, int len, int flags);
+#endif
+
+
/* Some extra signals */
#define SIGHUP 1
#define SIGQUIT 3
@@ -179,3 +213,8 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ECONNRESET WSAECONNRESET
#define EINPROGRESS WSAEINPROGRESS
+#define ENOBUFS WSAENOBUFS
+#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
+#define ECONNREFUSED WSAECONNREFUSED
+#define EBADFD WSAENOTSOCK
+#define EOPNOTSUPP WSAEOPNOTSUPP