Diff for /Amaya/amaya/AHTBridge.c between versions 1.31 and 1.32

version 1.31, 1997/06/23 16:18:11 version 1.32, 1997/06/24 15:09:09
Line 27 Line 27
 #ifndef _WINDOWS  #ifndef _WINDOWS
 /* Amaya's X appcontext */  /* Amaya's X appcontext */
 extern ThotAppContext app_cont;  extern ThotAppContext app_cont;
 #endif  
   
 /*  /* Private functions */
  * Private functions  
  */  
 #ifdef __STDC__  #ifdef __STDC__
 static void         RequestRegisterReadXtevent (AHTReqContext *, SOCKET);  static void         RequestRegisterReadXtevent (AHTReqContext *, SOCKET);
 static void         RequestKillReadXtevent (AHTReqContext *);  static void         RequestKillReadXtevent (AHTReqContext *);
Line 39  static void         RequestRegisterWrite Line 36  static void         RequestRegisterWrite
 static void         RequestKillWriteXtevent (AHTReqContext *);  static void         RequestKillWriteXtevent (AHTReqContext *);
 static void         RequestRegisterExceptXtevent (AHTReqContext *, SOCKET);  static void         RequestRegisterExceptXtevent (AHTReqContext *, SOCKET);
 static void         RequestKillExceptXtevent (AHTReqContext *);  static void         RequestKillExceptXtevent (AHTReqContext *);
   
 #else /* __STDC__ */  #else /* __STDC__ */
 static void         RequesAddReadXtevent ();  static void         RequesAddReadXtevent ();
 static void         RequestKillReadXtevent ();  static void         RequestKillReadXtevent ();
