00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4StatusRunnable.h"
00017
00018 #include "Riostream.h"
00019 #include <signal.h>
00020
00021 #include "TGo4Log.h"
00022 #include "TGo4ThreadManager.h"
00023 #include "TGo4Thread.h"
00024 #include "TGo4BufferQueue.h"
00025 #include "TGo4Socket.h"
00026 #include "TGo4SocketSignalHandler.h"
00027 #include "TGo4TaskHandler.h"
00028 #include "TGo4TaskHandlerAbortException.h"
00029
00030 TGo4StatusRunnable::TGo4StatusRunnable(const char* name, TGo4ThreadManager* man, TGo4TaskHandler* hand, Bool_t receivermode) :
00031 TGo4TaskHandlerRunnable(name,man,hand,receivermode)
00032 {
00033 fxBufferQueue = dynamic_cast<TGo4BufferQueue*> (fxTaskHandler->GetStatusQueue() );
00034 fxTransport = fxTaskHandler->GetStatusTransport();
00035 }
00036
00037
00038 TGo4StatusRunnable::~TGo4StatusRunnable()
00039 {
00040 }
00041
00042 Int_t TGo4StatusRunnable::Run(void* ptr)
00043 {
00044 if(!CheckTransportOpen()) return 0;
00045 if(fbReceiverMode)
00046 {
00047
00048 Int_t rev = fxTransport->ReceiveBuffer();
00049 if(rev>=0)
00050 {
00051 TBuffer* buf=const_cast<TBuffer*> (fxTransport->GetBuffer());
00052 if(CheckStopBuffer(buf)) return 0;
00053 fxBufferQueue->AddBuffer(buf, kTRUE);
00054 }
00055 else
00056 {
00057 if (TGo4SocketSignalHandler::GetLastSignal() == SIGWINCH)
00058 {
00059
00060 TGo4Log::Debug(" %s: caught SIGWINCH ",GetName());
00061 TGo4SocketSignalHandler::SetLastSignal(0);
00062 }
00063 else if(fxManager->IsTerminating())
00064 {
00065
00066 TGo4Log::Debug("Receive Error in %s during threadmanager termination. Ignored.",GetName());
00067 GetThread()->Stop();
00068 }
00069 else
00070 {
00071 TGo4Log::Debug(" !!!Receive Error in %s!!!",
00072 GetName());
00073
00074 throw TGo4TaskHandlerAbortException(this);
00075 }
00076 }
00077
00078 }
00079 else
00080 {
00081
00082
00083 TBuffer* buf= fxBufferQueue->WaitBuffer();
00084 if (buf)
00085
00086 {
00087 CheckStopBuffer(buf);
00088 fxTransport->SendBuffer(buf);
00089 fxBufferQueue->FreeBuffer(buf);
00090 }
00091 }
00092
00093
00094 return 0;
00095 }
00096
00097
00098