* Copyright (C) 1995-2006, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: zoom-c.c,v 1.87 2006-08-25 14:57:04 adam Exp $
+ * $Id: zoom-c.c,v 1.92 2006-10-05 14:58:58 adam Exp $
*/
/**
* \file zoom-c.c
#include <sys/select.h>
#endif
#ifdef WIN32
+#if FD_SETSIZE < 512
+#define FD_SETSIZE 512
+#endif
#include <winsock.h>
#endif
static zoom_ret do_write_ex(ZOOM_connection c, char *buf_out, int len_out);
static char *cql2pqf(ZOOM_connection c, const char *cql);
-static void initlog()
+static void initlog(void)
{
static int log_level_initialized = 0;
if (!log_level_initialized)
return *taskp;
}
+ZOOM_API(int) ZOOM_connection_is_idle(ZOOM_connection c)
+{
+ return c->tasks ? 0 : 1;
+}
+
ZOOM_task ZOOM_connection_insert_task(ZOOM_connection c, int which)
{
ZOOM_task task = (ZOOM_task) xmalloc(sizeof(*task));
return c;
}
+
/* set database names. Take local databases (if set); otherwise
take databases given in ZURL (if set); otherwise use Default */
static char **set_DatabaseNames(ZOOM_connection con, ZOOM_options options,
}
}
-ZOOM_resultset ZOOM_resultset_create()
+ZOOM_resultset ZOOM_resultset_create(void)
{
int i;
ZOOM_resultset r = (ZOOM_resultset) xmalloc(sizeof(*r));
c->state = STATE_IDLE;
}
+static int ZOOM_test_reconnect(ZOOM_connection c)
+{
+ if (!c->reconnect_ok)
+ return 0;
+ do_close(c);
+ c->reconnect_ok = 0;
+ c->tasks->running = 0;
+ ZOOM_connection_insert_task(c, ZOOM_TASK_CONNECT);
+ return 1;
+}
+
static void ZOOM_resultset_retrieve(ZOOM_resultset r,
int force_sync, int start, int count)
{
odr_prepend(c->odr_out, "ZOOM-C",
ireq->implementationName));
- version = odr_strdup(c->odr_out, "$Revision: 1.87 $");
+ version = odr_strdup(c->odr_out, "$Revision: 1.92 $");
if (strlen(version) > 10) /* check for unexpanded CVS strings */
version[strlen(version)-2] = '\0';
ireq->implementationVersion =
break;
case Z_APDU_close:
yaz_log(log_api, "%p recv_apdu Close PDU", c);
- if (c->reconnect_ok)
- {
- do_close(c);
- c->reconnect_ok = 0;
- c->tasks->running = 0;
- ZOOM_connection_insert_task(c, ZOOM_TASK_CONNECT);
- }
- else
+ if (!ZOOM_test_reconnect(c))
{
set_ZOOM_error(c, ZOOM_ERROR_CONNECTION_LOST, c->host_port);
do_close(c);
return 0;
if (r <= 0)
{
- if (c->reconnect_ok)
+ if (ZOOM_test_reconnect(c))
{
yaz_log(log_details, "%p do_read reconnect read", c);
- do_close(c);
- c->reconnect_ok = 0;
- c->tasks->running = 0;
- ZOOM_connection_insert_task(c, ZOOM_TASK_CONNECT);
}
else
{
if ((r = cs_put(c->cs, buf_out, len_out)) < 0)
{
yaz_log(log_details, "%p do_write_ex write failed", c);
- if (c->reconnect_ok)
+ if (ZOOM_test_reconnect(c))
{
- do_close(c);
- c->reconnect_ok = 0;
- c->tasks->running = 0;
- ZOOM_connection_insert_task(c, ZOOM_TASK_CONNECT);
return zoom_pending;
}
if (c->state == STATE_CONNECTING)
yaz_log(log_details, "%p ZOOM_connection_do_io mask=%d cs_look=%d",
c, mask, r);
- if (mask & ZOOM_SELECT_EXCEPT)
- {
- if (r == CS_CONNECT)
- set_ZOOM_error(c, ZOOM_ERROR_CONNECT, c->host_port);
- else
- set_ZOOM_error(c, ZOOM_ERROR_CONNECTION_LOST, c->host_port);
- do_close(c);
- return;
- }
if (r == CS_NONE)
{
event = ZOOM_Event_create(ZOOM_EVENT_CONNECT);
}
else
{
+ if (mask & ZOOM_SELECT_EXCEPT)
+ {
+ if (ZOOM_test_reconnect(c))
+ {
+ event = ZOOM_Event_create(ZOOM_EVENT_CONNECT);
+ ZOOM_connection_put_event(c, event);
+ }
+ else
+ {
+ set_ZOOM_error(c, ZOOM_ERROR_CONNECTION_LOST, c->host_port);
+ do_close(c);
+ }
+ return;
+ }
if (mask & ZOOM_SELECT_READ)
do_read(c);
if (c->cs && (mask & ZOOM_SELECT_WRITE))