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.

199 lines
5.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1994 - 1999
  6. //
  7. // File: dgsccomn.c
  8. //
  9. //--------------------------------------------------------------------------
  10. /////////////////////////////////////////////////////////////////////////
  11. //
  12. // Filename: dgsccomn.c
  13. //
  14. // Description: This file contains common routines for Datagram Socket I/O
  15. // routines for use with IPC raw network performance
  16. // tests.
  17. // This module is written using win32 API calls.
  18. //
  19. // Authors: Scott Holden (Translator from NT API to win32 API)
  20. // Mahesh Keni (Mahesh wrote this application using mostly
  21. // NT native API calls)
  22. //
  23. /////////////////////////////////////////////////////////////////////////
  24. #include "rawcom.h"
  25. #include "dgsccomn.h"
  26. /************************************************************************/
  27. INTEGER
  28. DGSocket_Recv(
  29. IN USHORT CIndex,
  30. IN OUT PVOID PReadBuf,
  31. IN OUT PULONG rpdatalen)
  32. {
  33. INTEGER RetCode;
  34. ULONG Buflen;
  35. PCHAR Bufp;
  36. Bufp = PReadBuf;
  37. Buflen = *rpdatalen; // use this for getting request packet length
  38. *rpdatalen = 0; // total data received
  39. // we have make sure that the data received is same as the data
  40. // requested
  41. while (Buflen) { // till we receive all the data
  42. RetCode = recv(Clients[CIndex].c_Sock.c_Sockid, Bufp, Buflen, 0);
  43. if (RetCode == SOCKET_ERROR) {
  44. //DbgPrint("Error: Receive:%ld\n",WSAGetLastError());
  45. break;
  46. }
  47. else {
  48. if (RetCode){
  49. *rpdatalen += (ULONG)RetCode; // bytes received
  50. Buflen -= (ULONG)RetCode; // bytes yet to receive
  51. Bufp += (USHORT)RetCode; // Move the buffer pointer
  52. }
  53. else { break; }
  54. }
  55. } // check to see if it's 0
  56. return(RetCode);
  57. }
  58. /************************************************************************/
  59. INTEGER
  60. DGSocket_RecvFrom(
  61. IN USHORT CIndex,
  62. IN OUT PVOID PReadBuf,
  63. IN OUT PULONG rpdatalen,
  64. IN OUT PSOCKADDR pcaddr,
  65. IN OUT PUSHORT pcaddrlen)
  66. {
  67. INTEGER RetCode;
  68. ULONG Buflen;
  69. PCHAR Bufp;
  70. Bufp = PReadBuf;
  71. Buflen = *rpdatalen; // use this for getting request packet length
  72. *rpdatalen = 0; // total data received
  73. // we have make sure that the data received is same as the data
  74. // requested
  75. while (Buflen) { // till we receive all the data
  76. RetCode = recvfrom(
  77. Clients[CIndex].c_Sock.c_Sockid,
  78. Bufp,
  79. Buflen,
  80. 0,
  81. pcaddr,
  82. (int *)pcaddrlen);
  83. if (RetCode == SOCKET_ERROR) {
  84. //DbgPrint("Error: Receive:%ld\n",WSAGetLastError());
  85. break;
  86. }
  87. else {
  88. if (RetCode){
  89. *rpdatalen += (ULONG)RetCode; // bytes received
  90. Buflen -= (ULONG)RetCode; // bytes yet to receive
  91. Bufp += (USHORT)RetCode; // Move the buffer pointer
  92. }
  93. else { break; }
  94. }
  95. } // check to see if it's 0
  96. return(RetCode);
  97. }
  98. /************************************************************************/
  99. INTEGER
  100. DGSocket_Send(
  101. IN USHORT CIndex,
  102. IN OUT PVOID PWriteBuf,
  103. IN OUT PULONG spdatalen)
  104. {
  105. INTEGER RetCode;
  106. ULONG Buflen;
  107. Buflen = *spdatalen; // total data to be sent
  108. *spdatalen = 0;
  109. // Could use write also
  110. RetCode = send(Clients[CIndex].c_Sock.c_Sockid, PWriteBuf, Buflen, 0);
  111. if (RetCode == SOCKET_ERROR) {
  112. //DbgPrint("Error: Send:%ld\n",WSAGetLastError());
  113. }
  114. else {
  115. *spdatalen = (ULONG) RetCode;
  116. } // check to see if send length is 0
  117. return(RetCode);
  118. }
  119. /************************************************************************/
  120. INTEGER
  121. DGSocket_SendTo(
  122. IN USHORT CIndex,
  123. IN OUT PVOID PWriteBuf,
  124. IN OUT PULONG spdatalen,
  125. IN OUT PSOCKADDR pcaddr,
  126. IN OUT PUSHORT pcaddrlen)
  127. {
  128. INTEGER RetCode;
  129. ULONG Buflen;
  130. Buflen = *spdatalen; // total data to be sent
  131. *spdatalen = 0;
  132. // Could use write also
  133. RetCode = sendto(Clients[CIndex].c_Sock.c_Sockid, PWriteBuf, Buflen, 0,
  134. pcaddr, *pcaddrlen);
  135. if (RetCode == SOCKET_ERROR) {
  136. //DbgPrint("Error: Send:%ld\n",WSAGetLastError());
  137. }
  138. else {
  139. *spdatalen = (ULONG) RetCode;
  140. } // check to see if SendTo Length is 0
  141. return(RetCode);
  142. }
  143. /************************************************************************/
  144. INTEGER
  145. DGSocket_Close(
  146. IN USHORT CIndex)
  147. {
  148. INTEGER RetCode;
  149. RetCode = closesocket(Clients[CIndex].c_Sock.c_Sockid);
  150. if (RetCode == SOCKET_ERROR) {
  151. //DbgPrint("Error: Close Socket Id %ld\n",WSAGetLastError());
  152. return(RetCode);
  153. }
  154. return(RetCode);
  155. }
  156. /************************************************************************/
  157. INTEGER
  158. DGSocket_Connect(
  159. IN USHORT CIndex,
  160. IN PSOCKADDR pcsockaddr)
  161. {
  162. INTEGER RetCode;
  163. RetCode = connect(Clients[CIndex].c_Sock.c_Sockid,
  164. pcsockaddr,
  165. sizeof(SOCKADDR));
  166. if (RetCode == SOCKET_ERROR) {
  167. //DbgPrint("DGSock: Connect %ld\n",WSAGetLastError());
  168. return(RetCode);
  169. }
  170. return(RetCode);
  171. }
  172. /************************************************************************/