[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pq 8151e0bc99 60/63: Add function pq:notifies to suppor
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pq 8151e0bc99 60/63: Add function pq:notifies to support LISTEN. |
Date: |
Mon, 14 Feb 2022 23:24:28 -0500 (EST) |
branch: externals/pq
commit 8151e0bc99e090c570bbe08a686dacfac5f3bbc2
Author: Andreas Seltenreich <seltenreich@gmx.de>
Commit: Andreas Seltenreich <seltenreich@gmx.de>
Add function pq:notifies to support LISTEN.
---
pq.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
test.el | 22 ++++++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/pq.c b/pq.c
index ab13da6c00..abf6e0ee63 100644
--- a/pq.c
+++ b/pq.c
@@ -282,6 +282,43 @@ Fpq_reset (emacs_env *env, ptrdiff_t nargs, emacs_value
args[], void *data)
return Qt;
}
+static emacs_value
+Fpq_notifies (emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data)
+{
+ PGconn *conn = env->get_user_ptr(env, args[0]);
+
+ if (env->non_local_exit_check (env) != emacs_funcall_exit_return)
+ return NULL;
+
+ if (!connection_ok(env, conn)) {
+ return NULL;
+ }
+
+ PQconsumeInput(conn);
+
+ emacs_value Qvector = env->intern (env, "vector");
+ emacs_value Qcons = env->intern (env, "cons");
+ emacs_value result = Qnil;
+
+ PGnotify *notify;
+ while ((notify = PQnotifies(conn)) != NULL)
+ {
+ emacs_value vector_args[3];
+ vector_args[0] = env->make_string(env, notify->relname,
strlen(notify->relname));
+ vector_args[1] = env->make_integer(env, notify->be_pid);
+ vector_args[2] = env->make_string(env, notify->extra,
strlen(notify->extra));
+
+ PQfreemem(notify);
+
+ emacs_value cons_args[2];
+ cons_args[0] = env->funcall (env, Qvector, 3, vector_args);
+ cons_args[1] = result;
+ result = env->funcall (env, Qcons, 2, cons_args);
+ }
+
+ return result;
+}
+
/* Bind NAME to FUN. */
static void
bind_function (emacs_env *env, const char *name, emacs_value Sfun)
@@ -394,6 +431,13 @@ emacs_module_init (struct emacs_runtime *ert)
"\n\(fn CONN)",
NULL);
+ DEFUN("pq:notifies", Fpq_notifies, 1, 1,
+ "Get asynchronous notifications recieved on CONN.\n"
+ "\n"
+ "Returns list of vectors [channel-string pid payload-string]\n"
+ "\n\(fn CONN)",
+ NULL);
+
#undef DEFUN
/* Define custom error signal. The error data is a list with two
diff --git a/test.el b/test.el
index 68d84a2735..4988725e24 100644
--- a/test.el
+++ b/test.el
@@ -102,3 +102,25 @@
(with-current-buffer "*Messages*"
(goto-char (point-max))
(re-search-backward "ert_nonexisting_table"))))
+
+(ert-deftest pq-async-notify-test ()
+ (let* ((conn (pq:connectdb *conninfo*))
+ (mypid (car (pq:query conn "select pg_backend_pid()"))))
+ (pq:notifies conn)
+ (pq:query conn "listen ert_notification")
+ (pq:query conn "notify ert_notification")
+ (should
+ (equal
+ (car (pq:notifies conn))
+ (vector "ert_notification" mypid "")))
+ (should (equal (pq:notifies conn) nil))
+ (pq:query conn "notify ert_notification, 'paylöad'")
+ (should
+ (equal
+ (car (pq:notifies conn))
+ (vector "ert_notification" mypid "paylöad")))
+ (should-error (pq:notifies 0))
+ (should-error (pq:notifies nil))
+ (should-error (pq:query conn "select pg_terminate_backend($1)" mypid))
+ (should-error (pq:notifies conn))
+))
- [elpa] externals/pq a70d1fe40d 37/63: Test encoding by using some high unicode codepoints., (continued)
- [elpa] externals/pq a70d1fe40d 37/63: Test encoding by using some high unicode codepoints., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 795260553a 17/63: Use load-path in test.el, ELPA Syncer, 2022/02/14
- [elpa] externals/pq a03d2c2e9b 44/63: Update README, ELPA Syncer, 2022/02/14
- [elpa] externals/pq 12c54fbf15 14/63: Add undef DEFUN macro, ELPA Syncer, 2022/02/14
- [elpa] externals/pq 862bf023c0 20/63: Add processing for asynchronous notices., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 9e719959b3 12/63: Avoid global variable for pq:error symbol., ELPA Syncer, 2022/02/14
- [elpa] externals/pq ca337173dd 08/63: Explicitly free the libpq result., ELPA Syncer, 2022/02/14
- [elpa] externals/pq e1d1b77b88 34/63: test: Notice receiver., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 499dc3b50e 57/63: Re-introduce custom error signal pq:error with SQLSTATE., ELPA Syncer, 2022/02/14
- [elpa] externals/pq d738d21b6a 52/63: Add checks for non-local exit., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 8151e0bc99 60/63: Add function pq:notifies to support LISTEN.,
ELPA Syncer <=
- [elpa] externals/pq 46e38888e3 01/63: Initial commit., ELPA Syncer, 2022/02/14
- [elpa] externals/pq b72ee45524 02/63: Add .gitignore, flush tempfile., ELPA Syncer, 2022/02/14
- [elpa] externals/pq dfa4ad04bb 03/63: README: clarify., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 8e13d07737 16/63: Update Makefile, ELPA Syncer, 2022/02/14
- [elpa] externals/pq e9e1998796 10/63: Handle booleans and fix some NULL handling., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 09e320f63f 29/63: Initial travis ci configuration, ELPA Syncer, 2022/02/14
- [elpa] externals/pq 76f81f5ca5 05/63: Replace low-level functions with a higher level one., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 1048d41b99 28/63: Use pg_config to detect postgresql include directory, ELPA Syncer, 2022/02/14
- [elpa] externals/pq fb79f059fb 19/63: Flush debug fprintf()s., ELPA Syncer, 2022/02/14
- [elpa] externals/pq 2c03e4aba4 42/63: Make garbage-collection test more robust., ELPA Syncer, 2022/02/14