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.

74 lines
2.3 KiB

  1. // PMSPservice.h
  2. #include "ntservice.h"
  3. #define MAX_PIPE_INSTANCES (5)
  4. class CPMSPService : public CNTService
  5. {
  6. public:
  7. CPMSPService(DWORD& dwLastError);
  8. virtual ~CPMSPService();
  9. virtual BOOL OnInit(DWORD& dwLastError);
  10. virtual void Run();
  11. virtual BOOL OnUserControl(DWORD dwOpcode);
  12. virtual void OnStop();
  13. virtual void OnShutdown();
  14. protected:
  15. // Manual reset event; signalled to stop the service, else unsignalled
  16. HANDLE m_hStopEvent;
  17. // Number of clients connected to named pipe
  18. DWORD m_dwNumClients;
  19. typedef struct
  20. {
  21. // Note: This struct is initilized by calling ZeroMemory in the
  22. // constructor. If members are added that should not have an inital
  23. //value of 0, change the constructor.
  24. HANDLE hPipe;
  25. OVERLAPPED overlapped;
  26. enum {
  27. NO_IO_PENDING = 0,
  28. CONNECT_PENDING,
  29. READ_PENDING,
  30. WRITE_PENDING
  31. } state;
  32. // Read state:
  33. BYTE readBuf[256];
  34. DWORD dwNumBytesRead;
  35. // Write state:
  36. BYTE writeBuf[256];
  37. DWORD dwNumBytesToWrite;
  38. DWORD dwNumBytesWritten;
  39. // MSDN is not clear whether we can call GetOverlappedResult if an
  40. // i/o call returns with anything other than ERROR_IO_PENDING.
  41. // So we don't. We stash away the last IO result and the number of
  42. // bytes transferred (if appropraite) so that we can
  43. // decide whether to call GetOverlappedResult later.
  44. DWORD dwLastIOCallError;
  45. DWORD dwNumBytesTransferredByLastIOCall;
  46. // The number of consecutive calls to ConenctNamedPipe that return
  47. // failure. Once this hits the limit, we do not attempt to connect to
  48. // this instance of the pipe any more.
  49. DWORD dwConsecutiveConnectErrors;
  50. } PIPE_STATE, *PPIPE_STATE;
  51. PIPE_STATE m_PipeState[MAX_PIPE_INSTANCES];
  52. static const DWORD m_dwMaxConsecutiveConnectErrors;
  53. // Helper methods
  54. void ConnectToClient(DWORD i);
  55. void Read(DWORD i);
  56. void Write(DWORD i);
  57. };