X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;ds=sidebyside;f=src%2Fyaz-pdu-assoc-thread.cpp;h=54d2cf07aa2a33128d49b54f0642627fb55508c1;hb=86726b00b052694e65b036c262f5fe9096554175;hp=5f7a20ec5539c254f7a611c09e3c46f1639e1117;hpb=bd71f8812ca0f38438733efc89ecce1f49dae9e7;p=yazpp-moved-to-github.git diff --git a/src/yaz-pdu-assoc-thread.cpp b/src/yaz-pdu-assoc-thread.cpp index 5f7a20e..54d2cf0 100644 --- a/src/yaz-pdu-assoc-thread.cpp +++ b/src/yaz-pdu-assoc-thread.cpp @@ -1,18 +1,23 @@ /* - * Copyright (c) 1998-2001, Index Data. + * Copyright (c) 1998-2004, 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. - * + * $Id: yaz-pdu-assoc-thread.cpp,v 1.10 2005-06-02 06:40:21 adam Exp $ */ -#include -#include +#ifdef WIN32 +#define USE_THREADS 1 +#endif -#include -#include +#if YAZ_POSIX_THREADS +#define USE_THREADS 1 +#endif + +#if USE_THREADS + +#if HAVE_UNISTD_H +#include +#endif #ifdef WIN32 #include @@ -21,6 +26,15 @@ #endif +#include +#include +#include + +#include +#include + +using namespace yazpp_1; + Yaz_PDU_AssocThread::Yaz_PDU_AssocThread( IYazSocketObservable *socketObservable) : Yaz_PDU_Assoc(socketObservable) @@ -37,10 +51,10 @@ events(void *p) { Yaz_SocketManager *s = (Yaz_SocketManager *) p; - logf (LOG_LOG, "thread started"); + yaz_log (YLOG_LOG, "thread started"); while (s->processEvent() > 0) ; - logf (LOG_LOG, "thread finished"); + yaz_log (YLOG_LOG, "thread finished"); #ifdef WIN32 #else return 0; @@ -51,7 +65,11 @@ 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); - + + new_observable->m_next = m_children; + m_children = new_observable; + new_observable->m_parent = this; + /// Clone PDU Observer new_observable->m_PDU_Observer = m_PDU_Observer->sessionNotify(new_observable, cs_fileno(cs)); @@ -60,13 +78,17 @@ void Yaz_PDU_AssocThread::childNotify(COMSTACK cs) t_id = _beginthread (events, 0, socket_observable); if (t_id == -1) { - yaz_log (LOG_FATAL|LOG_ERRNO, "_beginthread failed"); + yaz_log (YLOG_FATAL|YLOG_ERRNO, "_beginthread failed"); exit (1); } #else - pthread_t type; + pthread_t tid; - int id = pthread_create (&type, 0, events, socket_observable); - yaz_log (LOG_LOG, "pthread_create returned id=%d", id); + int id = pthread_create (&tid, 0, events, socket_observable); + if (id) + yaz_log (YLOG_ERRNO|YLOG_FATAL, "pthread_create returned id=%d", id); + else + pthread_detach (tid); #endif } +#endif