Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.1 KiB

  1. /*
  2. * Copyright (c) 1998, Microsoft Corporation
  3. * File: timeout.cpp
  4. *
  5. * Purpose:
  6. *
  7. * Contains all the definitions
  8. * for the overlapped I/O context structures
  9. *
  10. * History:
  11. *
  12. * 1. created
  13. * Ajay Chitturi (ajaych) 26-Jun-1998
  14. *
  15. */
  16. #ifndef _oviocontext_h_
  17. #define _oviocontext_h_
  18. /*
  19. * This file defines the structures used for overlapped I/O
  20. */
  21. #define ACCEPT_BUFFER_MAX (sizeof (SOCKADDR_IN) * 2 + 0x20)
  22. #define TPKT_HEADER_SIZE 4
  23. #define TPKT_VERSION 3
  24. // Types of overlapped I/O requests
  25. enum EMGR_OV_IO_REQ_TYPE
  26. {
  27. EMGR_OV_IO_REQ_ACCEPT = 0,
  28. EMGR_OV_IO_REQ_SEND,
  29. EMGR_OV_IO_REQ_RECV
  30. };
  31. // This structure stores the I/O context for each Overlapped I/O request
  32. // OVERLAPPED should always be the first member of this struct.
  33. // A pointer to the overlapped member of this structure is passed
  34. // for all overlapped I/O calls.
  35. // When we receive an I/O completion packet, the IOContext pointer is
  36. // obtained by casting the OVERLAPPED pointer.
  37. typedef struct _IOContext {
  38. OVERLAPPED ov;
  39. EMGR_OV_IO_REQ_TYPE reqType; // ACCEPT/SEND/RECV
  40. OVERLAPPED_PROCESSOR *pOvProcessor; // callback called on this member
  41. // this gives us the socket and
  42. // the call type (Q931/H245) as well
  43. } IOContext, *PIOContext;
  44. // This structure stores the I/O context
  45. // for each Overlapped Send/Recv request
  46. typedef struct _SendRecvContext {
  47. IOContext ioCtxt;
  48. SOCKET sock;
  49. BYTE pbTpktHdr[TPKT_HEADER_SIZE];
  50. DWORD dwTpktHdrBytesDone;
  51. PBYTE pbData;
  52. DWORD dwDataLen;
  53. DWORD dwDataBytesDone;
  54. } SendRecvContext, *PSendRecvContext;
  55. // This structure stores the I/O context
  56. // for each Overlapped accept request
  57. typedef struct _AcceptContext {
  58. IOContext ioCtxt;
  59. SOCKET listenSock;
  60. SOCKET acceptSock;
  61. BYTE addrBuf[ACCEPT_BUFFER_MAX];
  62. } AcceptContext, *PAcceptContext;
  63. #include "sockinfo.h"
  64. // the PDU decode logic depends upon whether its targeted for
  65. // a Q931 or H245 channel. Since we want to keep that logic
  66. // in the event manager, the overlapped processor needs to
  67. // expose its type via this
  68. enum OVERLAPPED_PROCESSOR_TYPE
  69. {
  70. OPT_Q931 = 0,
  71. OPT_H245
  72. };
  73. // Classes (Q931 src, dest and H245) inheriting
  74. // from this make async overlapped operations
  75. // this class provides the callback methods and
  76. // some of the parameters needed by the event manager
  77. // to make the overlapped calls
  78. class OVERLAPPED_PROCESSOR
  79. {
  80. protected:
  81. OVERLAPPED_PROCESSOR_TYPE m_OverlappedProcessorType;
  82. // it belongs to this call state
  83. H323_STATE * m_pH323State;
  84. SOCKET_INFO m_SocketInfo; // socket handle and remote/local address/ports
  85. public:
  86. OVERLAPPED_PROCESSOR::OVERLAPPED_PROCESSOR (void)
  87. : m_OverlappedProcessorType (OPT_Q931),
  88. m_pH323State (NULL)
  89. {}
  90. void Init (
  91. IN OVERLAPPED_PROCESSOR_TYPE OverlappedProcessorType,
  92. IN H323_STATE &H323State)
  93. {
  94. // an assert is sufficient as this shouldn't happen
  95. _ASSERTE(NULL == m_pH323State);
  96. m_OverlappedProcessorType = OverlappedProcessorType;
  97. m_pH323State = &H323State;
  98. }
  99. BOOLEAN IsSocketValid (void) { return m_SocketInfo.IsSocketValid(); }
  100. inline OVERLAPPED_PROCESSOR_TYPE GetOverlappedProcessorType() { return m_OverlappedProcessorType; }
  101. inline SOCKET_INFO &GetSocketInfo() { return m_SocketInfo; }
  102. inline H323_STATE &GetH323State() { return *m_pH323State; }
  103. inline CALL_BRIDGE &GetCallBridge();
  104. virtual HRESULT AcceptCallback (
  105. IN DWORD Status,
  106. IN SOCKET Socket,
  107. IN SOCKADDR_IN * LocalAddress,
  108. IN SOCKADDR_IN * RemoteAddress) = 0;
  109. virtual HRESULT SendCallback(
  110. IN HRESULT CallbackHResult
  111. ) = 0;
  112. virtual HRESULT ReceiveCallback(
  113. IN HRESULT CallbackHResult,
  114. IN BYTE *pBuffer,
  115. IN DWORD BufLen
  116. ) = 0;
  117. };
  118. void
  119. EventMgrFreeSendContext(
  120. IN PSendRecvContext pSendCtxt
  121. );
  122. void
  123. EventMgrFreeRecvContext(
  124. IN PSendRecvContext pRecvCtxt
  125. );
  126. void
  127. EventMgrFreeAcceptContext(
  128. IN PAcceptContext pAcceptCtxt
  129. );
  130. #endif //_oviocontext_h_