diff options
| author | Robert Haas | 2014-10-31 16:02:40 +0000 |
|---|---|---|
| committer | Robert Haas | 2014-10-31 16:02:40 +0000 |
| commit | 2bd9e412f92bc6a68f3e8bcb18e04955cc35001d (patch) | |
| tree | 9a4a8dc45c5761aa0554d7f1ba255d5e599150b5 /src/include/libpq | |
| parent | 252e652edea80b948fbc9c3723183065e94d8480 (diff) | |
Support frontend-backend protocol communication using a shm_mq.
A background worker can use pq_redirect_to_shm_mq() to direct protocol
that would normally be sent to the frontend to a shm_mq so that another
process may read them.
The receiving process may use pq_parse_errornotice() to parse an
ErrorResponse or NoticeResponse from the background worker and, if
it wishes, ThrowErrorData() to propagate the error (with or without
further modification).
Patch by me. Review by Andres Freund.
Diffstat (limited to 'src/include/libpq')
| -rw-r--r-- | src/include/libpq/libpq.h | 36 | ||||
| -rw-r--r-- | src/include/libpq/pqmq.h | 22 |
2 files changed, 50 insertions, 8 deletions
diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h index 5da9d8d4f5..409f3d7786 100644 --- a/src/include/libpq/libpq.h +++ b/src/include/libpq/libpq.h @@ -37,6 +37,31 @@ typedef struct } u; } PQArgBlock; +typedef struct +{ + void (*comm_reset)(void); + int (*flush)(void); + int (*flush_if_writable)(void); + bool (*is_send_pending)(void); + int (*putmessage)(char msgtype, const char *s, size_t len); + void (*putmessage_noblock)(char msgtype, const char *s, size_t len); + void (*startcopyout)(void); + void (*endcopyout)(bool errorAbort); +} PQcommMethods; + +PQcommMethods *PqCommMethods; + +#define pq_comm_reset() (PqCommMethods->comm_reset()) +#define pq_flush() (PqCommMethods->flush()) +#define pq_flush_if_writable() (PqCommMethods->flush_if_writable()) +#define pq_is_send_pending() (PqCommMethods->is_send_pending()) +#define pq_putmessage(msgtype, s, len) \ + (PqCommMethods->putmessage(msgtype, s, len)) +#define pq_putmessage_noblock(msgtype, s, len) \ + (PqCommMethods->putmessage(msgtype, s, len)) +#define pq_startcopyout() (PqCommMethods->startcopyout()) +#define pq_endcopyout(errorAbort) (PqCommMethods->endcopyout(errorAbort)) + /* * External functions. */ @@ -51,7 +76,6 @@ extern int StreamConnection(pgsocket server_fd, Port *port); extern void StreamClose(pgsocket sock); extern void TouchSocketFiles(void); extern void pq_init(void); -extern void pq_comm_reset(void); extern int pq_getbytes(char *s, size_t len); extern int pq_getstring(StringInfo s); extern int pq_getmessage(StringInfo s, int maxlen); @@ -59,13 +83,6 @@ extern int pq_getbyte(void); extern int pq_peekbyte(void); extern int pq_getbyte_if_available(unsigned char *c); extern int pq_putbytes(const char *s, size_t len); -extern int pq_flush(void); -extern int pq_flush_if_writable(void); -extern bool pq_is_send_pending(void); -extern int pq_putmessage(char msgtype, const char *s, size_t len); -extern void pq_putmessage_noblock(char msgtype, const char *s, size_t len); -extern void pq_startcopyout(void); -extern void pq_endcopyout(bool errorAbort); /* * prototypes for functions in be-secure.c @@ -75,6 +92,9 @@ extern char *ssl_key_file; extern char *ssl_ca_file; extern char *ssl_crl_file; +extern int (*pq_putmessage_hook)(char msgtype, const char *s, size_t len); +extern int (*pq_flush_hook)(void); + extern int secure_initialize(void); extern bool secure_loaded_verify_locations(void); extern void secure_destroy(void); diff --git a/src/include/libpq/pqmq.h b/src/include/libpq/pqmq.h new file mode 100644 index 0000000000..6bb24d9928 --- /dev/null +++ b/src/include/libpq/pqmq.h @@ -0,0 +1,22 @@ +/*------------------------------------------------------------------------- + * + * pqmq.h + * Use the frontend/backend protocol for communication over a shm_mq + * + * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/pqmq.h + * + *------------------------------------------------------------------------- + */ +#ifndef PQMQ_H +#define PQMQ_H + +#include "storage/shm_mq.h" + +extern void pq_redirect_to_shm_mq(shm_mq *, shm_mq_handle *); + +extern void pq_parse_errornotice(StringInfo str, ErrorData *edata); + +#endif /* PQMQ_H */ |