Line 47  static void         RequesAddWriteXteven Line 43  static void         RequesAddWriteXteven
 static void         RequestKillWriteXtevent ();  static void         RequestKillWriteXtevent ();
 static void         RequestRegisterExceptXtevent ();  static void         RequestRegisterExceptXtevent ();
 static void         RequestKillExceptXtevent ();  static void         RequestKillExceptXtevent ();
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
   
 #ifdef _WINDOWS  
 static void         WIN_ResetMaxSock (void);  
 static int          WIN_ProcessFds (fd_set * fdsp, SockOps ops);  
 #if 0  
 static int          VerifySocketState (AHTReqContext *me, SOCKET sock);  
 PUBLIC LRESULT CALLBACK ASYNCWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
 #endif /* 0 */  
 #endif /* _WINDOWS */  #endif /* _WINDOWS */
   
 /*  /* Private variables */
  * Private variables   
  */  
   
 /*  /*
  * this set of SockOps map our WinSock "socket event SockOps" into    * this set of SockOps map our WinSock "socket event SockOps" into 
Line 71  PUBLIC LRESULT CALLBACK ASYNCWindowProc( Line 56  PUBLIC LRESULT CALLBACK ASYNCWindowProc(
  * if the connection has been closed, the socket will appear readable under   * if the connection has been closed, the socket will appear readable under
  * BSD Unix semantics    * BSD Unix semantics 
  */   */
   
 static const SockOps ReadBits = FD_READ | FD_ACCEPT | FD_CLOSE;  static const SockOps ReadBits = FD_READ | FD_ACCEPT | FD_CLOSE;
 static const SockOps WriteBits = FD_WRITE | FD_CONNECT;  static const SockOps WriteBits = FD_WRITE | FD_CONNECT;
 static const SockOps ExceptBits = FD_OOB;  static const SockOps ExceptBits = FD_OOB;
   
 #ifdef _WINDOWS  /* Private functions */
 static fd_set read_fds, write_fds, except_fds, all_fds;  
 static int maxfds = 0;  
 #endif /* _WINDOWS */  
   
 /*  
  * Private functions  
  */  
   
 /*--------------------------------------------------------------------  /*--------------------------------------------------------------------
   AHTCallback_bridge    AHTCallback_bridge
Line 127  XtInputId          *id; Line 106  XtInputId          *id;
    /* Libwww 5.0a does not take into account the ops parameter     /* Libwww 5.0a does not take into account the ops parameter
       in the invocation of for this function call */        in the invocation of for this function call */
   
 #ifdef HACK_WWW  #  ifdef HACK_WWW
    HTEventCallback    *cbf;     HTEventCallback    *cbf;
   #  else
 #else  
    HTEventCallback    *cbf;     HTEventCallback    *cbf;
   
    ops = FD_WRITE;     ops = FD_WRITE;
    cbf = (HTEventCallback *) __RetrieveCBF (*s, ops, &rqp);     cbf = (HTEventCallback *) __RetrieveCBF (*s, ops, &rqp);
 #endif  #  endif
   
    me = HTRequest_context (rqp);     me = HTRequest_context (rqp);
    if (THD_TRACE)     if (THD_TRACE)
      fprintf (stderr, "AHTBridge: Processing url %s \n", me->urlName);        fprintf (stderr, "AHTBridge: Processing url %s \n", me->urlName);
   
    /* verify if there's any callback associated with the request */     /* verify if there's any callback associated with the request */
    if (!cbf || !rqp || rqp->priority == HT_PRIORITY_OFF)     if (!cbf || !rqp || rqp->priority == HT_PRIORITY_OFF) {
      {        if (THD_TRACE)
         if (THD_TRACE)           HTTrace ("Callback.... No callback found\n");
            HTTrace ("Callback.... No callback found\n");        
         /* experimental */        /* experimental */
         /* remove the Xt input which caused this callback */        /* remove the Xt input which caused this callback */
 #ifdef WWW_XWINDOWS  #     ifdef WWW_XWINDOWS
         XtRemoveInput (*id);        XtRemoveInput (*id);
 #endif  #     endif
         /* put some more code to correctly destroy this request ?*/        /* put some more code to correctly destroy this request ?*/
         return (0);        return (0);
      }     }
   
 #  ifdef _WINDOWS  #  ifdef _WINDOWS
    ops = _ops;     ops = _ops;
 #  else  #  else
    switch ((XtInputId) cd)     switch ((XtInputId) cd) {
          {            case XtInputReadMask:
             case XtInputReadMask:  
                ops = me->read_ops;                 ops = me->read_ops;
                ops = FD_READ;                 ops = FD_READ;
                break;                 break;
             case XtInputWriteMask:            case XtInputWriteMask:
                ops = me->write_ops;                 ops = me->write_ops;
                ops = FD_WRITE;                 ops = FD_WRITE;
                break;                 break;
             case XtInputExceptMask:            case XtInputExceptMask:
                ops = me->except_ops;                 ops = me->except_ops;
                ops = FD_OOB;                 ops = FD_OOB;
                break;                 break;
          default:            default:
            break;                 break;
          }                      /* switch */     } /* switch */
 #  endif /* _WINDOWS */  #  endif /* _WINDOWS */
   
      /* Invokes the callback associated to the requests */     /* Invokes the callback associated to the requests */
           
      /* first we change the status of the request, to say it     /* first we change the status of the request, to say it
         has entered a critical section */        has entered a critical section */
   
      if((HTRequest_outputStream(me->request) == (HTStream *) NULL))     if ((HTRequest_outputStream(me->request) == (HTStream *) NULL))
        fprintf(stderr,"\n **ERROR** opening %s\n\n",me->urlName);        fprintf(stderr,"\n **ERROR** opening %s\n\n",me->urlName);
   
      me->reqStatus = HT_BUSY;     me->reqStatus = HT_BUSY;
      if ((status = (*cbf) (*s, rqp, ops)) != HT_OK)     if ((status = (*cbf) (*s, rqp, ops)) != HT_OK)
        HTTrace ("Callback.... received != HT_OK");        HTTrace ("Callback.... received != HT_OK");
   
    /* Several states can happen after this callback. They     /* Several states can happen after this callback. They
     * are indicated by the me->reqStatus structure member and      * are indicated by the me->reqStatus structure member and
Line 203  XtInputId          *id; Line 180  XtInputId          *id;
     * HT_END:     Request has ended      * HT_END:     Request has ended
     */      */
   
    if (me->reqStatus == HT_ABORT)     if (me->reqStatus == HT_ABORT) {
    /* Has the user stopped the request? */     /* Has the user stopped the request? */
      {        me->reqStatus = HT_WAITING;
         me->reqStatus = HT_WAITING;        StopRequest (me->docid);
         StopRequest (me->docid);        return (0);
         return (0);     }
      }  
   
    if (me->reqStatus == HT_WAITING)     if (me->reqStatus == HT_WAITING) {
    /* the request is being reissued */        /* the request is being reissued */
      {        /*
         /*         * (1) The old request has ended and the library
          * (1) The old request has ended and the library         * assigned the old socket number to a pending
          * assigned the old socket number to a pending         * request.
          * request.         *
          *         * (2) The request has been reissued after an 
          * (2) The request has been reissued after an          * authentication or redirection directive and
          * authentication or redirection directive and         * we are using the same old socket number.
          * we are using the same old socket number.         */
          */  
                 
        if (THD_TRACE)         if (THD_TRACE)
          fprintf (stderr, "*** detected a reissue of request \n");            fprintf (stderr, "*** detected a reissue of request \n");
        return (0);         return (0);
      }     }
   
     /* we verify if the request exists. If it has ended, we will have     /* we verify if the request exists. If it has ended, we will have
        a reqStatus with an HT_END value */        a reqStatus with an HT_END value */
   
    if ((me->request->net == (HTNet *) NULL) || (me->reqStatus == HT_END || me->reqStatus == HT_ERR))     if ((me->request->net == (HTNet *) NULL) || (me->reqStatus == HT_END || me->reqStatus == HT_ERR)) {
      /* request has ended */        /* request has ended */
      {  #     ifndef _WINDOWS
 #       ifndef _WINDOWS        if (THD_TRACE)
         if (THD_TRACE)           fprintf (stderr, "(BF) removing Xtinput %lu !RWE, sock %d (Request has ended)\n", *id, *s);
           fprintf (stderr, "(BF) removing Xtinput %lu !RWE, sock %d (Request has ended)\n", *id, *s);  #     endif
 #       endif        if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC)) {
         if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC))           /* free the memory allocated for async requests */
           /* free the memory allocated for async requests */           AHTPrintPendingRequestStatus (me->docid, YES);
           {           AHTReqContext_delete (me);
              AHTPrintPendingRequestStatus (me->docid, YES);        } else if (me->reqStatus != HT_END && HTError_hasSeverity (HTRequest_error (me->request), ERR_NON_FATAL))
              AHTReqContext_delete (me);              /* did the SYNC request end because of an error? If yes, report it back to the caller */
           }              me->reqStatus = HT_ERR;
         else if (me->reqStatus != HT_END && HTError_hasSeverity (HTRequest_error (me->request), ERR_NON_FATAL))        return (0);
           /* did the SYNC request end because of an error? If yes, report it back to the caller */     }
            me->reqStatus = HT_ERR;  
         return (0);  
      }  
   
    /* The request is still alive, so change it's status to indicate it's out of the     /* The request is still alive, so change it's status to indicate it's out of the
       critical section */        critical section */
