Leaked source code of windows server 2003
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.

146 lines
2.1 KiB

  1. /*++=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ioctx.cxx
  5. Abstract:
  6. Implements the IO Context object.
  7. Author:
  8. Paul M Midgen (pmidge) 08-February-2001
  9. Revision History:
  10. 08-February-2001 pmidge
  11. Created
  12. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--*/
  13. #include "common.h"
  14. IOCTX::IOCTX(IOTYPE iot, SOCKET s):
  15. clientid(NULL),
  16. local(NULL),
  17. remote(NULL),
  18. session(NULL),
  19. socket(s),
  20. sockbuf(NULL),
  21. bytes(0),
  22. flags(0),
  23. bufsize(0),
  24. error(0),
  25. _iot(iot),
  26. _cRefs(1)
  27. {
  28. pthis = this;
  29. memset(&overlapped, 0, sizeof(OVERLAPPED));
  30. if( _iot == IOCT_CONNECT )
  31. {
  32. sockbuf = new BYTE[((sizeof(SOCKADDR_IN)+16)*2)];
  33. }
  34. }
  35. IOCTX::~IOCTX()
  36. {
  37. if( _iot == IOCT_CONNECT )
  38. {
  39. SAFEDELETE(sockbuf);
  40. SAFEDELETEBUF(clientid);
  41. }
  42. SAFECLOSE(overlapped.hEvent);
  43. }
  44. void
  45. IOCTX::AddRef(void)
  46. {
  47. InterlockedIncrement(&_cRefs);
  48. }
  49. void
  50. IOCTX::Release(void)
  51. {
  52. InterlockedDecrement(&_cRefs);
  53. if( _cRefs == 0 )
  54. {
  55. delete this;
  56. }
  57. return;
  58. }
  59. IOTYPE
  60. IOCTX::Type(void)
  61. {
  62. return _iot;
  63. }
  64. BOOL
  65. IOCTX::AllocateWSABuffer(DWORD size, LPVOID pv)
  66. {
  67. if( !(pwsa = new WSABUF) )
  68. {
  69. return FALSE;
  70. }
  71. if( size != 0 )
  72. {
  73. bufsize = size;
  74. if( pv )
  75. {
  76. pwsa->buf = (CHAR*) pv;
  77. pwsa->len = size;
  78. }
  79. else
  80. {
  81. if( !(pwsa->buf = new CHAR[size]) )
  82. {
  83. return FALSE;
  84. }
  85. pwsa->len = (_iot == IOCT_SEND) ? 0 : size;
  86. }
  87. }
  88. return TRUE;
  89. }
  90. void
  91. IOCTX::FreeWSABuffer(void)
  92. {
  93. SAFEDELETEBUF(pwsa->buf);
  94. SAFEDELETE(pwsa);
  95. bufsize = 0;
  96. }
  97. BOOL
  98. IOCTX::ResizeWSABuffer(DWORD size)
  99. {
  100. SAFEDELETEBUF(pwsa->buf);
  101. if( !(pwsa->buf = new CHAR[size]) )
  102. {
  103. return FALSE;
  104. }
  105. bufsize = size;
  106. pwsa->len = (_iot == IOCT_SEND) ? 0 : size;
  107. return TRUE;
  108. }
  109. void
  110. IOCTX::DisableIoCompletion(void)
  111. {
  112. overlapped.hEvent =
  113. (HANDLE) ((ULONG_PTR) CreateEvent(NULL, TRUE, FALSE, NULL) | 0x00000001);
  114. }