HTEvntrg.h
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:5k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /*                                                                              Event Manager
  2.                                       EVENT MANAGER
  3.                                              
  4.  */
  5. /*
  6. **      (c) COPYRIGHT MIT 1995.
  7. **      Please first read the full copyright statement in the file COPYRIGH.
  8. */
  9. /*
  10.    This module is the application interface to the multi-threaded functionality in the
  11.    Library. It contains a set of functions that the application can either use as are or
  12.    they can be overwritten by the application.
  13.    
  14.    This module is implemented by HTEvntrg.c, and it is a part of the W3C Reference
  15.    Library.
  16.    
  17.  */
  18. #ifndef HTEVNTRG_H
  19. #define HTEVNTRG_H
  20. #include "HTReq.h"
  21. #include "tcp.h"
  22. /*
  23. Windows Specific Handles
  24.  */
  25. #if defined(WWW_WIN_ASYNC) || defined(WWW_WIN_DLL)
  26. extern BOOL HTEvent_winHandle (HTRequest * request);
  27. extern BOOL HTEvent_setWinHandle (HWND window, unsigned long message);
  28. extern HWND HTEvent_getWinHandle (unsigned long * pMessage);
  29. extern LRESULT CALLBACK AsyncWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
  30. );
  31. #endif
  32. /*
  33. Event Handlers
  34.    The appplication registers a set of event handlers to be used on a specified set of
  35.    sockets. The eventhandlers must be defined as follows:
  36.    
  37.  */
  38. typedef u_long SockOps;
  39. #define FD_NONE 0
  40. #define FD_ALL (FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT |FD_CLOSE)
  41. #define FD_UNREGISTER (((FD_ALL) << 1) & (~(FD_ALL)))
  42. typedef enum _HTPriority {
  43.     HT_PRIORITY_INV = -1,
  44.     HT_PRIORITY_OFF = 0,
  45.     HT_PRIORITY_MIN = 1,
  46.     HT_PRIORITY_MAX = 20
  47. } HTPriority;
  48. typedef int HTEventCallback (SOCKET, HTRequest *, SockOps);
  49. /*
  50.   REGISTER A TTY EVENT HANDLER
  51.   
  52.    Register the tty (console) as having events. If the TTY is select()-able (as is true
  53.    under Unix), then we treat it as just another socket. Otherwise, take steps depending
  54.    on the platform. This is the function to use to register user events!
  55.    
  56.  */
  57. extern int HTEvent_RegisterTTY  (SOCKET, HTRequest *, SockOps,
  58.                                  HTEventCallback *, HTPriority);
  59. /*
  60.   UNREGISTER A TTY EVENT HANDLER
  61.   
  62.    Unregisters TTY I/O channel. If the TTY is select()-able (as is true under Unix), then
  63.    we treat it as just another socket.
  64.    
  65.  */
  66. extern int HTEvent_UnRegisterTTY (SOCKET, SockOps);
  67. /*
  68.   REGISTER AN EVENT HANDLER
  69.   
  70.    For a given socket, reqister a request structure, a set of operations, a
  71.    HTEventCallback function, and a priority. For this implementation, we allow only a
  72.    single HTEventCallback function for all operations. and the priority field is ignored.
  73.    
  74.  */
  75. extern int HTEvent_Register     (SOCKET, HTRequest *,
  76.                                  SockOps, HTEventCallback *,
  77.                                  HTPriority);
  78. /*
  79.   UNREGISTER AN EVENT HANDLER
  80.   
  81.    Remove the registered information for the specified socket for the actions specified in
  82.    ops. if no actions remain after the unregister, the registered info is deleted, and, if
  83.    the socket has been registered for notification, the HTEventCallback will be invoked.
  84.    
  85.  */
  86. extern int HTEvent_UnRegister   (SOCKET, SockOps);
  87. /*
  88.   UNREGISTER ALL EVENT HANDLERS
  89.   
  90.    Unregister all sockets. N.B. we just remove them for our internal data structures: it
  91.    is up to the application to actually close the socket.
  92.    
  93.  */
  94. extern int HTEvent_UnregisterAll (void);
  95. /*
  96. Handler for Timeout on Sockets
  97.    This function sets the timeout for sockets in the select() call and registers a timeout
  98.    function that is called if select times out. This does only works on NON windows
  99.    platforms as we need to poll for the console on windows If tv = NULL then timeout is
  100.    disabled. Default is no timeout. If always=YES then the callback is called at all
  101.    times, if NO then only when Library sockets are active. Returns YES if OK else NO.
  102.    
  103.  */
  104. typedef int HTEventTimeout (HTRequest *);
  105. extern BOOL HTEvent_registerTimeout (struct timeval *tp, HTRequest * request,
  106.                                      HTEventTimeout *tcbf, BOOL always);
  107. /*
  108. Start the Event Loop
  109.    That is, we wait for activity from one of our registered channels, and dispatch on
  110.    that. Under Windows/NT, we must treat the console and sockets as distinct.  That means
  111.    we can't avoid a busy wait, but we do our best.
  112.    
  113.  */
  114. extern int HTEvent_Loop (HTRequest * request);
  115. /*
  116. Stop the Event Loop
  117.    Stops the (select based) event loop. The function does not guarantee that all requests
  118.    have terminated. This is for the app to do
  119.    
  120.  */
  121. extern void HTEvent_stopLoop (void);
  122. /*
  123.  */
  124. #endif /* HTEvent_H */
  125. /*
  126.    End of declartion module  */