Line 257  XtInputId          *id; Line 229  XtInputId          *id;
    return (0);     return (0);
 }  }
   
   #ifdef _WINDOWS
 /*----------------------------------------------------------------  /*----------------------------------------------------------------
   Add_NewSocket_to_Loop    WIN_Activate_Request
   when there are more open requests than available sockets, the     when there are more open requests than available sockets, the 
   requests are put in a "pending state." When a socket becomes    requests are put in a "pending state." When a socket becomes
   available, libwww associates it with a pending request and then    available, libwww associates it with a pending request and then
Line 271  XtInputId          *id; Line 243  XtInputId          *id;
   of this function.    of this function.
   ----------------------------------------------------------------*/    ----------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 int                 Add_NewSocket_to_Loop (HTRequest * request, HTAlertOpcode op, int msgnum, const char *dfault, void *input, HTAlertPar * reply)  int                 WIN_Activate_Request (HTRequest * request, HTAlertOpcode op, int msgnum, const char *dfault, void *input, HTAlertPar * reply)
 #else  #else
 int                 Add_NewSocket_to_Loop (request, op, msgnum, dfault, input, reply)  int                 WIN_Activate_Request (request, op, msgnum, dfault, input, reply)
 HTRequest          *request;  HTRequest          *request;
 HTAlertOpcode       op;  HTAlertOpcode       op;
 int                 msgnum;  int                 msgnum;
