2004-04-22 05:51:24 +02:00
|
|
|
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.23 2004/04/22 03:51:24 momjian Exp $ */
|
2003-05-15 18:35:30 +02:00
|
|
|
|
|
|
|
/* undefine and redefine after #include */
|
|
|
|
#undef mkdir
|
|
|
|
|
|
|
|
#undef ERROR
|
|
|
|
#include <windows.h>
|
2004-02-08 23:28:57 +01:00
|
|
|
#include <winsock.h>
|
2004-04-19 19:42:59 +02:00
|
|
|
#include <process.h>
|
2003-05-15 18:35:30 +02:00
|
|
|
#undef near
|
|
|
|
|
|
|
|
/* Must be here to avoid conflicting with prototype in windows.h */
|
|
|
|
#define mkdir(a,b) mkdir(a)
|
|
|
|
|
2003-04-18 03:03:42 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define USES_WINSOCK
|
2002-01-22 20:02:40 +01:00
|
|
|
|
|
|
|
/* defines for dynamic linking on Win32 platform */
|
2004-01-26 23:59:54 +01:00
|
|
|
#if defined(__CYGWIN__) || defined(__MINGW32__)
|
2002-01-22 20:02:40 +01:00
|
|
|
|
|
|
|
#if __GNUC__ && ! defined (__declspec)
|
|
|
|
#error You need egcs 1.1 or newer for compiling!
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BUILDING_DLL
|
|
|
|
#define DLLIMPORT __declspec (dllexport)
|
|
|
|
#else /* not BUILDING_DLL */
|
|
|
|
#define DLLIMPORT __declspec (dllimport)
|
|
|
|
#endif
|
|
|
|
|
2004-03-02 19:35:59 +01:00
|
|
|
#elif defined(WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__)) /* not CYGWIN or MingW */
|
2002-01-22 20:02:40 +01:00
|
|
|
|
|
|
|
#if defined(_DLL)
|
|
|
|
#define DLLIMPORT __declspec (dllexport)
|
|
|
|
#else /* not _DLL */
|
|
|
|
#define DLLIMPORT __declspec (dllimport)
|
|
|
|
#endif
|
|
|
|
|
2004-01-26 23:59:54 +01:00
|
|
|
#else /* not CYGWIN, not MSVC, not MingW */
|
2002-01-22 20:02:40 +01:00
|
|
|
|
|
|
|
#define DLLIMPORT
|
|
|
|
#endif
|
2003-04-18 03:03:42 +02:00
|
|
|
|
2003-04-24 23:23:01 +02:00
|
|
|
/*
|
|
|
|
* IPC defines
|
|
|
|
*/
|
2003-05-15 18:35:30 +02:00
|
|
|
#undef HAVE_UNION_SEMUN
|
|
|
|
#define HAVE_UNION_SEMUN 1
|
|
|
|
|
2003-04-24 23:23:01 +02:00
|
|
|
#define IPC_RMID 256
|
|
|
|
#define IPC_CREAT 512
|
|
|
|
#define IPC_EXCL 1024
|
|
|
|
#define IPC_PRIVATE 234564
|
|
|
|
#define IPC_NOWAIT 2048
|
|
|
|
#define IPC_STAT 4096
|
|
|
|
|
2003-05-15 18:35:30 +02:00
|
|
|
#define EACCESS 2048
|
|
|
|
#define EIDRM 4096
|
|
|
|
|
|
|
|
#define SETALL 8192
|
|
|
|
#define GETNCNT 16384
|
|
|
|
#define GETVAL 65536
|
|
|
|
#define SETVAL 131072
|
|
|
|
#define GETPID 262144
|
2003-04-24 23:23:01 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Shared memory
|
|
|
|
*/
|
|
|
|
struct shmid_ds
|
|
|
|
{
|
2003-08-04 02:43:34 +02:00
|
|
|
int dummy;
|
|
|
|
int shm_nattch;
|
2003-04-24 23:23:01 +02:00
|
|
|
};
|
|
|
|
|
2003-08-04 02:43:34 +02:00
|
|
|
int shmdt(const void *shmaddr);
|
|
|
|
void *shmat(int memId, void *shmaddr, int flag);
|
|
|
|
int shmctl(int shmid, int flag, struct shmid_ds * dummy);
|
|
|
|
int shmget(int memKey, int size, int flag);
|
2003-04-24 23:23:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Semaphores
|
|
|
|
*/
|
|
|
|
union semun
|
|
|
|
{
|
2003-08-04 02:43:34 +02:00
|
|
|
int val;
|
2003-04-24 23:23:01 +02:00
|
|
|
struct semid_ds *buf;
|
|
|
|
unsigned short *array;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sembuf
|
|
|
|
{
|
2003-08-04 02:43:34 +02:00
|
|
|
int sem_flg;
|
|
|
|
int sem_op;
|
|
|
|
int sem_num;
|
2003-04-24 23:23:01 +02:00
|
|
|
};
|
|
|
|
|
2003-08-04 02:43:34 +02:00
|
|
|
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);
|
2003-04-24 23:23:01 +02:00
|
|
|
|
2003-05-15 18:35:30 +02:00
|
|
|
|
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
2004-04-12 18:19:18 +02:00
|
|
|
/* 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)
|
2004-02-08 23:28:57 +01:00
|
|
|
|
|
|
|
#ifndef FRONTEND
|
|
|
|
#define kill(pid,sig) pqkill(pid,sig)
|
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
2004-04-12 18:19:18 +02:00
|
|
|
extern int pqkill(int pid, int sig);
|
|
|
|
|
|
|
|
#define pg_usleep(t) pgwin32_backend_usleep(t)
|
|
|
|
void pgwin32_backend_usleep(long microsec);
|
2004-02-08 23:28:57 +01:00
|
|
|
#endif
|
|
|
|
|
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
2004-04-12 18:19:18 +02:00
|
|
|
/* 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);
|
2004-04-22 05:51:24 +02:00
|
|
|
|
|
|
|
const char *pgwin32_socket_strerror(int err);
|
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
2004-04-12 18:19:18 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-05-15 18:35:30 +02:00
|
|
|
/* Some extra signals */
|
|
|
|
#define SIGHUP 1
|
2003-08-04 02:43:34 +02:00
|
|
|
#define SIGQUIT 3
|
|
|
|
#define SIGTRAP 5
|
|
|
|
#define SIGABRT 22 /* Set to match W32 value -- not UNIX
|
|
|
|
* value */
|
|
|
|
#define SIGKILL 9
|
|
|
|
#define SIGPIPE 13
|
|
|
|
#define SIGALRM 14
|
|
|
|
#define SIGSTOP 17
|
|
|
|
#define SIGCONT 19
|
|
|
|
#define SIGCHLD 20
|
|
|
|
#define SIGTTIN 21
|
|
|
|
#define SIGTTOU 22 /* Same as SIGABRT -- no problem, I hope */
|
|
|
|
#define SIGWINCH 28
|
|
|
|
#define SIGUSR1 30
|
|
|
|
#define SIGUSR2 31
|
2003-05-15 18:35:30 +02:00
|
|
|
|
|
|
|
struct timezone
|
|
|
|
{
|
2003-08-04 02:43:34 +02:00
|
|
|
int tz_minuteswest; /* Minutes west of GMT. */
|
|
|
|
int tz_dsttime; /* Nonzero if DST is ever in effect. */
|
2003-05-15 18:35:30 +02:00
|
|
|
};
|
2003-04-24 23:23:01 +02:00
|
|
|
|
2004-02-18 17:25:12 +01:00
|
|
|
/* for setitimer in backend/port/win32/timer.c */
|
|
|
|
#define ITIMER_REAL 0
|
|
|
|
struct itimerval {
|
|
|
|
struct timeval it_interval;
|
|
|
|
struct timeval it_value;
|
|
|
|
};
|
|
|
|
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
|
|
|
|
|
|
|
|
|
2003-04-24 23:23:01 +02:00
|
|
|
/* FROM SRA */
|
|
|
|
|
2003-04-18 03:03:42 +02:00
|
|
|
/*
|
|
|
|
* Supplement to <sys/types.h>.
|
|
|
|
*/
|
|
|
|
#define uid_t int
|
|
|
|
#define gid_t int
|
|
|
|
#define pid_t unsigned long
|
|
|
|
#define ssize_t int
|
|
|
|
#define mode_t int
|
|
|
|
#define key_t long
|
|
|
|
#define ushort unsigned short
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Supplement to <sys/stat.h>.
|
|
|
|
*/
|
|
|
|
#define lstat slat
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Supplement to <errno.h>.
|
|
|
|
*/
|
|
|
|
#include <errno.h>
|
|
|
|
#undef EAGAIN
|
|
|
|
#undef EINTR
|
|
|
|
#define EINTR WSAEINTR
|
|
|
|
#define EAGAIN WSAEWOULDBLOCK
|
|
|
|
#define EMSGSIZE WSAEMSGSIZE
|
|
|
|
#define EAFNOSUPPORT WSAEAFNOSUPPORT
|
|
|
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
|
|
|
#define ECONNRESET WSAECONNRESET
|
|
|
|
#define EINPROGRESS WSAEINPROGRESS
|
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
2004-04-12 18:19:18 +02:00
|
|
|
#define ENOBUFS WSAENOBUFS
|
|
|
|
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
|
|
|
|
#define ECONNREFUSED WSAECONNREFUSED
|
|
|
|
#define EBADFD WSAENOTSOCK
|
|
|
|
#define EOPNOTSUPP WSAEOPNOTSUPP
|