X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=zoom%2Fzoom-c.c;h=8b38ce38ceb3fa09fb2fbaae0ea67779c240420b;hb=79e745223e808aef83c885d94a7a2e58ee8e4ba0;hp=51908f84067cee60405333f06f36bc94f67b68c9;hpb=69bcd68523a9a8da083faef16887100369152673;p=yaz-moved-to-github.git diff --git a/zoom/zoom-c.c b/zoom/zoom-c.c index 51908f8..8b38ce3 100644 --- a/zoom/zoom-c.c +++ b/zoom/zoom-c.c @@ -1,5 +1,5 @@ /* - * $Id: zoom-c.c,v 1.1 2001-10-23 21:00:20 adam Exp $ + * $Id: zoom-c.c,v 1.3 2001-11-06 17:05:19 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -144,9 +144,9 @@ void Z3950_connection_connect(Z3950_connection c, } } -Z3950_search Z3950_search_create(void) +Z3950_query Z3950_query_create(void) { - Z3950_search s = xmalloc (sizeof(*s)); + Z3950_query s = xmalloc (sizeof(*s)); s->refcount = 1; s->query = 0; @@ -161,13 +161,13 @@ const char *Z3950_connection_host (Z3950_connection c) return c->host_port; } -void Z3950_search_destroy(Z3950_search s) +void Z3950_query_destroy(Z3950_query s) { if (!s) return; (s->refcount)--; - yaz_log (LOG_DEBUG, "Z3950_search_destroy count=%d", s->refcount); + yaz_log (LOG_DEBUG, "Z3950_query_destroy count=%d", s->refcount); if (s->refcount == 0) { odr_destroy (s->odr); @@ -175,7 +175,7 @@ void Z3950_search_destroy(Z3950_search s) } } -int Z3950_search_prefix(Z3950_search s, const char *str) +int Z3950_query_prefix(Z3950_query s, const char *str) { s->query = odr_malloc (s->odr, sizeof(*s->query)); s->query->which = Z_Query_type_1; @@ -185,7 +185,7 @@ int Z3950_search_prefix(Z3950_search s, const char *str) return 0; } -int Z3950_search_sortby(Z3950_search s, const char *criteria) +int Z3950_query_sortby(Z3950_query s, const char *criteria) { s->sort_spec = yaz_sort_spec (s->odr, criteria); if (!s->sort_spec) @@ -285,16 +285,16 @@ Z3950_resultset Z3950_resultset_create () Z3950_resultset Z3950_connection_search_pqf(Z3950_connection c, const char *q) { Z3950_resultset r; - Z3950_search s = Z3950_search_create(); + Z3950_query s = Z3950_query_create(); - Z3950_search_prefix (s, q); + Z3950_query_prefix (s, q); r = Z3950_connection_search (c, s); - Z3950_search_destroy (s); + Z3950_query_destroy (s); return r; } -Z3950_resultset Z3950_connection_search(Z3950_connection c, Z3950_search q) +Z3950_resultset Z3950_connection_search(Z3950_connection c, Z3950_query q) { Z3950_resultset r = Z3950_resultset_create (); Z3950_task task; @@ -350,7 +350,7 @@ void Z3950_resultset_destroy(Z3950_resultset r) rp = &(*rp)->next; } } - Z3950_search_destroy (r->search); + Z3950_query_destroy (r->search); Z3950_options_destroy (r->options); odr_destroy (r->odr); xfree (r); @@ -395,22 +395,19 @@ static void Z3950_resultset_retrieve (Z3950_resultset r, } void Z3950_resultset_records (Z3950_resultset r, Z3950_record *recs, - size_t *cnt) + size_t start, size_t count) { int force_present = 0; - int start, count; if (!r) return ; - start = Z3950_options_get_int (r->options, "start", 0); - count = Z3950_options_get_int (r->options, "count", 0); - if (cnt && recs) + if (count && recs) force_present = 1; Z3950_resultset_retrieve (r, force_present, start, count); if (force_present) { - int i; - for (i = 0; i< *cnt; i++) + size_t i; + for (i = 0; i< count; i++) recs[i] = Z3950_resultset_record_immediate (r, i+start); } } @@ -432,15 +429,18 @@ static void do_connect (Z3950_connection c) if (c->cs) { - cs_connect (c->cs, add); - c->state = STATE_CONNECTING; - c->mask = Z3950_SELECT_READ | Z3950_SELECT_WRITE; - } - else - { - c->state = STATE_IDLE; - c->error = Z3950_ERROR_CONNECT; + int ret = cs_connect (c->cs, add); + yaz_log (LOG_DEBUG, "cs_connect returned %d", ret); + if (ret >= 0) + { + c->state = STATE_CONNECTING; + c->mask = Z3950_SELECT_READ | Z3950_SELECT_WRITE | Z3950_SELECT_EXCEPT; + return; + } } + c->event_pending = 1; + c->state = STATE_IDLE; + c->error = Z3950_ERROR_CONNECT; } int z3950_connection_socket(Z3950_connection c) @@ -728,7 +728,7 @@ Z3950_record Z3950_record_dup (Z3950_record srec) return nrec; } -Z3950_record Z3950_resultset_record_immediate (Z3950_resultset s, int pos) +Z3950_record Z3950_resultset_record_immediate (Z3950_resultset s,size_t pos) { Z3950_record rec = record_cache_lookup (s, pos, 0); if (!rec) @@ -736,7 +736,7 @@ Z3950_record Z3950_resultset_record_immediate (Z3950_resultset s, int pos) return Z3950_record_dup (rec); } -Z3950_record Z3950_resultset_record (Z3950_resultset r, int pos) +Z3950_record Z3950_resultset_record (Z3950_resultset r, size_t pos) { Z3950_resultset_retrieve (r, 1, pos, 1); return Z3950_resultset_record_immediate (r, pos); @@ -752,7 +752,7 @@ void Z3950_record_destroy (Z3950_record rec) xfree (rec); } -void *Z3950_record_get (Z3950_record rec, const char *type, int *len) +void *Z3950_record_get (Z3950_record rec, const char *type, size_t *len) { Z_NamePlusRecord *npr; if (!rec) @@ -823,8 +823,8 @@ void *Z3950_record_get (Z3950_record rec, const char *type, int *len) return 0; } -void *Z3950_resultset_get (Z3950_resultset s, int pos, const char *type, - int *len) +void *Z3950_resultset_get (Z3950_resultset s, size_t pos, const char *type, + size_t *len) { Z3950_record rec = record_cache_lookup (s, pos, 0); return Z3950_record_get (rec, type, len); @@ -1293,7 +1293,7 @@ int Z3950_connection_do_io(Z3950_connection c, int mask) { #if 0 int r = cs_look(c->cs); - yaz_log (LOG_LOG, "Z3950_connection_do_io c=%p mask=%d cs_look=%d", + yaz_log (LOG_DEBUG, "Z3950_connection_do_io c=%p mask=%d cs_look=%d", c, mask, r); if (r == CS_NONE) @@ -1303,7 +1303,7 @@ int Z3950_connection_do_io(Z3950_connection c, int mask) } else if (r == CS_CONNECT) { - yaz_log (LOG_LOG, "calling rcvconnect"); + yaz_log (LOG_DEBUG, "calling rcvconnect"); if (cs_rcvconnect (c->cs) < 0) { c->error = Z3950_ERROR_CONNECT; @@ -1351,7 +1351,7 @@ int Z3950_connection_do_io(Z3950_connection c, int mask) int Z3950_event (int no, Z3950_connection *cs) { struct timeval tv; - fd_set input, output; + fd_set input, output, except; int i, r; int max_fd = 0; @@ -1370,6 +1370,7 @@ int Z3950_event (int no, Z3950_connection *cs) FD_ZERO (&input); FD_ZERO (&output); + FD_ZERO (&except); r = 0; for (i = 0; i