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.

88 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. tnpsrv.c
  5. Abstract:
  6. This program creates a single instance of the pipe \cw\testpipe,
  7. awaits for a connection. While a client wants to talk it will echo
  8. data back to the client. When the client closes the pipe tnpsrv will
  9. wait for another client.
  10. Author:
  11. Colin Watson (ColinW) 19-March-1991
  12. Revision History:
  13. --*/
  14. #include <assert.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <windows.h>
  18. int
  19. main(
  20. int argc,
  21. char *argv[],
  22. char *envp[]
  23. )
  24. {
  25. HANDLE S1;
  26. DWORD Size;
  27. DWORD Dummy;
  28. CHAR Data[1024];
  29. S1 = CreateNamedPipe("\\\\.\\Pipe\\cw\\testpipe",
  30. PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
  31. PIPE_WAIT | PIPE_READMODE_MESSAGE| PIPE_TYPE_MESSAGE,
  32. 1, // One instance only
  33. sizeof(Data),
  34. sizeof(Data),
  35. 0,
  36. NULL);
  37. assert(S1 != INVALID_HANDLE_VALUE);
  38. while (1) {
  39. printf("Waiting for connection\n");
  40. if ( FALSE == ConnectNamedPipe( S1, NULL )) {
  41. printf("Server ReadFile returned Error %lx\n", GetLastError() );
  42. break;
  43. }
  44. while (1) {
  45. printf("Server now Reading\n");
  46. if ( FALSE == ReadFile(S1,Data, sizeof(Data), &Size, NULL) ) {
  47. printf("Server ReadFile returned Error %lx\n", GetLastError() );
  48. break;
  49. }
  50. printf("Server Reading Done %s\n",Data);
  51. printf("Server Writing\n");
  52. if ( FALSE == WriteFile(S1, Data, Size, &Dummy, NULL) ) {
  53. printf("Server WriteFile returned Error %lx\n", GetLastError() );
  54. break;
  55. }
  56. printf("Server Writing Done\n");
  57. }
  58. if ( FALSE == DisconnectNamedPipe( S1 ) ) {
  59. printf("Server WriteFile returned Error %lx\n", GetLastError() );
  60. break;
  61. }
  62. }
  63. CloseHandle(S1);
  64. }