#!/bin/sh
-# $Id: buildconf.sh,v 1.5 2001-02-21 11:25:07 adam Exp $
+# $Id: buildconf.sh,v 1.6 2001-03-26 14:43:49 adam Exp $
dir=`aclocal --print-ac-dir`
if [ -f $dir/yaz.m4 ]; then
- aclocal
+ aclocal || exit 1
else
- aclocal -I .
+ aclocal -I . || exit 1
+fi
+libtoolize --force >/dev/null 2>&1 || exit 2
+automake -a >/dev/null 2>&1 || exit 3
+autoconf || exit 4
+if [ -f config.cache ]; then
+ rm config.cache
fi
-libtoolize --force
-automake -a
-autoconf
AM_DISABLE_SHARED
AM_PROG_LIBTOOL
-YAZ_INIT
+YAZ_INIT(threads)
-YAZPP_SRC_ROOT=`pwd`
AC_SUBST(YAZPP_SRC_ROOT)
+AC_SUBST(YAZPP_BUILD_ROOT)
+YAZPP_SRC_ROOT=`cd ${srcdir}; pwd`
+YAZPP_BUILD_ROOT=`pwd`
-if test -f src/yaz++-config.in; then
- rm src/yaz++-config.in
+if test -f ${srcdir}/src/yaz++-config.in; then
+ rm ${srcdir}/src/yaz++-config.in
fi
-sed s%yaz_echo_source=yes%yaz_echo_source=no%g < yaz++-config.in >src/yaz++-config.in
+sed s%yaz_echo_source=yes%yaz_echo_source=no%g < ${srcdir}/yaz++-config.in >${srcdir}/src/yaz++-config.in
AC_OUTPUT([
Makefile
src/Makefile
* Copyright (c) 1998-2000, Index Data.
* See the file LICENSE for details.
*
- * $Id: yaz-pdu-assoc.h,v 1.1 2000-10-11 11:58:16 adam Exp $
+ * $Id: yaz-pdu-assoc.h,v 1.2 2001-03-26 14:43:49 adam Exp $
*/
#ifndef YAZ_PDU_ASSOC_INCLUDED
listen method.
*/
class YAZ_EXPORT Yaz_PDU_Assoc : public IYaz_PDU_Observable, IYazSocketObserver {
+ friend class Yaz_PDU_AssocThread;
private:
- enum { Connecting, Listen, Ready, Closed } m_state;
+ enum {
+ Connecting,
+ Listen,
+ Ready,
+ Closed,
+ Writing,
+ Accepting
+ } m_state;
class PDU_Queue {
public:
PDU_Queue(const char *buf, int len);
int *m_destroyed;
int m_idleTime;
int m_log;
+ void init(IYazSocketObservable *socketObservable);
public:
- COMSTACK comstack();
+ COMSTACK comstack(const char *type_and_host, void **vp);
/// Create object using specified socketObservable
Yaz_PDU_Assoc(IYazSocketObservable *socketObservable);
+ /// Create Object using existing comstack
+ Yaz_PDU_Assoc(IYazSocketObservable *socketObservable,
+ COMSTACK cs);
/// Close socket and destroy object.
/// virtual ~Yaz_PDU_Assoc();
/// Clone the object
void connect(IYaz_PDU_Observer *observer, const char *addr);
/// listen for clients (server role)
void listen(IYaz_PDU_Observer *observer, const char *addr);
- /// open with existing socket
- void socket(IYaz_PDU_Observer *observer, int fd);
/// Socket notification
void socketNotify(int event);
/// Close socket
/// Set Idle Time
void idleTime (int timeout);
/// Child start...
- virtual void childNotify(int fd);
+ virtual void childNotify(COMSTACK cs);
};
+class YAZ_EXPORT Yaz_PDU_AssocThread : public Yaz_PDU_Assoc {
+ public:
+ Yaz_PDU_AssocThread(IYazSocketObservable *socketObservable);
+ private:
+ void childNotify(COMSTACK cs);
+
+};
#endif
+
* Copyright (c) 1998-2000, Index Data.
* See the file LICENSE for details.
*
- * $Id: yaz-pdu-observer.h,v 1.2 2000-11-01 14:22:59 adam Exp $
+ * $Id: yaz-pdu-observer.h,v 1.3 2001-03-26 14:43:49 adam Exp $
*/
#ifndef YAZ_PDU_OBSERVER_H
virtual void destroy() = 0;
/// Set Idle Time
virtual void idleTime (int timeout) = 0;
- /// open with existing socket
- virtual void socket(IYaz_PDU_Observer *observer, int fd) = 0;
};
/** Protocol Data Unit Observer.
/// Called whenever there is a timeout
virtual void timeoutNotify() = 0;
/// Make clone of observer using IYaz_PDU_Observable interface
- virtual IYaz_PDU_Observer *clone(IYaz_PDU_Observable *the_PDU_Observable,
- int fd) = 0;
+ virtual IYaz_PDU_Observer *sessionNotify(
+ IYaz_PDU_Observable *the_PDU_Observable, int fd) = 0;
};
#endif
* Copyright (c) 1998-2000, Index Data.
* See the file LICENSE for details.
*
- * $Id: yaz-proxy.h,v 1.2 2000-11-01 14:22:59 adam Exp $
+ * $Id: yaz-proxy.h,v 1.3 2001-03-26 14:43:49 adam Exp $
*/
#include <yaz++/yaz-z-assoc.h>
Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable);
~Yaz_ProxyClient();
void recv_Z_PDU(Z_APDU *apdu);
- IYaz_PDU_Observer* clone(IYaz_PDU_Observable *the_PDU_Observable, int fd);
+ IYaz_PDU_Observer* sessionNotify
+ (IYaz_PDU_Observable *the_PDU_Observable, int fd);
void shutdown();
Yaz_Proxy *m_server;
void failNotify();
Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable);
~Yaz_Proxy();
void recv_Z_PDU(Z_APDU *apdu);
- IYaz_PDU_Observer* clone(IYaz_PDU_Observable *the_PDU_Observable, int fd);
+ IYaz_PDU_Observer* sessionNotify
+ (IYaz_PDU_Observable *the_PDU_Observable, int fd);
void failNotify();
void timeoutNotify();
void connectNotify();
/*
- * Copyright (c) 2000, Index Data.
+ * Copyright (c) 2000-2001, Index Data.
* See the file LICENSE for details.
*
- * $Id: yaz-z-server.h,v 1.1 2000-10-11 11:58:16 adam Exp $
+ * $Id: yaz-z-server.h,v 1.2 2001-03-26 14:43:49 adam Exp $
*/
#include <yaz++/yaz-z-assoc.h>
+class Yaz_Z_Server;
+
+class YAZ_EXPORT Yaz_I_Facility {
+ public:
+ virtual const char *get_name(Yaz_Z_Server *server) = 0;
+ virtual int open(Yaz_Z_Server *server,
+ Z_InitRequest *initRequest,
+ Z_InitResponse *initResponse) = 0;
+ virtual int recv_PDU(Yaz_Z_Server *server, Z_APDU *apdu) = 0;
+ virtual int close(Yaz_Z_Server *server) = 0;
+};
+
+class YAZ_EXPORT Yaz_Facility_Retrieval : public Yaz_I_Facility {
+ public:
+ const char *get_name(Yaz_Z_Server *server);
+ int open(Yaz_Z_Server *server,
+ Z_InitRequest *initRequest,
+ Z_InitResponse *initResponse);
+ int recv_PDU(Yaz_Z_Server *server, Z_APDU *apdu);
+ int close(Yaz_Z_Server *server);
+};
+
class YAZ_EXPORT Yaz_Z_Server : public Yaz_Z_Assoc {
public:
Yaz_Z_Server(IYaz_PDU_Observable *the_PDU_Observable);
void create_surrogateDiagnostics(Z_NamePlusRecord *rec,
const char *dbname, int error,
char *const addinfo);
-
private:
Z_Records *pack_records (const char *resultSetName,
int start, int num,
-## $Id: Makefile.am,v 1.1 2000-10-11 11:58:16 adam Exp $
+## $Id: Makefile.am,v 1.2 2001-03-26 14:43:49 adam Exp $
-INCLUDES=$(YAZINC) -I../include
+INCLUDES=$(YAZINC) -I$(srcdir)/../include
lib_LTLIBRARIES = libyaz++.la
libyaz___la_SOURCES=yaz-socket-manager.cpp yaz-pdu-assoc.cpp \
yaz-z-assoc.cpp yaz-proxy.cpp yaz-z-query.cpp yaz-ir-assoc.cpp \
- yaz-z-server.cpp
+ yaz-z-server.cpp yaz-pdu-assoc-thread.cpp
libyaz___la_LDFLAGS=-version-info 0:0:0
* See the file LICENSE for details.
*
* $Log: yaz-client.cpp,v $
- * Revision 1.16 2000-11-01 14:22:59 adam
+ * Revision 1.17 2001-03-26 14:43:49 adam
+ * New threaded PDU association.
+ *
+ * Revision 1.16 2000/11/01 14:22:59 adam
* Added fd parameter for method IYaz_PDU_Observer::clone.
*
* Revision 1.15 2000/10/11 11:58:16 adam
public:
MyClient(IYaz_PDU_Observable *the_PDU_Observable,
Yaz_SocketManager *the_SocketManager);
- IYaz_PDU_Observer *clone(IYaz_PDU_Observable *the_PDU_Observable, int fd);
+ IYaz_PDU_Observer *sessionNotify(
+ IYaz_PDU_Observable *the_PDU_Observable, int fd);
int args(Yaz_SocketManager *socketManager, int argc, char **argv);
int interactive(Yaz_SocketManager *socketManager);
int wait();
set_lastReceived(-1);
}
-IYaz_PDU_Observer *MyClient::clone(IYaz_PDU_Observable *the_PDU_Observable,
- int fd)
+IYaz_PDU_Observer *MyClient::sessionNotify(
+ IYaz_PDU_Observable *the_PDU_Observable, int fd)
{
return new MyClient(the_PDU_Observable, m_socketManager);
}
--- /dev/null
+/*
+ * Copyright (c) 1998-2001, Index Data.
+ * See the file LICENSE for details.
+ *
+ * $Log: yaz-pdu-assoc-thread.cpp,v $
+ * Revision 1.1 2001-03-26 14:43:49 adam
+ * New threaded PDU association.
+ *
+ */
+
+#include <yaz/log.h>
+#include <yaz/tcpip.h>
+
+#include <yaz++/yaz-pdu-assoc.h>
+#include <yaz++/yaz-socket-manager.h>
+
+#ifdef WIN32
+#include <process.h>
+#else
+#include <pthread.h>
+#endif
+
+
+Yaz_PDU_AssocThread::Yaz_PDU_AssocThread(
+ IYazSocketObservable *socketObservable)
+ : Yaz_PDU_Assoc(socketObservable)
+{
+
+}
+
+#ifdef WIN32
+void __cdecl
+#else
+void *
+#endif
+events(void *p)
+{
+ Yaz_SocketManager *s = (Yaz_SocketManager *) p;
+
+ logf (LOG_LOG, "thread started");
+ while (s->processEvent() > 0)
+ ;
+ logf (LOG_LOG, "thread finished");
+#ifdef WIN32
+#else
+ return 0;
+#endif
+}
+
+void Yaz_PDU_AssocThread::childNotify(COMSTACK cs)
+{
+ Yaz_SocketManager *socket_observable = new Yaz_SocketManager;
+ Yaz_PDU_Assoc *new_observable = new Yaz_PDU_Assoc (socket_observable, cs);
+
+ /// Clone PDU Observer
+ new_observable->m_PDU_Observer =
+ m_PDU_Observer->sessionNotify(new_observable, cs_fileno(cs));
+#ifdef WIN32
+ long t_id;
+ t_id = _beginthread (events, 0, socket_observable);
+ if (t_id == -1)
+ {
+ yaz_log (LOG_FATAL|LOG_ERRNO, "_beginthread failed");
+ exit (1);
+ }
+#else
+ pthread_t type;
+
+ int id = pthread_create (&type, 0, events, socket_observable);
+ yaz_log (LOG_LOG, "pthread_create returned id=%d", id);
+#endif
+}
/*
- * Copyright (c) 1998-2000, Index Data.
+ * Copyright (c) 1998-2001, Index Data.
* See the file LICENSE for details.
*
* $Log: yaz-pdu-assoc.cpp,v $
- * Revision 1.22 2001-01-29 11:18:24 adam
+ * Revision 1.23 2001-03-26 14:43:49 adam
+ * New threaded PDU association.
+ *
+ * Revision 1.22 2001/01/29 11:18:24 adam
* Server sets OPTIONS search and present.
*
* Revision 1.21 2000/11/20 14:17:36 adam
*/
#include <assert.h>
+#include <string.h>
+#include <yaz/log.h>
+#include <yaz/tcpip.h>
#include <yaz++/yaz-pdu-assoc.h>
-#include <yaz/log.h>
-#include <yaz/tcpip.h>
-Yaz_PDU_Assoc::Yaz_PDU_Assoc(IYazSocketObservable *socketObservable)
+void Yaz_PDU_Assoc::init(IYazSocketObservable *socketObservable)
{
m_state = Closed;
m_cs = 0;
m_next = 0;
m_destroyed = 0;
m_idleTime = 0;
- m_log = LOG_LOG;
+ m_log = LOG_DEBUG;
+}
+
+Yaz_PDU_Assoc::Yaz_PDU_Assoc(IYazSocketObservable *socketObservable)
+{
+ init (socketObservable);
+}
+
+Yaz_PDU_Assoc::Yaz_PDU_Assoc(IYazSocketObservable *socketObservable,
+ COMSTACK cs)
+{
+ init(socketObservable);
+ m_cs = cs;
+ unsigned mask = 0;
+ if (cs->io_pending & CS_WANT_WRITE)
+ mask |= YAZ_SOCKET_OBSERVE_WRITE;
+ if (cs->io_pending & CS_WANT_READ)
+ mask |= YAZ_SOCKET_OBSERVE_READ;
+ m_socketObservable->addObserver(cs_fileno(cs), this);
+ if (!mask)
+ {
+ yaz_log (m_log, "new PDU_Assoc. Ready");
+ m_state = Ready;
+ flush_PDU();
+ }
+ else
+ {
+ yaz_log (m_log, "new PDU_Assoc. Accepting");
+ // assume comstack is accepting...
+ m_state = Accepting;
+ m_socketObservable->addObserver(cs_fileno(cs), this);
+ m_socketObservable->maskObserver(this,
+ mask |YAZ_SOCKET_OBSERVE_EXCEPT);
+ }
}
+
IYaz_PDU_Observable *Yaz_PDU_Assoc::clone()
{
Yaz_PDU_Assoc *copy = new Yaz_PDU_Assoc(m_socketObservable);
void Yaz_PDU_Assoc::socketNotify(int event)
{
- logf (m_log, "Yaz_PDU_Assoc::socketNotify p=%p event = %d", this, event);
+ yaz_log (m_log, "Yaz_PDU_Assoc::socketNotify p=%p state=%d event = %d",
+ this, m_state, event);
+ if (event & YAZ_SOCKET_OBSERVE_EXCEPT)
+ {
+ close();
+ m_PDU_Observer->failNotify();
+ return;
+ }
+ else if (event & YAZ_SOCKET_OBSERVE_TIMEOUT)
+ {
+ m_PDU_Observer->timeoutNotify();
+ return;
+ }
switch (m_state)
{
+ case Accepting:
+ if (!cs_accept (m_cs))
+ {
+ yaz_log (m_log, "Yaz_PDU_Assoc::cs_accept failed");
+ m_cs = 0;
+ close();
+ m_PDU_Observer->failNotify();
+ }
+ else
+ {
+ unsigned mask = 0;
+ if (m_cs->io_pending & CS_WANT_WRITE)
+ mask |= YAZ_SOCKET_OBSERVE_WRITE;
+ if (m_cs->io_pending & CS_WANT_READ)
+ mask |= YAZ_SOCKET_OBSERVE_READ;
+ if (!mask)
+ { // accept is complete. turn to ready state and write if needed
+ m_state = Ready;
+ flush_PDU();
+ }
+ else
+ { // accept still incomplete.
+ m_socketObservable->maskObserver(this,
+ mask|YAZ_SOCKET_OBSERVE_EXCEPT);
+ }
+ }
+ break;
case Connecting:
- if (event & (YAZ_SOCKET_OBSERVE_READ|YAZ_SOCKET_OBSERVE_EXCEPT))
+ if (event & YAZ_SOCKET_OBSERVE_READ &&
+ event & YAZ_SOCKET_OBSERVE_WRITE)
{
+ // For Unix: if both read and write is set, then connect failed.
close();
m_PDU_Observer->failNotify();
}
- else if (event & YAZ_SOCKET_OBSERVE_TIMEOUT)
- {
- m_PDU_Observer->timeoutNotify();
- }
- else
+ else
{
- m_state = Ready;
- m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_READ|
- YAZ_SOCKET_OBSERVE_EXCEPT);
- m_PDU_Observer->connectNotify();
- flush_PDU();
+ yaz_log (m_log, "cs_connect again");
+ int res = cs_connect (m_cs, 0);
+ if (res == 1)
+ {
+ unsigned mask = YAZ_SOCKET_OBSERVE_EXCEPT;
+ if (m_cs->io_pending & CS_WANT_WRITE)
+ mask |= YAZ_SOCKET_OBSERVE_WRITE;
+ if (m_cs->io_pending & CS_WANT_READ)
+ mask |= YAZ_SOCKET_OBSERVE_READ;
+ m_socketObservable->maskObserver(this, mask);
+ }
+ else
+ {
+ m_state = Ready;
+ m_PDU_Observer->connectNotify();
+ flush_PDU();
+ }
}
break;
case Listen:
return;
if (res < 0)
{
- logf(LOG_FATAL|LOG_ERRNO, "cs_listen failed");
+ yaz_log(LOG_FATAL|LOG_ERRNO, "cs_listen failed");
return;
}
if (!(new_line = cs_accept(m_cs)))
setup observer for child fileid in pdu-assoc
4. start thread
*/
- int fd = cs_fileno(new_line);
- logf (m_log, "accept ok fd = %d", fd);
- cs_fileno(new_line) = -1;
- cs_close (new_line);
- childNotify(fd);
+ childNotify (new_line);
}
break;
+ case Writing:
+ if (event & (YAZ_SOCKET_OBSERVE_READ|YAZ_SOCKET_OBSERVE_WRITE))
+ flush_PDU();
+ break;
case Ready:
- if (event & YAZ_SOCKET_OBSERVE_WRITE)
- {
- flush_PDU();
- }
- if (event & YAZ_SOCKET_OBSERVE_READ)
+ if (event & (YAZ_SOCKET_OBSERVE_READ|YAZ_SOCKET_OBSERVE_WRITE))
{
do
{
int res = cs_get (m_cs, &m_input_buf, &m_input_len);
if (res == 1)
+ {
+ unsigned mask = YAZ_SOCKET_OBSERVE_EXCEPT;
+ if (m_cs->io_pending & CS_WANT_WRITE)
+ mask |= YAZ_SOCKET_OBSERVE_WRITE;
+ if (m_cs->io_pending & CS_WANT_READ)
+ mask |= YAZ_SOCKET_OBSERVE_READ;
+ m_socketObservable->maskObserver(this, mask);
return;
+ }
else if (res <= 0)
{
- logf (m_log, "Connection closed by peer");
+ yaz_log (m_log, "Yaz_PDU_Assoc::Connection closed by peer");
close();
m_PDU_Observer->failNotify(); // problem here..
return;
if (destroyed) // it really was destroyed, return now.
return;
} while (m_cs && cs_more (m_cs));
- }
- if (event & YAZ_SOCKET_OBSERVE_TIMEOUT)
- {
- m_PDU_Observer->timeoutNotify();
+ if (m_cs)
+ m_socketObservable->maskObserver(this,
+ YAZ_SOCKET_OBSERVE_EXCEPT|
+ YAZ_SOCKET_OBSERVE_READ);
}
break;
case Closed:
{
int r;
- logf (m_log, "Yaz_PDU_Assoc::flush_PDU");
- if (m_state != Ready)
+ if (m_state != Ready && m_state != Writing)
{
logf (m_log, "YAZ_PDU_Assoc::flush_PDU, not ready");
return 1;
PDU_Queue *q = m_queue_out;
if (!q)
{
+ m_state = Ready;
+ logf (m_log, "YAZ_PDU_Assoc::flush_PDU queue empty");
m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_READ|
+ YAZ_SOCKET_OBSERVE_WRITE|
YAZ_SOCKET_OBSERVE_EXCEPT);
return 0;
}
r = cs_put (m_cs, q->m_buf, q->m_len);
if (r < 0)
{
+ logf (m_log, "Yaz_PDU_Assoc::flush_PDU cs_put failed");
close();
m_PDU_Observer->failNotify();
return r;
}
if (r == 1)
{
- m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_READ|
- YAZ_SOCKET_OBSERVE_EXCEPT|
- YAZ_SOCKET_OBSERVE_WRITE);
- logf (m_log, "Yaz_PDU_Assoc::flush_PDU put %d bytes (incomplete)",
+ unsigned mask = YAZ_SOCKET_OBSERVE_EXCEPT;
+ m_state = Writing;
+ if (m_cs->io_pending & CS_WANT_WRITE)
+ mask |= YAZ_SOCKET_OBSERVE_WRITE;
+ if (m_cs->io_pending & CS_WANT_READ)
+ mask |= YAZ_SOCKET_OBSERVE_READ;
+
+ m_socketObservable->maskObserver(this, mask);
+ logf (m_log, "Yaz_PDU_Assoc::flush_PDU cs_put %d bytes (incomplete)",
q->m_len);
return r;
- }
- logf (m_log, "Yaz_PDU_Assoc::flush_PDU put %d bytes", q->m_len);
+ }
+ m_state = Ready;
+ logf (m_log, "Yaz_PDU_Assoc::flush_PDU cs_put %d bytes", q->m_len);
// whole packet sent... delete this and proceed to next ...
m_queue_out = q->m_next;
delete q;
return 0;
}
-COMSTACK Yaz_PDU_Assoc::comstack()
+COMSTACK Yaz_PDU_Assoc::comstack(const char *type_and_host, void **vp)
{
- if (!m_cs)
- {
- CS_TYPE cs_type = tcpip_type;
- m_cs = cs_create (cs_type, 0, PROTO_Z3950);
- }
- return m_cs;
+ return cs_create_host(type_and_host, 0, vp);
}
void Yaz_PDU_Assoc::listen(IYaz_PDU_Observer *observer,
const char *addr)
{
close();
- void *ap;
- COMSTACK cs = comstack();
- logf (m_log, "Yaz_PDU_Assoc::listen %s", addr);
+ logf (LOG_LOG, "Adding listener %s", addr);
+
m_PDU_Observer = observer;
- if (!cs)
- return;
- ap = cs_straddr (cs, addr);
- if (!ap)
+ void *ap;
+ m_cs = comstack(addr, &ap);
+
+ if (!m_cs)
return;
- if (cs_bind(cs, ap, CS_SERVER) < 0)
+ if (cs_bind(m_cs, ap, CS_SERVER) < 0)
return;
- m_socketObservable->addObserver(cs_fileno(cs), this);
+ m_socketObservable->addObserver(cs_fileno(m_cs), this);
m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_READ|
YAZ_SOCKET_OBSERVE_EXCEPT);
- logf (m_log, "Yaz_PDU_Assoc::listen ok fd=%d", cs_fileno(cs));
+ logf (m_log, "Yaz_PDU_Assoc::listen ok fd=%d", cs_fileno(m_cs));
m_state = Listen;
}
logf (m_log, "Yaz_PDU_Assoc::connect %s", addr);
close();
m_PDU_Observer = observer;
- COMSTACK cs = comstack();
- void *ap = cs_straddr (cs, addr);
- if (!ap)
- {
- logf (m_log, "cs_straddr failed");
- return;
- }
- int res = cs_connect (cs, ap);
- logf (m_log, "Yaz_PDU_Assoc::connect fd=%d res=%d", cs_fileno(cs), res);
- m_socketObservable->addObserver(cs_fileno(cs), this);
- m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_READ|
- YAZ_SOCKET_OBSERVE_EXCEPT|
- YAZ_SOCKET_OBSERVE_WRITE);
+ void *ap;
+ m_cs = comstack(addr, &ap);
+ int res = cs_connect (m_cs, ap);
+ logf (m_log, "Yaz_PDU_Assoc::connect fd=%d res=%d", cs_fileno(m_cs), res);
+ m_socketObservable->addObserver(cs_fileno(m_cs), this);
+
if (res >= 0)
+ { // Connect pending or complet
m_state = Connecting;
- // if res < 0, then cs_connect failed immediately -> m_state is Closed..
-}
-
-void Yaz_PDU_Assoc::socket(IYaz_PDU_Observer *observer, int fd)
-{
- close();
- m_PDU_Observer = observer;
- if (fd >= 0)
- {
- CS_TYPE cs_type = tcpip_type;
- m_cs = cs_createbysocket(fd, cs_type, 0, PROTO_Z3950);
- m_state = Ready;
- m_socketObservable->addObserver(fd, this);
- m_socketObservable->maskObserver(this,
- YAZ_SOCKET_OBSERVE_READ|
+ unsigned mask = YAZ_SOCKET_OBSERVE_EXCEPT;
+ if (m_cs->io_pending & CS_WANT_WRITE)
+ mask |= YAZ_SOCKET_OBSERVE_WRITE;
+ if (m_cs->io_pending & CS_WANT_READ)
+ mask |= YAZ_SOCKET_OBSERVE_READ;
+ m_socketObservable->maskObserver(this, mask);
+ }
+ else
+ { // Connect failed immediately
+ // Since m_state is Closed we can distinguish this case from
+ // normal connect in socketNotify handler
+ m_socketObservable->maskObserver(this, YAZ_SOCKET_OBSERVE_WRITE|
YAZ_SOCKET_OBSERVE_EXCEPT);
- m_socketObservable->timeoutObserver(this, m_idleTime);
}
}
-#if 1
- // 1 = single-threaded
- // 0 = multi-threaded
-
// Single-threaded... Only useful for non-blocking handlers
-void Yaz_PDU_Assoc::childNotify(int fd)
-{
- // Clone PDU Observable (keep socket manager)
- IYaz_PDU_Observable *new_observable = clone();
-
- // Clone PDU Observer
- IYaz_PDU_Observer *observer = m_PDU_Observer->clone(new_observable, fd);
-
- // Attach new socket to it
- new_observable->socket(observer, fd);
-}
-#else
-
-#include <yaz++/yaz-socket-manager.h>
-
-#ifdef WIN32
-#include <process.h>
-#else
-#include <pthread.h>
-#endif
-
-#ifdef WIN32
-void __cdecl
-#else
-void *
-#endif
- events(void *p)
-{
- Yaz_SocketManager *s = (Yaz_SocketManager *) p;
-
- logf (LOG_LOG, "thread started");
- while (s->processEvent() > 0)
- ;
- logf (LOG_LOG, "thread finished");
-#ifdef WIN32
-#else
- return 0;
-#endif
-}
-
-void Yaz_PDU_Assoc::childNotify(int fd)
+void Yaz_PDU_Assoc::childNotify(COMSTACK cs)
{
- Yaz_SocketManager *socket_observable = new Yaz_SocketManager;
- Yaz_PDU_Assoc *new_observable = new Yaz_PDU_Assoc (socket_observable);
+ Yaz_PDU_Assoc *new_observable =
+ new Yaz_PDU_Assoc (m_socketObservable, cs);
- /// Clone PDU Observer
- IYaz_PDU_Observer *observer = m_PDU_Observer->clone(new_observable, fd);
-
- /// Attach new socket to it
- new_observable->socket(observer, fd);
-
-#ifdef WIN32
- long t_id;
- t_id = _beginthread (events, 0, socket_observable);
- if (t_id == -1)
- {
- logf (LOG_FATAL|LOG_ERRNO, "_beginthread failed");
- exit (1);
- }
-#else
- pthread_t type;
-
- int id = pthread_create (&type, 0, events, socket_observable);
- logf (LOG_LOG, "pthread_create returned id=%d", id);
-#endif
+ // Clone PDU Observer
+ new_observable->m_PDU_Observer = m_PDU_Observer->sessionNotify
+ (new_observable, cs_fileno(cs));
}
-// Threads end
-#endif
/*
- * Copyright (c) 1998-2000, Index Data.
+ * Copyright (c) 1998-2001, Index Data.
* See the file LICENSE for details.
*
* $Log: yaz-proxy.cpp,v $
- * Revision 1.22 2000-11-20 11:27:33 adam
+ * Revision 1.23 2001-03-26 14:43:49 adam
+ * New threaded PDU association.
+ *
+ * Revision 1.22 2000/11/20 11:27:33 adam
* Fixes for connect operation (timeout and notify fix).
*
* Revision 1.21 2000/11/01 14:22:59 adam
m_proxyTarget = (char *) xstrdup (target);
}
-IYaz_PDU_Observer *Yaz_Proxy::clone(IYaz_PDU_Observable
- *the_PDU_Observable, int fd)
+IYaz_PDU_Observer *Yaz_Proxy::sessionNotify(IYaz_PDU_Observable
+ *the_PDU_Observable, int fd)
{
Yaz_Proxy *new_proxy = new Yaz_Proxy(the_PDU_Observable);
new_proxy->m_parent = this;
timeout(600);
}
-IYaz_PDU_Observer *Yaz_ProxyClient::clone(IYaz_PDU_Observable
- *the_PDU_Observable, int fd)
+IYaz_PDU_Observer *Yaz_ProxyClient::sessionNotify(IYaz_PDU_Observable
+ *the_PDU_Observable, int fd)
{
return new Yaz_ProxyClient(the_PDU_Observable);
}
/*
- * Copyright (c) 1998-2000, Index Data.
+ * Copyright (c) 1998-2001, Index Data.
* See the file LICENSE for details.
*
* $Log: yaz-server.cpp,v $
- * Revision 1.14 2000-11-01 14:22:59 adam
+ * Revision 1.15 2001-03-26 14:43:49 adam
+ * New threaded PDU association.
+ *
+ * Revision 1.14 2000/11/01 14:22:59 adam
* Added fd parameter for method IYaz_PDU_Observer::clone.
*
* Revision 1.13 2000/10/11 11:58:16 adam
Z_RecordComposition *comp,
Z_NamePlusRecord *namePlusRecord,
Z_Records *records);
- IYaz_PDU_Observer* clone(IYaz_PDU_Observable *the_PDU_Observable,
- int fd);
+ IYaz_PDU_Observer* sessionNotify(IYaz_PDU_Observable *the_PDU_Observable,
+ int fd);
void failNotify();
void timeoutNotify();
void connectNotify();
void MyServer::recv_Z_init (Z_InitRequest *initRequest,
Z_InitResponse *initResponse)
{
- logf (LOG_LOG, "MyServer::recv_Z_init");
+ yaz_log (LOG_LOG, "MyServer::recv_Z_init");
}
static MyServer *myServer = 0;
void MyServer::recv_Z_search (Z_SearchRequest *searchRequest,
Z_SearchResponse *searchResponse)
{
- logf (LOG_LOG, "MyServer::recv_Z_search");
+ yaz_log (LOG_LOG, "MyServer::recv_Z_search");
if (searchRequest->query->which == Z_Query_type_1)
{
Z_RPNStructure *s = searchRequest->query->u.type_1->RPNStructure;
void MyServer::recv_Z_present (Z_PresentRequest *presentRequest,
Z_PresentResponse *presentResponse)
{
- logf (LOG_LOG, "MyServer::recv_Z_present");
+ yaz_log (LOG_LOG, "MyServer::recv_Z_present");
}
void MyServer::recv_Z_record (const char *resultSetName,
Z_NamePlusRecord *namePlusRecord,
Z_Records *records)
{
- logf (LOG_LOG, "MyServer::recv_Z_record");
+ yaz_log (LOG_LOG, "MyServer::recv_Z_record");
int max = sizeof(marc_records) / sizeof(*marc_records);
int eff_pos = (position-1) % max;
create_databaseRecord (namePlusRecord, 0, VAL_USMARC,
strlen(marc_records[eff_pos]));
}
-IYaz_PDU_Observer *MyServer::clone(IYaz_PDU_Observable *the_PDU_Observable,
- int fd)
+IYaz_PDU_Observer *MyServer::sessionNotify(
+ IYaz_PDU_Observable *the_PDU_Observable, int fd)
{
MyServer *new_server;
- logf (LOG_LOG, "child no %d", m_no);
m_no++;
new_server = new MyServer(the_PDU_Observable);
new_server->timeout(900);
void MyServer::timeoutNotify()
{
- logf (LOG_LOG, "connection timed out");
+ yaz_log (LOG_LOG, "connection timed out");
delete this;
}
void MyServer::failNotify()
{
- logf (LOG_LOG, "connection closed by client");
+ yaz_log (LOG_LOG, "connection closed by client");
delete this;
}
while (1)
{
Yaz_SocketManager mySocketManager;
- Yaz_PDU_Assoc *my_PDU_Assoc = new Yaz_PDU_Assoc(&mySocketManager);
+ Yaz_PDU_AssocThread *my_PDU_Assoc = new Yaz_PDU_AssocThread(&mySocketManager);
myServer = new MyServer(my_PDU_Assoc);
* See the file LICENSE for details.
*
* $Log: yaz-socket-manager.cpp,v $
- * Revision 1.14 2000-11-20 14:17:36 adam
+ * Revision 1.15 2001-03-26 14:43:49 adam
+ * New threaded PDU association.
+ *
+ * Revision 1.14 2000/11/20 14:17:36 adam
* Yet another WIN32 fix for connect notify.
*
* Revision 1.13 2000/11/20 11:27:33 adam
YazSocketEntry *p;
YazSocketEvent *event = getEvent();
unsigned timeout = 0;
- logf (m_log, "processEvent");
+ logf (m_log, "Yaz_SocketManager::processEvent manager=%p", this);
if (event)
{
event->observer->socketNotify(event->event);
no++;
if (p->mask & YAZ_SOCKET_OBSERVE_READ)
{
- yaz_log (m_log, "select fd=%d: read fd", fd);
+ yaz_log (m_log, "Yaz_SocketManager::select fd=%d read", fd);
FD_SET(fd, &in);
}
if (p->mask & YAZ_SOCKET_OBSERVE_WRITE)
{
- yaz_log (m_log, "select fd=%d: write fd", fd);
+ yaz_log (m_log, "Yaz_SocketManager::select fd=%d write", fd);
FD_SET(fd, &out);
}
if (p->mask & YAZ_SOCKET_OBSERVE_EXCEPT)
{
- yaz_log (m_log, "select fd=%d: except fd", fd);
+ yaz_log (m_log, "Yaz_SocketManager::select fd=%d except", fd);
FD_SET(fd, &except);
}
if (fd > max)
to.tv_sec = timeout;
to.tv_usec = 0;
- logf (m_log, "select pending=%d timeout=%d", no, timeout);
+ logf (m_log, "Yaz_SocketManager::select no=%d timeout=%d", no, timeout);
while ((res = select(max + 1, &in, &out, &except, timeout ? &to : 0)) < 0)
if (errno != EINTR)
return -1;
* See the file LICENSE for details.
*
* $Log: yaz-z-assoc.cpp,v $
- * Revision 1.17 2001-01-04 14:25:25 heikki
+ * Revision 1.18 2001-03-26 14:43:49 adam
+ * New threaded PDU association.
+ *
+ * Revision 1.17 2001/01/04 14:25:25 heikki
* No SIGPIPES in windows...
*
* Revision 1.16 2000/12/14 16:00:39 adam
{
recv_Z_PDU (apdu);
}
+ else
+ {
+ close();
+ }
}
Z_APDU *Yaz_Z_Assoc::create_Z_PDU(int type)
/*
- * Copyright (c) 2000, Index Data.
+ * Copyright (c) 2000-2001, Index Data.
* See the file LICENSE for details.
*
* $Log: yaz-z-server.cpp,v $
- * Revision 1.6 2001-01-29 11:18:24 adam
+ * Revision 1.7 2001-03-26 14:43:49 adam
+ * New threaded PDU association.
+ *
+ * Revision 1.6 2001/01/29 11:18:24 adam
* Server sets OPTIONS search and present.
*
* Revision 1.5 2000/10/24 12:29:57 adam
switch (apdu_request->which)
{
case Z_APDU_initRequest:
- logf (LOG_LOG, "got InitRequest p=%p", this);
+ yaz_log (LOG_LOG, "got InitRequest p=%p", this);
apdu_response = create_Z_PDU(Z_APDU_initResponse);
req = apdu_request->u.initRequest->options;
res = apdu_response->u.initResponse->options;
send_Z_PDU(apdu_response);
break;
case Z_APDU_searchRequest:
- logf (LOG_LOG, "got SearchRequest p=%p", this);
+ yaz_log (LOG_LOG, "got SearchRequest p=%p", this);
apdu_response = create_Z_PDU(Z_APDU_searchResponse);
recv_Z_search (apdu_request->u.searchRequest,
apdu_response->u.searchResponse);
send_Z_PDU(apdu_response);
break;
case Z_APDU_presentRequest:
- logf (LOG_LOG, "got PresentRequest p=%p", this);
+ yaz_log (LOG_LOG, "got PresentRequest p=%p", this);
apdu_response = create_Z_PDU(Z_APDU_presentResponse);
recv_Z_present (apdu_request->u.presentRequest,
apdu_response->u.presentResponse);
#!/bin/sh
-# $Id: yaz++-config.in,v 1.2 2000-10-11 12:21:00 adam Exp $
+# $Id: yaz++-config.in,v 1.3 2001-03-26 14:43:49 adam Exp $
yazppprefix=@prefix@
yaz_echo_cflags=no
yaz_echo_libs=no
yaz_echo_source=yes
yaz_echo_lalibs=no
yazpp_src_root=@YAZPP_SRC_ROOT@
+yazpp_build_root=@YAZPP_BUILD_ROOT@
yazlibs="@YAZLIB@ @LIBS@"
YAZPPVERSION=@VERSION@
done
if test "$yaz_echo_source" = "yes"; then
- YAZPPLIB="-L${yazpp_src_root}/src/.libs -lyaz++ $yazlibs"
- YAZPPLALIB="${yazpp_src_root}/src/libyaz++.la $yazlibs"
+ YAZPPLIB="-L${yazpp_build_root}/src/.libs -lyaz++ $yazlibs"
+ YAZPPLALIB="${yazpp_build_root}/src/libyaz++.la $yazlibs"
YAZPPINC="@YAZINC@ -I${yazpp_src_root}/include"
else
-## $Id: yaz.m4,v 1.1 2001-02-21 11:25:07 adam Exp $
+## $Id: yaz.m4,v 1.2 2001-03-26 14:43:49 adam Exp $
##
# Use this m4 funciton for autoconf if you use YAZ in your own
# configure script.
if test "x$yazpath" != "xNONE"; then
yazconfig=$yazpath/yaz-config
else
- for i in ../yaz* ../yaz; do
+ if test "x$srcdir" = "x"; then
+ yazsrcdir=.
+ else
+ yazsrcdir=$srcdir
+ fi
+ for i in ${yazsrcdir}/../yaz* ${yazsrcdir}/../yaz; do
if test -d $i; then
if test -r $i/yaz-config; then
yazconfig=$i/yaz-config