Line 285  HTAlertPar         *reply; Line 257  HTAlertPar         *reply;
 {  {
    AHTReqContext      *me = HTRequest_context (request);     AHTReqContext      *me = HTRequest_context (request);
   
    if (me->reqStatus == HT_BUSY)     if (me->reqStatus == HT_NEW) {
      /* request was aborted and now is is being reissued */        if (me->outputfile && (me->output = fopen (me->outputfile, "wb")) == NULL) {
      {  
        rewind (me->output);  
        HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));  
      } else if (me->reqStatus == HT_NEW_PENDING)  
        {  
          /* we are dequeing a pending request */  
          if (me->outputfile && (me->output = fopen (me->outputfile, "w")) == NULL)  
            {  
              /* the request is associated with a file */               /* the request is associated with a file */
              me->outputfile[0] = '\0';  /* file could not be opened */               me->outputfile[0] = EOS;   /* file could not be opened */
              TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),               TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
                            me->outputfile);                             me->outputfile);
              me->reqStatus = HT_ERR;               me->reqStatus = HT_ERR;
              return (HT_ERROR);               if (me->error_html)
            }                   DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; /* so we can show the error message */
          if (THD_TRACE)        } else {
            fprintf (stderr, "Add_NewSocket_to_Loop: Activating pending %s . Open fd %d\n", me->urlName, (int) me->output);              if (THD_TRACE)
          HTRequest_setOutputStream (me->request,                  fprintf (stderr, "Add_NewSocket_to_Loop: Activating pending %s . Open fd %d\n", me->urlName, (int) me->output);
                                     AHTFWriter_new (me->request, me->output, YES));               HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));    
        }          /*change the status of the request */
           me->reqStatus = HT_WAITING;
         }
      } 
      else if (me->reqStatus == HT_WAITING) {
   
              /*change the status of the request */
           rewind (me->output);
                   if (HTRequest_outputStream (me->request) == NULL)
               HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
      } 
      else {
                    me->reqStatus = HT_ERR;
      }
      
     return ((me->reqStatus != HT_ERR) ? HT_OK : HT_ERROR);
   }
   
    /*change the status of the request */  #else
    me->reqStatus = HT_WAITING;  
   /*----------------------------------------------------------------
     Add_NewSocket_to_Loop
     when there are more open requests than available sockets, the 
     requests are put in a "pending state." When a socket becomes
     available, libwww associates it with a pending request and then
     calls this callback function. This function is responsible for
     opening the temporary file where the GET and POST  results
     will be stored. The function is also responsible for 
     registering the socket with the Xt event loop.
     Consult the libwww manual for more details on the signature
     of this function.
     ----------------------------------------------------------------*/
   #ifdef __STDC__
   int                 Add_NewSocket_to_Loop (HTRequest * request, HTAlertOpcode op, int msgnum, const char *dfault, void *input, HTAlertPar * reply)
   #else
   int                 Add_NewSocket_to_Loop (request, op, msgnum, dfault, input, reply)
   HTRequest          *request;
   HTAlertOpcode       op;
   int                 msgnum;
   const char         *dfault;
   void               *input;
   HTAlertPar         *reply;
   
   #endif /* __STDC__ */
   {
      AHTReqContext      *me = HTRequest_context (request);
   
    if (THD_TRACE)     if (THD_TRACE)
      fprintf (stderr, "(Activating a pending request\n");       fprintf (stderr, "(Activating a request\n");
   
      if (me->reqStatus == HT_NEW || me->reqStatus == HT_PENDING) {
           /* the request is active, open the output file */
          if (!(me->output = fopen (me->outputfile, "w"))) {
              me->outputfile[0] = EOS;     
              /* file could not be opened */
              TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE), me->outputfile);
              me->reqStatus = HT_ERR;
              /* should the error be shown on the Amaya doc window? */
              if (me->error_html)
                  DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR; 
          } 
          /* else {
                HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
                me->reqStatus = HT_WAITING;
          }*/
   #ifdef JOSE
              fprintf (stderr, "ADDNEWSOCK: associated %s to fd %d\n", me->urlName, me->output); 
   #endif
          if (me->output) {
             if (THD_TRACE)
                fprintf (stderr, "Add_NewSocket_to_Loop: Activating pending %s . Open fd %d\n", me->urlName, (int) me->output);
             HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
             me->reqStatus = HT_WAITING;
          }
      }
      else  if (me->reqStatus == HT_BUSY) {
          /* JK: Comment: see if we can add HT_WAIT HERE */
          /* request was aborted and now is is being reissued */
          rewind (me->output);
          /* verify if this is OK */
          HTRequest_setOutputStream (me->request, AHTFWriter_new (me->request, me->output, YES));
      } 
      
    return (HT_OK);     return (HT_OK);
 }  }
   #endif /* _WINDOWS */
   
   #ifndef _WINDOWS
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTEvent_register    AHTEvent_register
   callback called by libwww whenever a socket is open and associated    callback called by libwww whenever a socket is open and associated
