+ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_listen_async, 0, 0, 0)
+ ZEND_ARG_INFO(0, channel)
+ ZEND_ARG_INFO(0, callable)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqconn, listenAsync) {
+ char *channel_str = NULL;
+ int channel_len = 0;
+ php_pq_callback_t listener;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sf", &channel_str, &channel_len, &listener.fci, &listener.fcc)) {
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ obj->intern->poller = PQconsumeInput;
+
+ if (obj->intern) {
+ char *quoted_channel = PQescapeIdentifier(obj->intern->conn, channel_str, channel_len);
+
+ if (quoted_channel) {
+ char *cmd;
+
+ obj->intern->poller = PQconsumeInput;
+
+ spprintf(&cmd, 0, "LISTEN %s", channel_str);
+ if (PQsendQuery(obj->intern->conn, cmd)) {
+ php_pqconn_add_listener(obj, channel_str, channel_len, &listener TSRMLS_CC);
+ RETVAL_TRUE;
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not install listener (%s)", PHP_PQerrorMessage(obj->intern->conn));
+ RETVAL_FALSE;
+ }
+
+ efree(cmd);
+ PQfreemem(quoted_channel);
+
+ php_pqconn_notify_listeners(obj TSRMLS_CC);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not escape channel identifier (%s)", PHP_PQerrorMessage(obj->intern->conn));
+ }
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "pq\\Connection not initialized");
+ RETVAL_FALSE;
+ }
+ }
+}
+