diff -cr postgresql-snapshot-030325/src/backend/libpq/pqsignal.c postgresql-newsignal/src/backend/libpq/pqsignal.c *** postgresql-snapshot-030325/src/backend/libpq/pqsignal.c Wed Feb 18 17:25:12 2004 --- postgresql-newsignal/src/backend/libpq/pqsignal.c Fri Apr 2 20:21:26 2004 *************** *** 38,46 **** * is to do signal-handler reinstallation, which doesn't work well * at all. * ------------------------------------------------------------------------*/ - #ifdef WIN32 - #define _WIN32_WINNT 0x0400 - #endif #include "postgres.h" --- 38,43 ---- *************** *** 131,137 **** --- 128,136 ---- } + /* Win32 signal handling is in backend/port/win32/signal.c */ #ifndef WIN32 + /* * Set up a signal handler */ *************** *** 154,443 **** return oact.sa_handler; #endif /* !HAVE_POSIX_SIGNALS */ } ! ! ! #else ! ! ! /* Win32 specific signals code */ ! ! /* pg_signal_crit_sec is used to protect only pg_signal_queue. That is the only ! * variable that can be accessed from the signal sending threads! */ ! static CRITICAL_SECTION pg_signal_crit_sec; ! static int pg_signal_queue; ! ! #define PG_SIGNAL_COUNT 32 ! static pqsigfunc pg_signal_array[PG_SIGNAL_COUNT]; ! static pqsigfunc pg_signal_defaults[PG_SIGNAL_COUNT]; ! static int pg_signal_mask; ! ! HANDLE pgwin32_main_thread_handle; ! ! /* Signal handling thread function */ ! static DWORD WINAPI pg_signal_thread(LPVOID param); ! static BOOL WINAPI pg_console_handler(DWORD dwCtrlType); ! ! /* Initialization */ ! void ! pgwin32_signal_initialize(void) ! { ! int i; ! HANDLE signal_thread_handle; ! ! InitializeCriticalSection(&pg_signal_crit_sec); ! ! for (i = 0; i < PG_SIGNAL_COUNT; i++) ! { ! pg_signal_array[i] = SIG_DFL; ! pg_signal_defaults[i] = SIG_IGN; ! } ! pg_signal_mask = 0; ! pg_signal_queue = 0; ! ! /* Get handle to main thread so we can post calls to it later */ ! if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), ! GetCurrentProcess(), &pgwin32_main_thread_handle, ! 0, FALSE, DUPLICATE_SAME_ACCESS)) ! ereport(FATAL, ! (errmsg_internal("Failed to get main thread handle!"))); ! ! /* Create thread for handling signals */ ! signal_thread_handle = CreateThread(NULL, 0, pg_signal_thread, NULL, 0, NULL); ! if (signal_thread_handle == NULL) ! ereport(FATAL, ! (errmsg_internal("Failed to create signal handler thread!"))); ! ! if (!SetConsoleCtrlHandler(pg_console_handler, TRUE)) ! ereport(FATAL, ! (errmsg_internal("Failed to set console control handler!"))); ! } ! ! ! /* Dispatch all signals currently queued and not blocked ! * Blocked signals are ignored, and will be fired at the time of ! * the sigsetmask() call. */ ! static void ! dispatch_queued_signals(void) ! { ! int i; ! ! EnterCriticalSection(&pg_signal_crit_sec); ! while (pg_signal_queue & ~pg_signal_mask) ! { ! /* One or more unblocked signals queued for execution */ ! ! int exec_mask = pg_signal_queue & ~pg_signal_mask; ! ! for (i = 0; i < PG_SIGNAL_COUNT; i++) ! { ! if (exec_mask & sigmask(i)) ! { ! /* Execute this signal */ ! pqsigfunc sig = pg_signal_array[i]; ! ! if (sig == SIG_DFL) ! sig = pg_signal_defaults[i]; ! pg_signal_queue &= ~sigmask(i); ! if (sig != SIG_ERR && sig != SIG_IGN && sig != SIG_DFL) ! { ! LeaveCriticalSection(&pg_signal_crit_sec); ! sig(i); ! EnterCriticalSection(&pg_signal_crit_sec); ! break; /* Restart outer loop, in case signal mask ! * or queue has been modified inside ! * signal handler */ ! } ! } ! } ! } ! LeaveCriticalSection(&pg_signal_crit_sec); ! } ! ! /* signal masking. Only called on main thread, no sync required */ ! int ! pqsigsetmask(int mask) ! { ! int prevmask; ! ! prevmask = pg_signal_mask; ! pg_signal_mask = mask; ! ! /* ! * Dispatch any signals queued up right away, in case we have ! * unblocked one or more signals previously queued ! */ ! dispatch_queued_signals(); ! ! return prevmask; ! } ! ! ! /* signal manipulation. Only called on main thread, no sync required */ ! pqsigfunc ! pqsignal(int signum, pqsigfunc handler) ! { ! pqsigfunc prevfunc; ! ! if (signum >= PG_SIGNAL_COUNT || signum < 0) ! return SIG_ERR; ! prevfunc = pg_signal_array[signum]; ! pg_signal_array[signum] = handler; ! return prevfunc; ! } ! ! /* signal sending */ ! int ! pqkill(int pid, int sig) ! { ! char pipename[128]; ! BYTE sigData = sig; ! BYTE sigRet = 0; ! DWORD bytes; ! ! if (sig >= PG_SIGNAL_COUNT || sig <= 0) ! { ! errno = EINVAL; ! return -1; ! } ! if (pid <= 0) ! { ! /* No support for process groups */ ! errno = EINVAL; ! return -1; ! } ! wsprintf(pipename, "\\\\.\\pipe\\pgsignal_%i", pid); ! if (!CallNamedPipe(pipename, &sigData, 1, &sigRet, 1, &bytes, 1000)) ! { ! if (GetLastError() == ERROR_FILE_NOT_FOUND) ! errno = ESRCH; ! else if (GetLastError() == ERROR_ACCESS_DENIED) ! errno = EPERM; ! else ! errno = EINVAL; ! return -1; ! } ! if (bytes != 1 || sigRet != sig) ! { ! errno = ESRCH; ! return -1; ! } ! ! return 0; ! } ! ! /* APC callback scheduled on main thread when signals are fired */ ! static void CALLBACK ! pg_signal_apc(ULONG_PTR param) ! { ! dispatch_queued_signals(); ! } ! ! /* ! * All functions below execute on the signal handler thread ! * and must be synchronized as such! ! * NOTE! The only global variable that can be used is ! * pg_signal_queue! ! */ ! ! ! void ! pg_queue_signal(int signum) ! { ! if (signum >= PG_SIGNAL_COUNT || signum < 0) ! return; ! ! EnterCriticalSection(&pg_signal_crit_sec); ! pg_signal_queue |= sigmask(signum); ! LeaveCriticalSection(&pg_signal_crit_sec); ! ! QueueUserAPC(pg_signal_apc, pgwin32_main_thread_handle, (ULONG_PTR) NULL); ! } ! ! /* Signal dispatching thread */ ! static DWORD WINAPI ! pg_signal_dispatch_thread(LPVOID param) ! { ! HANDLE pipe = (HANDLE) param; ! BYTE sigNum; ! DWORD bytes; ! ! if (!ReadFile(pipe, &sigNum, 1, &bytes, NULL)) ! { ! /* Client died before sending */ ! CloseHandle(pipe); ! return 0; ! } ! if (bytes != 1) ! { ! /* Received bytes over signal pipe (should be 1) */ ! CloseHandle(pipe); ! return 0; ! } ! WriteFile(pipe, &sigNum, 1, &bytes, NULL); /* Don't care if it works ! * or not.. */ ! FlushFileBuffers(pipe); ! DisconnectNamedPipe(pipe); ! CloseHandle(pipe); ! ! pg_queue_signal(sigNum); ! return 0; ! } ! ! /* Signal handling thread */ ! static DWORD WINAPI ! pg_signal_thread(LPVOID param) ! { ! char pipename[128]; ! HANDLE pipe = INVALID_HANDLE_VALUE; ! ! wsprintf(pipename, "\\\\.\\pipe\\pgsignal_%i", GetCurrentProcessId()); ! ! for (;;) ! { ! BOOL fConnected; ! HANDLE hThread; ! ! pipe = CreateNamedPipe(pipename, PIPE_ACCESS_DUPLEX, ! PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, ! PIPE_UNLIMITED_INSTANCES, 16, 16, 1000, NULL); ! if (pipe == INVALID_HANDLE_VALUE) ! { ! fprintf(stderr, gettext("Failed to create signal listener pipe: %i. Retrying.\n"), (int) GetLastError()); ! SleepEx(500, TRUE); ! continue; ! } ! ! fConnected = ConnectNamedPipe(pipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); ! if (fConnected) ! { ! hThread = CreateThread(NULL, 0, ! (LPTHREAD_START_ROUTINE) pg_signal_dispatch_thread, ! (LPVOID) pipe, 0, NULL); ! if (hThread == INVALID_HANDLE_VALUE) ! fprintf(stderr, gettext("Failed to create signal dispatch thread: %i\n"), (int) GetLastError()); ! else ! CloseHandle(hThread); ! } ! else ! /* Connection failed. Cleanup and try again */ ! CloseHandle(pipe); ! } ! return 0; ! } ! ! ! /* Console control handler will execute on a thread created ! by the OS at the time of invocation */ ! static BOOL WINAPI pg_console_handler(DWORD dwCtrlType) { ! if (dwCtrlType == CTRL_C_EVENT || ! dwCtrlType == CTRL_BREAK_EVENT || ! dwCtrlType == CTRL_CLOSE_EVENT || ! dwCtrlType == CTRL_SHUTDOWN_EVENT) { ! pg_queue_signal(SIGINT); ! return TRUE; ! } ! return FALSE; ! } ! ! ! #endif --- 153,156 ---- return oact.sa_handler; #endif /* !HAVE_POSIX_SIGNALS */ } ! #endif /* WIN32 */ diff -cr postgresql-snapshot-030325/src/backend/port/win32/Makefile postgresql-newsignal/src/backend/port/win32/Makefile *** postgresql-snapshot-030325/src/backend/port/win32/Makefile Wed Feb 18 17:25:12 2004 --- postgresql-newsignal/src/backend/port/win32/Makefile Fri Apr 2 20:12:12 2004 *************** *** 12,18 **** top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global ! OBJS = sema.o shmem.o timer.o all: SUBSYS.o --- 12,18 ---- top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global ! OBJS = sema.o shmem.o timer.o socket.o signal.o all: SUBSYS.o diff -cr postgresql-snapshot-030325/src/backend/port/win32/sema.c postgresql-newsignal/src/backend/port/win32/sema.c *** postgresql-snapshot-030325/src/backend/port/win32/sema.c Thu Feb 12 21:37:34 2004 --- postgresql-newsignal/src/backend/port/win32/sema.c Tue Mar 30 22:02:47 2004 *************** *** 228,244 **** if (sops[0].sem_op == -1) { DWORD ret; ! if (sops[0].sem_flg & IPC_NOWAIT) ! ret = WaitForSingleObject(cur_handle, 0); ! else ! ret = WaitForSingleObject(cur_handle, INFINITE); if (ret == WAIT_OBJECT_0) { /* We got it! */ sem_counts[sops[0].sem_num]--; return 0; } else if (ret == WAIT_TIMEOUT) /* Couldn't get it */ --- 228,251 ---- if (sops[0].sem_op == -1) { DWORD ret; + HANDLE wh[2]; ! wh[0] = cur_handle; ! wh[1] = pgwin32_signal_event; ! ! ret = WaitForMultipleObjects(2, wh, FALSE, (sops[0].sem_flg & IPC_NOWAIT)?0:INFINITE); if (ret == WAIT_OBJECT_0) { /* We got it! */ sem_counts[sops[0].sem_num]--; return 0; + } + else if (ret == WAIT_OBJECT_0+1) + { + /* Signal event is set - we have a signal to deliver */ + pgwin32_dispatch_queued_signals(); + errno = EINTR; } else if (ret == WAIT_TIMEOUT) /* Couldn't get it */ diff -cr postgresql-snapshot-030325/src/backend/postmaster/pgstat.c postgresql-newsignal/src/backend/postmaster/pgstat.c *** postgresql-snapshot-030325/src/backend/postmaster/pgstat.c Tue Mar 23 00:55:29 2004 --- postgresql-newsignal/src/backend/postmaster/pgstat.c Fri Apr 2 23:38:15 2004 *************** *** 83,88 **** --- 83,89 ---- static int pgStatPipe[2]; static struct sockaddr_storage pgStatAddr; static int pgStatPmPipe[2] = {-1, -1}; + static int pgStatCollectorPmPipe[2] = {-1, -1}; static int pgStatPid; static time_t last_pgstat_start_time; *************** *** 423,429 **** /* * Create the pipe that controls the statistics collector shutdown */ ! if (pgpipe(pgStatPmPipe) < 0) { ereport(LOG, (errcode_for_socket_access(), --- 424,430 ---- /* * Create the pipe that controls the statistics collector shutdown */ ! if (pgpipe(pgStatPmPipe) < 0 || pgpipe(pgStatCollectorPmPipe) < 0) { ereport(LOG, (errcode_for_socket_access(), *************** *** 464,472 **** pgstat_forkexec(STATS_PROCESS_TYPE procType) { pid_t pid; ! char *av[13]; int ac = 0, bufc = 0, i; ! char pgstatBuf[10][MAXPGPATH]; av[ac++] = "postgres"; switch (procType) --- 465,473 ---- pgstat_forkexec(STATS_PROCESS_TYPE procType) { pid_t pid; ! char *av[15]; int ac = 0, bufc = 0, i; ! char pgstatBuf[12][MAXPGPATH]; av[ac++] = "postgres"; switch (procType) *************** *** 488,493 **** --- 489,496 ---- snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatSock); snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatPmPipe[0]); snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatPmPipe[1]); + snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatCollectorPmPipe[0]); + snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatCollectorPmPipe[1]); snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatPipe[0]); snprintf(pgstatBuf[bufc++],MAXPGPATH,"%d",pgStatPipe[1]); *************** *** 531,541 **** static void pgstat_parseArgs(PGSTAT_FORK_ARGS) { ! Assert(argc == 10); argc = 0; pgStatSock = atoi(argv[argc++]); pgStatPmPipe[0] = atoi(argv[argc++]); pgStatPmPipe[1] = atoi(argv[argc++]); pgStatPipe[0] = atoi(argv[argc++]); pgStatPipe[1] = atoi(argv[argc++]); MaxBackends = atoi(argv[argc++]); --- 534,546 ---- static void pgstat_parseArgs(PGSTAT_FORK_ARGS) { ! Assert(argc == 12); argc = 0; pgStatSock = atoi(argv[argc++]); pgStatPmPipe[0] = atoi(argv[argc++]); pgStatPmPipe[1] = atoi(argv[argc++]); + pgStatCollectorPmPipe[0] = atoi(argv[argc++]); + pgStatCollectorPmPipe[1] = atoi(argv[argc++]); pgStatPipe[0] = atoi(argv[argc++]); pgStatPipe[1] = atoi(argv[argc++]); MaxBackends = atoi(argv[argc++]); *************** *** 689,694 **** --- 694,705 ---- if (pgStatPmPipe[1] >= 0) closesocket(pgStatPmPipe[1]); pgStatPmPipe[1] = -1; + if (pgStatCollectorPmPipe[0] >= 0) + closesocket(pgStatCollectorPmPipe[0]); + pgStatCollectorPmPipe[0] = -1; + if (pgStatCollectorPmPipe[1] >= 0) + closesocket(pgStatCollectorPmPipe[1]); + pgStatCollectorPmPipe[1] = -1; } *************** *** 1504,1509 **** --- 1515,1522 ---- */ closesocket(pgStatPmPipe[1]); pgStatPmPipe[1] = -1; + closesocket(pgStatCollectorPmPipe[1]); + pgStatCollectorPmPipe[1] = -1; /* * Start a buffering process to read from the socket, so we have a *************** *** 1560,1566 **** fd_set rfds; int readPipe; int pmPipe; - int maxfd; int nready; int len = 0; struct timeval timeout; --- 1573,1578 ---- *************** *** 1577,1583 **** closesocket(pgStatPipe[1]); closesocket(pgStatSock); ! pmPipe = pgStatPmPipe[0]; /* * In the child we can have default SIGCHLD handling (in case we want --- 1589,1595 ---- closesocket(pgStatPipe[1]); closesocket(pgStatSock); ! pmPipe = pgStatCollectorPmPipe[0]; /* * In the child we can have default SIGCHLD handling (in case we want *************** *** 1679,1695 **** */ FD_ZERO(&rfds); FD_SET(readPipe, &rfds); - FD_SET(pmPipe, &rfds); - - if (readPipe > pmPipe) - maxfd = readPipe; - else - maxfd = pmPipe; /* * Now wait for something to do. */ ! nready = select(maxfd + 1, &rfds, NULL, NULL, (need_statwrite) ? &timeout : NULL); if (nready < 0) { --- 1691,1701 ---- */ FD_ZERO(&rfds); FD_SET(readPipe, &rfds); /* * Now wait for something to do. */ ! nready = select(readPipe+1, &rfds, NULL, NULL, (need_statwrite) ? &timeout : NULL); if (nready < 0) { *************** *** 1862,1868 **** * is still open. If it is read-ready (ie, EOF), the postmaster must * have quit. */ ! if (FD_ISSET(pmPipe, &rfds)) pgstat_write_statsfile(); } --- 1868,1879 ---- * is still open. If it is read-ready (ie, EOF), the postmaster must * have quit. */ ! FD_ZERO(&rfds); ! FD_SET(pmPipe, &rfds); ! timeout.tv_sec = 0; ! timeout.tv_usec = 0; ! nready = select(pmPipe+1,&rfds,NULL,NULL,&timeout); ! if (nready > 0 && FD_ISSET(pmPipe, &rfds)) pgstat_write_statsfile(); } diff -cr postgresql-snapshot-030325/src/backend/postmaster/postmaster.c postgresql-newsignal/src/backend/postmaster/postmaster.c *** postgresql-snapshot-030325/src/backend/postmaster/postmaster.c Wed Mar 24 16:20:54 2004 --- postgresql-newsignal/src/backend/postmaster/postmaster.c Fri Apr 2 22:07:18 2004 *************** *** 2017,2051 **** } - #ifdef WIN32 - /* - * On WIN32, we cannot use socket functions inside - * an APC (signal handler). If we do, select() will return - * with incorrect return values, causing the postmaster to - * enter a blocking accept(). We work around this by - * running it on a separate thread. We still block the main - * thread until it is done, so we don't scribble over any - * data from the wrong thread (pgstat functions aqre not - * thread safe). - */ - static DWORD WINAPI win32_pgstat_beterm_thread(LPVOID param) - { - pgstat_beterm((int)param); - return 0; - } - - static void win32_pgstat_beterm(int pid) { - HANDLE beterm_thread = CreateThread(NULL, 64*1024, win32_pgstat_beterm_thread, (LPVOID)pid, 0, NULL); - if (!beterm_thread) - ereport(FATAL, - (errmsg_internal("failed to create beterm sender thread: %i", (int)GetLastError()))); - if (WaitForSingleObject(beterm_thread,INFINITE) != WAIT_OBJECT_0) - ereport(FATAL, - (errmsg_internal("failed to wait for beterm sender thread: %i", (int)GetLastError()))); - CloseHandle(beterm_thread); - } - #endif - /* * CleanupProc -- cleanup after terminated backend. * --- 2017,2022 ---- *************** *** 2099,2109 **** else if (pid == BgWriterPID) BgWriterPID = 0; else - #ifndef WIN32 pgstat_beterm(pid); - #else - win32_pgstat_beterm(pid); - #endif return; } --- 2070,2076 ---- diff -cr postgresql-snapshot-030325/src/include/libpq/pqsignal.h postgresql-newsignal/src/include/libpq/pqsignal.h *** postgresql-snapshot-030325/src/include/libpq/pqsignal.h Sun Feb 8 23:28:57 2004 --- postgresql-newsignal/src/include/libpq/pqsignal.h Fri Apr 2 20:12:04 2004 *************** *** 18,26 **** #ifndef PQSIGNAL_H #define PQSIGNAL_H - #ifndef WIN32 #include - #endif #ifdef HAVE_SIGPROCMASK extern sigset_t UnBlockSig, --- 18,24 ---- *************** *** 46,68 **** 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 */ --- 44,48 ---- diff -cr postgresql-snapshot-030325/src/include/miscadmin.h postgresql-newsignal/src/include/miscadmin.h *** postgresql-snapshot-030325/src/include/miscadmin.h Wed Mar 24 23:40:29 2004 --- postgresql-newsignal/src/include/miscadmin.h Tue Mar 30 21:59:17 2004 *************** *** 83,89 **** #else #define CHECK_FOR_INTERRUPTS() \ do { \ ! WaitForSingleObjectEx(GetCurrentThread(),0,TRUE); \ if (InterruptPending) \ ProcessInterrupts(); \ } while(0) --- 83,90 ---- #else #define CHECK_FOR_INTERRUPTS() \ do { \ ! if (WaitForSingleObject(pgwin32_signal_event,0) == WAIT_OBJECT_0) \ ! pgwin32_dispatch_queued_signals(); \ if (InterruptPending) \ ProcessInterrupts(); \ } while(0) diff -cr postgresql-snapshot-030325/src/include/port/win32.h postgresql-newsignal/src/include/port/win32.h *** postgresql-snapshot-030325/src/include/port/win32.h Tue Mar 2 19:35:59 2004 --- postgresql-newsignal/src/include/port/win32.h Fri Apr 2 21:18:42 2004 *************** *** 98,112 **** 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) #ifndef FRONTEND - /* In libpq/pqsignal.c */ #define kill(pid,sig) pqkill(pid,sig) ! int pqkill(int pid, int sig); #endif /* Some extra signals */ #define SIGHUP 1 #define SIGQUIT 3 --- 98,146 ---- int semget(int semKey, int semNum, int flags); int semop(int semId, struct sembuf * sops, int flag); + /* 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 #define kill(pid,sig) pqkill(pid,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,181 **** --- 213,220 ---- #define EWOULDBLOCK WSAEWOULDBLOCK #define ECONNRESET WSAECONNRESET #define EINPROGRESS WSAEINPROGRESS + #define ENOBUFS WSAENOBUFS + #define EPROTONOSUPPORT WSAEPROTONOSUPPORT + #define ECONNREFUSED WSAECONNREFUSED + #define EBADFD WSAENOTSOCK + #define EOPNOTSUPP WSAEOPNOTSUPP diff -cr postgresql-snapshot-030325/src/port/pgsleep.c postgresql-newsignal/src/port/pgsleep.c *** postgresql-snapshot-030325/src/port/pgsleep.c Tue Feb 10 05:23:03 2004 --- postgresql-newsignal/src/port/pgsleep.c Fri Apr 2 21:17:24 2004 *************** *** 15,21 **** #include #include - /* * pg_usleep --- delay the specified number of microseconds. * --- 15,20 ---- *************** *** 25,30 **** --- 24,32 ---- * * On machines where "long" is 32 bits, the maximum delay is ~2000 seconds. */ + #ifdef pg_usleep + #undef pg_usleep + #endif void pg_usleep(long microsec) { *************** *** 37,43 **** delay.tv_usec = microsec % 1000000L; (void) select(0, NULL, NULL, NULL, &delay); #else ! SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), TRUE); #endif } } --- 39,45 ---- delay.tv_usec = microsec % 1000000L; (void) select(0, NULL, NULL, NULL, &delay); #else ! SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE); #endif } }