Line 354  HTPriority          p; Line 394  HTPriority          p;
         me = HTRequest_context (rqp);          me = HTRequest_context (rqp);
   
         /* verify if we need to open the fd */          /* verify if we need to open the fd */
         if (me->reqStatus == HT_NEW_PENDING)          if (me->reqStatus == HT_NEW)
           {            {
              /* we are opening a pending request */               /* we are opening a pending request */
              if ((me->output = fopen (me->outputfile, "w")) == NULL)               if ((me->output = fopen (me->outputfile, "w")) == NULL)
Line 365  HTPriority          p; Line 405  HTPriority          p;
                   me->reqStatus = HT_ERR;                    me->reqStatus = HT_ERR;
                   return (HT_ERROR);                    return (HT_ERROR);
                }                 }
   #ifdef JOSE
              fprintf (stderr, "ADDNEWSOCK: associated %s to fd %d\n", me->urlName, me->output); 
   #endif
              HTRequest_setOutputStream (me->request,               HTRequest_setOutputStream (me->request,
                              AHTFWriter_new (me->request, me->output, YES));                               AHTFWriter_new (me->request, me->output, YES));
              me->reqStatus = HT_WAITING;               me->reqStatus = HT_WAITING;
Line 403  HTPriority          p; Line 446  HTPriority          p;
    return (status);     return (status);
 }  }
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   AHTEvent_unregister    AHTEvent_unregister
   callback called by libwww each time a request is unregistered. This    callback called by libwww each time a request is unregistered. This
Line 451  SockOps             ops; Line 493  SockOps             ops;
    return (status);     return (status);
 }  }
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   RequestKillAllXtevents    RequestKillAllXtevents
   front-end for kill all Xt events associated with the request pointed    front-end for kill all Xt events associated with the request pointed
Line 462  void                RequestKillAllXteven Line 503  void                RequestKillAllXteven
 #else  #else
 void                RequestKillAllXtevents (me)  void                RequestKillAllXtevents (me)
 AHTReqContext      *me;  AHTReqContext      *me;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
    if (THD_TRACE)     if (THD_TRACE)
Line 483  static void         RequestRegisterReadX Line 523  static void         RequestRegisterReadX
 static void         RequestRegisterReadXtevent (me, sock)  static void         RequestRegisterReadXtevent (me, sock)
 AHTReqContext      *me;  AHTReqContext      *me;
 SOCKET sock;  SOCKET sock;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
 #  ifdef _WINDOWS  
    FD_SET (sock, &read_fds);  
    FD_SET (sock, &all_fds);  
    me->read_sock = sock;  
    if (sock > maxfds)   
       maxfds = sock;  
      
    /*  
    me->read_sock = sock;  
    me->read_fd_state |= FD_READ;  
    WSAAsyncSelect (sock, HTSocketWin, HTwinMsg, me->read_fd_state);  
    */  
 # else  
   if (me->read_xtinput_id)    if (me->read_xtinput_id)
     {      {
       if (THD_TRACE)        if (THD_TRACE)
Line 516  SOCKET sock; Line 542  SOCKET sock;
    if (THD_TRACE)     if (THD_TRACE)
     fprintf (stderr, "(BT) adding Xtinput %lu Socket %d R\n",      fprintf (stderr, "(BT) adding Xtinput %lu Socket %d R\n",
              me->read_xtinput_id, sock);               me->read_xtinput_id, sock);
 # endif /* !_WINDOWS */  
   
 }  }
   
