"Fossies" - the Fresh Open Source Software Archive

Member "ivtools-ivtools-2.0.4/src/DrawServ/ackback-handler.c" (9 Oct 2020, 5077 Bytes) of package /linux/misc/ivtools-ivtools-2.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ackback-handler.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2004 Scott E. Johnston
    3  *
    4  * Permission to use, copy, modify, distribute, and sell this software and
    5  * its documentation for any purpose is hereby granted without fee, provided
    6  * that the above copyright notice appear in all copies and that both that
    7  * copyright notice and this permission notice appear in supporting
    8  * documentation, and that the names of the copyright holders not be used in
    9  * advertising or publicity pertaining to distribution of the software
   10  * without specific, written prior permission.  The copyright holders make
   11  * no representations about the suitability of this software for any purpose.
   12  * It is provided "as is" without express or implied warranty.
   13  *
   14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
   15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
   16  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
   17  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
   18  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
   19  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
   20  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   21  * 
   22  */
   23 
   24 #ifdef HAVE_ACE
   25 
   26 #include <iosfwd>
   27 using namespace std;
   28 #include <vector>
   29 #include <err.h>
   30 
   31 #ifdef __llvm__
   32 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   33 #endif
   34 
   35 #include <DrawServ/ackback-handler.h>
   36 #include <DrawServ/draweditor.h>
   37 #include <DrawServ/drawkit.h>
   38 #include <DrawServ/drawlink.h>
   39 #include <DrawServ/drawserv.h>
   40 
   41 #include <IVGlyph/gdialogs.h>
   42 #include <InterViews/window.h>
   43 
   44 #include <iostream.h>
   45 
   46 /*****************************************************************************/
   47 
   48 // Default constructor.
   49 
   50 AckBackHandler::AckBackHandler ()
   51 {
   52   _timer_started = false;
   53   _ackback_arrived = false;
   54   _eof_expected = false;
   55 }
   56 
   57 AckBackHandler::~AckBackHandler() {
   58   fprintf(stderr, "AckBackHandler deleted\n");
   59 }
   60 
   61 // Called when input becomes available on fd.
   62 
   63 int AckBackHandler::handle_input (ACE_HANDLE fd)
   64 {
   65   if (drawlink() && drawlink()->socket()) {
   66     vector<char> inv;
   67     char ch;
   68     int status;
   69     while((status = read(fd, &ch, 1))==1) inv.push_back(ch);
   70     inv.push_back('\0');
   71     if (strcmp((char*)&inv[0], "ackback(cycle)\n")==0) {
   72       char buffer[BUFSIZ];
   73       snprintf(buffer, BUFSIZ, "%s:%d", drawlink()->hostname(), drawlink()->portnum());
   74       GAcknowledgeDialog::map(DrawKit::Instance()->GetEditor()->GetWindow(), "Redundant connection rejected", buffer, "Redundant connection rejected");
   75       _eof_expected = true;
   76     }
   77     if (status == 0) {
   78       if (!_eof_expected) {
   79     char buffer[BUFSIZ];
   80     snprintf(buffer, BUFSIZ, "%s:%d", drawlink()->hostname(), drawlink()->portnum());
   81     GAcknowledgeDialog::map(DrawKit::Instance()->GetEditor()->GetWindow(), "Unexpected end-of-file on connection", buffer, "Unexpected end-of-file on connection");
   82       } else
   83     _eof_expected = false;
   84       cerr << "AckBack (end of file):  [" << (char*)&inv[0] << "]\n";
   85       drawlink()->ackhandler(nil);
   86       ((DrawServ*)unidraw)->linkdown(drawlink());
   87       return -1;
   88     } else if (errno != EAGAIN)
   89       warn(nil);
   90     else {
   91       cerr << "AckBack:  [" << (char*)&inv[0] << "]\n";
   92       _ackback_arrived = true;
   93     }
   94     return 0;
   95   } else {
   96     fprintf(stderr, "unexpected missing socket\n");
   97     return -1;
   98   }
   99 }
  100 
  101 void AckBackHandler::start_timer() {
  102   if (!_timer_started) {
  103     _timerid = ComterpHandler::reactor_singleton()->schedule_timer
  104       (this, (const void *) this, ACE_Time_Value (5), ACE_Time_Value (5));
  105     _timer_started = true;
  106     _ackback_arrived = false;
  107   }
  108 
  109 }
  110 
  111 int AckBackHandler::handle_timeout (const ACE_Time_Value &,
  112                     const void *arg)
  113 {
  114   if(_timer_started && !ComterpHandler::reactor_singleton()->cancel_timer(_timerid, nil))
  115     cerr << "unable to cancel timerid " << _timerid << "\n";
  116   _timer_started = false;
  117   if (!_ackback_arrived) {
  118     fprintf(stderr, "ackback timeout\n");
  119     drawlink()->ackhandler(nil);
  120     ((DrawServ*)unidraw)->linkdown(drawlink());
  121     return -1;
  122   }
  123 
  124   return 0;
  125 }
  126 
  127 // Get the I/O handle.
  128 ACE_HANDLE AckBackHandler::get_handle (void) const {
  129   return _handle;
  130 }
  131 
  132  // Set the I/O handle.
  133 void AckBackHandler::set_handle (ACE_HANDLE handle) {
  134   _handle = handle;
  135 }
  136 
  137 
  138 // Called when the object is about to be removed from the Dispatcher
  139 // tables.
  140 
  141 int  AckBackHandler::handle_close (ACE_HANDLE handle, ACE_Reactor_Mask mask)
  142 {
  143   fprintf(stderr, "AckBackHandler::handle_close called with mask 0x%lx\n", mask);
  144   if(_timer_started && !ComterpHandler::reactor_singleton()->cancel_timer(_timerid, nil))
  145     cerr << "unable to cancel timerid " << _timerid << "\n";
  146   else
  147     _timer_started = false;
  148   if (mask == ACE_Event_Handler::TIMER_MASK || mask == ACE_Event_Handler::READ_MASK) {
  149     if (mask == ACE_Event_Handler::TIMER_MASK)
  150       if (ComterpHandler::reactor_singleton()->remove_handler(this, ACE_Event_Handler::READ_MASK|ACE_Event_Handler::TIMER_MASK)==-1)
  151     cerr << "drawserv: error removing ackback handler\n";
  152     delete this;
  153   }
  154   
  155   return 0;
  156 }
  157 
  158 #endif /* HAVE_ACE */