Line 529  static void         RequestKillReadXteve Line 554  static void         RequestKillReadXteve
 #else  #else
 static void         RequestKillReadXtevent (me)  static void         RequestKillReadXtevent (me)
 AHTReqContext      *me;  AHTReqContext      *me;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
 #  ifdef _WINDOWS  
    int new_fd;  
   
    if (me->read_sock != INVSOC) {  
       FD_CLR (me->read_sock, &read_fds);  
       FD_CLR (me->read_sock, &all_fds);  
       me->read_sock = INVSOC;  
       WIN_ResetMaxSock();  
       /*  
       me->read_fd_state &= ~FD_READ;  
       new_fd = VerifySocketState (me, me->read_sock);  
       if (new_fd)  
          WSAAsyncSelect (me->read_sock, HTSocketWin, HTwinMsg, new_fd);  
       else   
           WSAAsyncSelect (me->read_sock, HTSocketWin, 0, 0);  
       me->read_sock = INVSOC;  
       */  
    }  
 #  else  
    if (me->read_xtinput_id)     if (me->read_xtinput_id)
      {       {
         if (THD_TRACE)          if (THD_TRACE)
Line 558  AHTReqContext      *me; Line 563  AHTReqContext      *me;
         XtRemoveInput (me->read_xtinput_id);          XtRemoveInput (me->read_xtinput_id);
         me->read_xtinput_id = (XtInputId) NULL;          me->read_xtinput_id = (XtInputId) NULL;
      }       }
 #  endif /* !_WINDOWS */  
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 574  SOCKET              sock; Line 578  SOCKET              sock;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
 #  ifdef _WINDOWS  
    FD_SET (sock, &write_fds);  
    FD_SET (sock, &all_fds);  
    me->write_sock = sock;  
      
    if (sock > maxfds)   
       maxfds = sock ;  
    /*  
    me->write_sock = sock;  
    me->write_fd_state |= FD_WRITE;  
    WSAAsyncSelect (sock, HTSocketWin, HTwinMsg, me->write_fd_state);  
    */  
 #  else  
    if (me->write_xtinput_id)     if (me->write_xtinput_id)
     {      {
       if (THD_TRACE)        if (THD_TRACE)
Line 604  SOCKET              sock; Line 595  SOCKET              sock;
   if (THD_TRACE)    if (THD_TRACE)
     fprintf (stderr, "(BT) adding Xtinput %lu Socket %d W\n",      fprintf (stderr, "(BT) adding Xtinput %lu Socket %d W\n",
              me->write_xtinput_id, sock);               me->write_xtinput_id, sock);
 #  endif /* !_WINDOWS */  
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 617  static void         RequestKillWriteXtev Line 607  static void         RequestKillWriteXtev
 #else  #else
 static void         RequestKillWriteXtevent (me)  static void         RequestKillWriteXtevent (me)
 AHTReqContext      *me;  AHTReqContext      *me;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
 #  ifdef _WINDOWS  
    int new_fd;  
   
    if (me->write_sock != INVSOC) {  
       FD_CLR (me->write_sock, &write_fds);  
       FD_CLR (me->write_sock, &all_fds);  
       me->write_sock = INVSOC;  
       WIN_ResetMaxSock();  
       /*  
       me->write_fd_state &= ~FD_WRITE;  
       new_fd = VerifySocketState (me, me->write_sock);  
       if (new_fd)  
          WSAAsyncSelect (me->write_sock, HTSocketWin, HTwinMsg, new_fd);  
       else   
          WSAAsyncSelect (me->write_sock, HTSocketWin, 0, 0);  
       me->write_sock = INVSOC;  
       */  
    }  
 #  else  
    if (me->write_xtinput_id)     if (me->write_xtinput_id)
      {       {
         if (THD_TRACE)          if (THD_TRACE)
Line 646  AHTReqContext      *me; Line 616  AHTReqContext      *me;
         XtRemoveInput (me->write_xtinput_id);          XtRemoveInput (me->write_xtinput_id);
         me->write_xtinput_id = (XtInputId) NULL;          me->write_xtinput_id = (XtInputId) NULL;
      }       }
 #  endif /* !_WINDOWS */  
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 662  SOCKET              sock; Line 631  SOCKET              sock;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
 #  ifdef _WINDOWS  
    FD_SET (sock, &except_fds);  
    FD_SET (sock, &all_fds);  
    me->except_sock = sock;  
    if (sock > maxfds)   
       maxfds = sock ;  
    /*  
    me->except_sock = sock;  
    me->except_fd_state |= FD_OOB;  
    WSAAsyncSelect (sock, HTSocketWin, HTwinMsg, me->except_fd_state);  
    */  
 #  else  
    if (me->except_xtinput_id)     if (me->except_xtinput_id)
      {       {
        if (THD_TRACE)         if (THD_TRACE)
Line 692  SOCKET              sock; Line 649  SOCKET              sock;
     fprintf (stderr, "(BT) adding Xtinput %lu Socket %d E\n",      fprintf (stderr, "(BT) adding Xtinput %lu Socket %d E\n",
              me->write_xtinput_id, sock);               me->write_xtinput_id, sock);
   
 #  endif /* !_WINDOWS */  
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 705  static void         RequestKillExceptXte Line 661  static void         RequestKillExceptXte
 #else  #else
 static void         RequestKillExceptXtevent (me)  static void         RequestKillExceptXtevent (me)
 AHTReqContext      *me;  AHTReqContext      *me;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
 #  ifdef _WINDOWS  
    int new_fd;  
    if (me->except_sock != INVSOC) {  
       FD_CLR (me->except_sock, &except_fds);  
       FD_CLR (me->except_sock, &all_fds);  
       me->except_sock = INVSOC;  
       WIN_ResetMaxSock();  
       /*  
       me->except_fd_state &= ~FD_WRITE;  
       new_fd = VerifySocketState (me, me->except_sock);  
       if (new_fd)  
          WSAAsyncSelect (me->except_sock, HTSocketWin, HTwinMsg, new_fd);  
       else   
          WSAAsyncSelect (me->except_sock, HTSocketWin, 0, 0);  
       me->except_sock = INVSOC;  
       */  
    }  
 #  else  
    if (me->except_xtinput_id)     if (me->except_xtinput_id)
      {       {
         if (THD_TRACE)          if (THD_TRACE)
Line 733  AHTReqContext      *me; Line 670  AHTReqContext      *me;
         XtRemoveInput (me->except_xtinput_id);          XtRemoveInput (me->except_xtinput_id);
         me->except_xtinput_id = (XtInputId) NULL;          me->except_xtinput_id = (XtInputId) NULL;
      }       }
 #  endif /* !_WINDOWS */  
 }  
   
 #ifdef _WINDOWS  
 #ifdef __STDC__  
 static void WIN_ResetMaxSock (void)  
 #else /* __STDC__ */  
 static void WIN_ResetMaxSock ()  
 #endif /* __STDC__ */  
 {  
     SOCKET s ;  
     SOCKET t_max = 0;  
       
     for (s = 0 ; s <= maxfds; s++) {   
         if (FD_ISSET(s, &all_fds)) {  
            if (s > t_max)  
               t_max = s ;  
         } /* scope */  
     } /* for */  
   
     maxfds = t_max ;  
 }  
   
 #ifdef __STDC__  
 void WIN_ProcessSocketActivity (void)  
 #else /* __STDC__ */  
 void WIN_ProcessSocketActivity ()  
 #endif /* __STDC__ */  
 {  
     int active_sockets;  
     SOCKET s;  
     struct timeval tv;  
     int exceptions, readings, writings;  
     fd_set treadset, twriteset, texceptset ;      
   
     treadset = read_fds;  
     twriteset = write_fds ;  
     texceptset = except_fds ;    
   
     /* do a non-blocking select */  
     tv.tv_sec = 0;   
     tv.tv_usec = 0;  
   
     if (maxfds == 0)  
        return; /* there are no active connections */  
   
     active_sockets = select(maxfds+1, &treadset, &twriteset, &texceptset, (struct timeval *) &tv);  
   
     switch (active_sockets)  {  
            case  0: /* no activity - timeout - allowed */  
            case -1: /* error has occurred */  
                 return;  
            default:  
                 break;  
     } /* switch */  
   
     exceptions = 0;  
     readings   = 0;  
     writings   = 0;  
   
     for (s = 0 ; s <= maxfds ; s++) {   
         if (FD_ISSET(s, &texceptset))  
            exceptions++;  
         if (FD_ISSET(s, &treadset))  
            readings++;  
         if (FD_ISSET(s, &twriteset))  
            writings++;  
     } /* for */  
       
     if (exceptions)  
        WIN_ProcessFds (&texceptset, FD_OOB);  
   
     if (readings)   
        WIN_ProcessFds (&treadset, FD_READ);  
   
     if (writings)   
        WIN_ProcessFds (&twriteset, FD_WRITE);  
 }  }
   #endif /* !_WINDOWS */
   
 #ifdef __STDC__  
 void WIN_InitializeSockets (void)  
 #else  /* __STDC__ */  
 void WIN_InitializeSockets ()  
 #endif /* __STDC__ */  
 {  
     maxfds = 0 ;  
   
     FD_ZERO(&read_fds);  
     FD_ZERO(&write_fds);  
     FD_ZERO(&except_fds) ;  
     FD_ZERO(&all_fds);  
     /*  
     AHTEventInit ();  
     */  
 }  
   
 #if 0  
 #ifdef __STDC__  
 static BOOL AHTEventInit (void)  
 #else  /* __STDC__ */  
 static BOOL AHTEventInit ()  
 #endif /* __STDC__ */  
 {  
     /*  
     **  We are here starting a hidden window to take care of events from  
     **  the async select() call in the async version of the event loop in  
     **  the Internal event manager (HTEvntrg.c)  
     */  
     static char   className[] = "AsyncWindowClass";  
     WNDCLASS      wc;  
     OSVERSIONINFO osInfo;  
     WSADATA       wsadata;  
       
     wc.style         = 0;  
     wc.lpfnWndProc   = (WNDPROC) ASYNCWindowProc;  
     wc.cbClsExtra    = 0;  
     wc.cbWndExtra    = 0;  
     wc.hIcon         = 0;  
     wc.hCursor       = 0;  
     wc.hbrBackground = 0;  
     wc.lpszMenuName  = (LPSTR) 0;  
     wc.lpszClassName = className;  
   
     osInfo.dwOSVersionInfoSize = sizeof (osInfo);  
     GetVersionEx (&osInfo);  
     if (osInfo.dwPlatformId == VER_PLATFORM_WIN32s || osInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)  
         wc.hInstance = GetModuleHandle (NULL); /* 95 and non threaded platforms */  
     else  
         wc.hInstance = GetCurrentProcess (); /* NT and hopefully everything following */  
   
     RegisterClass (&wc);  
     if (!(HTSocketWin = CreateWindow (className, "WWW_WIN_ASYNC", WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,   
                                       CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, wc.hInstance,0))) {  
         return NO;  
     }  
     HTwinMsg = WM_USER;  /* use first available message since app uses none */  
   
     /*  
     ** Initialise WinSock DLL. This must also be shut down! PMH  
     */  
     if (WSAStartup (DESIRED_WINSOCK_VERSION, &wsadata)) {  
         WSACleanup ();  
         return NO;  
     }  
   
     if (wsadata.wVersion < MINIMUM_WINSOCK_VERSION) {  
         WSACleanup ();  
         return NO;  
     }  
       
     return YES;  
 }  
   
 #ifdef __STDC__  
 PUBLIC LRESULT CALLBACK ASYNCWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)  
 #else  /* __STDC__ */  
 PUBLIC LRESULT CALLBACK ASYNCWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)  
 HWND   hwnd;   
 UINT   uMsg;   
 WPARAM wParam;   
 LPARAM lParam;  
 #endif /* __STDC__ */  
 {  
     WORD event;  
     SOCKET sock;  
   
     if (uMsg != HTwinMsg)       /* not our async message */  
         return (DefWindowProc (hwnd, uMsg, wParam, lParam));  
   
     event = LOWORD (lParam);  
     sock  = (SOCKET) wParam;  
   
     if (event & (FD_READ | FD_ACCEPT | FD_CLOSE))  
        WIN_AHTCallback_bridge (FD_READ, &sock);  
   
     if (event & (FD_WRITE | FD_CONNECT))  
        WIN_AHTCallback_bridge (FD_WRITE, &sock);  
   
     if (event & FD_OOB)  
        WIN_AHTCallback_bridge (FD_OOB, &sock);  
   
     return (0);  
 }  
   
 #ifdef __STDC__  
 static int VerifySocketState (AHTReqContext *me, SOCKET sock)  
 #else  /* __STDC__ */  
 static int VerifySocketState (me, sock)  
 AHTReqContext* me;   
 SOCKET         sock;  
 #endif /* __STDC__ */  
 {  
     int fd_state = 0;  
   
     if (sock == me->read_sock)  
        fd_state |= me->read_fd_state;  
   
     if (sock == me->write_sock)  
        fd_state |= me->write_fd_state;  
   
     if (sock == me->except_sock)  
        fd_state |= me->except_fd_state;  
   
     return (fd_state);  
 }  
 #endif /* 0 */  
   
 #ifdef __STDC__  
 static int WIN_ProcessFds (fd_set* fdsp, SockOps ops)  
 #else  /* __STDC__ */  
 static int WIN_ProcessFds (fdsp, ops)  
 fd_set* fdsp;   
 SockOps ops;  
 #endif /* __STDC__ */  
 {  
     SOCKET s ;  
   
     for (s = 0 ; s <= maxfds; s++) {  
         if (FD_ISSET( s, fdsp)) {  
            WIN_AHTCallback_bridge (ops, &s);  
            return;  
         }  
     }  
     return HT_OK;  
 }  
 #endif /* _WINDOWS */  
 #endif /* !AMAYA_JAVA */  #endif /* !AMAYA_JAVA */
   
   

Removed from v.1.31  
changed lines
  Added in v.1.32


Webmaster