Windows NT 4.0 source code leak
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.

616 lines
13 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. transvr.hxx
  5. Abstract:
  6. This module is the manager of loadable transport interface modules
  7. for the server side of the runtime. The classes necessary to provide
  8. that functionality are defined in this file.
  9. Author:
  10. Steve Zeck (stevez) 06-May-1991
  11. Revision History:
  12. 01-Mar-1992 mikemon
  13. Rewrote the majority of the code and added comments.
  14. --*/
  15. #ifndef __TRANSVR_HXX__
  16. #define __TRANSVR_HXX__
  17. #define InqTransAddress(RpcTransportAddress) \
  18. ((TRANS_ADDRESS *) \
  19. ((char *) RpcTransportAddress - sizeof(TRANS_ADDRESS)))
  20. #define InqTransSConnection(RpcTransportConnection) \
  21. ((TRANS_SCONNECTION *) \
  22. ((char *) RpcTransportConnection - sizeof(TRANS_SCONNECTION)))
  23. class TRANS_SCONNECTION;
  24. NEW_SDICT(TRANS_SCONNECTION);
  25. class TRANS_ADDRESS : public OSF_ADDRESS
  26. /*++
  27. Class Description:
  28. Fields:
  29. SetupAddressOccurred - Contains a flag which indicates whether or
  30. not SetupAddressWithEndpoint or SetupAddressUnknownEndpoint
  31. have been called and returned success. A value of non-zero
  32. indicates that the above (SetupAddress* has been called and
  33. succeeded) occured.
  34. ServerInfo - Contains the pointers to the loadable transport
  35. routines for the transport type of this address.
  36. SConnectionDict - Contains a dictionary of connections for this
  37. address.
  38. ReceiveAnyActiveFlag - Contains a flag indicating whether a thread
  39. is attempting to do a receive any or not. A value of zero
  40. indicates that no receive any is occuring.
  41. ReceiveAnyMutex - Contains a mutex used to serialize access to
  42. receive any.
  43. ConnectionsToBeDeleted - Contains the set of connections which need to
  44. be deleted the next time that it is safe to do so: this will be
  45. when there is no thread performing receive any on the transport.
  46. --*/
  47. {
  48. private:
  49. unsigned int SetupAddressOccurred;
  50. RPC_SERVER_TRANSPORT_INFO * ServerInfo;
  51. TRANS_SCONNECTION_DICT SConnectionDict;
  52. unsigned int ReceiveAnyActiveFlag;
  53. QUEUE ConnectionsToBeDeleted;
  54. #ifdef NTENV
  55. EVENT ReceiveAnyMutex;
  56. #else // NTENV
  57. MUTEX ReceiveAnyMutex;
  58. #endif // NTENV
  59. public:
  60. BOOL IsSlaveAddress ;
  61. TRANS_ADDRESS (
  62. IN RPC_SERVER_TRANSPORT_INFO PAPI * RpcServerInfo,
  63. IN OUT RPC_STATUS PAPI * RpcStatus
  64. );
  65. ~TRANS_ADDRESS (
  66. );
  67. int
  68. TransMarkReceiveAny (
  69. IN OSF_SCONNECTION * Connection
  70. );
  71. RPC_STATUS
  72. TransReceive (
  73. OUT OSF_SCONNECTION * * SConnection,
  74. OUT void * * Buffer,
  75. OUT unsigned int * BufferLength
  76. );
  77. RPC_STATUS
  78. SetupAddressWithEndpoint (
  79. IN RPC_CHAR PAPI * Endpoint,
  80. OUT RPC_CHAR PAPI * PAPI * lNetworkAddress,
  81. OUT unsigned int PAPI *NumNetworkAddress,
  82. IN void PAPI * SecurityDescriptor, OPTIONAL
  83. IN unsigned int PendingQueueSize,
  84. IN RPC_CHAR PAPI * RpcProtocolSequence,
  85. IN unsigned long EndpointFlags,
  86. IN unsigned long NICFlags
  87. );
  88. RPC_STATUS
  89. SetupAddressUnknownEndpoint (
  90. OUT RPC_CHAR PAPI * PAPI * Endpoint,
  91. OUT RPC_CHAR PAPI * PAPI * lNetworkAddress,
  92. OUT unsigned int PAPI * NumNetworkAddress,
  93. IN void PAPI * SecurityDescriptor, OPTIONAL
  94. IN unsigned int PendingQueueSize,
  95. IN RPC_CHAR PAPI * RpcProtocolSequence,
  96. IN unsigned long EndpointFlags,
  97. IN unsigned long NICFlags
  98. );
  99. TRANS_SCONNECTION *
  100. NewConnection (
  101. IN int ConnectionKey,
  102. OUT unsigned int PAPI * ReceiveFlag
  103. );
  104. TRANS_SCONNECTION *
  105. FindConnection (
  106. IN int ConnectionKey
  107. );
  108. void
  109. RemoveConnection (
  110. IN int DictKey
  111. );
  112. RPC_TRANSPORT_ADDRESS
  113. InqRpcTransportAddress (
  114. );
  115. void
  116. DeleteThisConnection (
  117. IN TRANS_SCONNECTION * SConnection
  118. );
  119. void * operator new (
  120. unsigned int allocBlock,
  121. char chInit,
  122. unsigned int xtraBytes
  123. );
  124. #if defined(NTENV) || defined(WIN96)
  125. RPC_STATUS
  126. StartListening (
  127. );
  128. #endif
  129. };
  130. inline void
  131. TRANS_ADDRESS::RemoveConnection (
  132. IN int DictKey
  133. )
  134. /*++
  135. Routine Description:
  136. The connection named by the dict key will be removed from the
  137. dictionary of connections for this address.
  138. --*/
  139. {
  140. SConnectionDict.Delete(DictKey);
  141. }
  142. inline RPC_TRANSPORT_ADDRESS
  143. TRANS_ADDRESS::InqRpcTransportAddress (
  144. )
  145. /*++
  146. Return Value:
  147. A pointer to the transport data for this address will be returned.
  148. --*/
  149. {
  150. return((RPC_TRANSPORT_ADDRESS)
  151. (((char *) this) + sizeof(TRANS_ADDRESS)));
  152. }
  153. inline void
  154. TRANS_ADDRESS::DeleteThisConnection (
  155. IN TRANS_SCONNECTION * SConnection
  156. )
  157. /*++
  158. Routine Description:
  159. The supplied connection will be added to the set of connections to be
  160. deleted when it is safe to do so.
  161. Arguments:
  162. SConnection - Supplies the connection to be deleted.
  163. --*/
  164. {
  165. // There is potential memory leak here: PutOnQueue may run out of
  166. // memory which means that the connection will never get deleted. This
  167. // is going to be very difficult to hit, so I dont think it is worth
  168. // putting in the code to recover from this.
  169. ConnectionsToBeDeleted.PutOnQueue(SConnection, 0);
  170. }
  171. inline void *
  172. TRANS_ADDRESS::operator new (
  173. unsigned int allocBlock,
  174. char chInit,
  175. unsigned int xtraBytes
  176. )
  177. {
  178. void * pvTemp = RpcpFarAllocate(allocBlock + xtraBytes);
  179. if (pvTemp)
  180. {
  181. memset(pvTemp, chInit, allocBlock + xtraBytes);
  182. }
  183. return(pvTemp);
  184. }
  185. class TRANS_SCONNECTION : public OSF_SCONNECTION
  186. /*++
  187. Class Description:
  188. Fields:
  189. ServerInfo - Contains the pointers to the loadable transport
  190. routines for the transport type of this connection.
  191. ConnectionKey - Contains the key specified by the loadable
  192. transport for this connection. Some loadable transports will
  193. use this key to find a connection.
  194. DictKey - Contains the key for this connection in the dictionary
  195. of connection maintained by the address owning this connection.
  196. ConnectionClosedFlag - Contains a flag which will be non-zero if
  197. the connection is closed, and zero otherwise.
  198. ReceiveAnyFlag - Contains a flag which will be non-zero if the
  199. connection is in the receive any state, and zero otherwise.
  200. Address - Contains a pointer to the address owning this connection.
  201. BufferQueue - Contains the queue of buffers to be received; this
  202. will occur when the connection is not receive any.
  203. ConnectionEvent - Contains an event which will be raised when
  204. something happens on this connection.
  205. ReceiveDirectFlag - Contains a flag indicating whether the transport
  206. connection should be received directly.
  207. CanMigrateToReceiveAny - equals 1 when the call depth of a receive
  208. direct call is 1 otherwise, it is 0. Used by I_RpcTransMaybeMakeAny,
  209. which is called by the transport to inquire if it is safe to migrate the
  210. thread to ReceiveAny.
  211. --*/
  212. {
  213. private:
  214. RPC_SERVER_TRANSPORT_INFO * ServerInfo;
  215. int ConnectionKey;
  216. int DictKey;
  217. unsigned int ConnectionClosedFlag;
  218. unsigned int ReceiveAnyFlag;
  219. TRANS_ADDRESS * Address;
  220. QUEUE BufferQueue;
  221. EVENT ConnectionEvent;
  222. unsigned int ReceiveDirectFlag;
  223. unsigned int CanMigrateToReceiveAny ;
  224. public:
  225. TRANS_SCONNECTION (
  226. IN TRANS_ADDRESS * TheAddress,
  227. IN RPC_SERVER_TRANSPORT_INFO * ServerInfo,
  228. IN int ConnectionKey,
  229. IN OUT RPC_STATUS PAPI * RpcStatus
  230. );
  231. ~TRANS_SCONNECTION (
  232. );
  233. RPC_STATUS
  234. TransReceive (
  235. IN OUT void * * Buffer,
  236. IN OUT unsigned int * BufferLength,
  237. IN unsigned int CanMigrate
  238. );
  239. int
  240. ConnectionClosed (
  241. );
  242. int
  243. NotifyBufferReceived (
  244. IN void * Buffer,
  245. IN unsigned int BufferLength
  246. );
  247. RPC_STATUS
  248. TransSend (
  249. IN void * Buffer,
  250. IN unsigned int BufferLength
  251. );
  252. RPC_STATUS
  253. TransSendReceive (
  254. IN void * SendBuffer,
  255. IN unsigned int SendBufferLength,
  256. IN OUT void * * ReceiveBuffer,
  257. IN OUT unsigned int * ReceiveBufferLength
  258. );
  259. unsigned int
  260. TransMaximumSend (
  261. );
  262. RPC_STATUS
  263. TransImpersonateClient (
  264. );
  265. void
  266. TransRevertToSelf (
  267. );
  268. void
  269. TransQueryClientProcess (
  270. OUT RPC_CLIENT_PROCESS_IDENTIFIER * ClientProcess
  271. );
  272. RPC_STATUS
  273. TransQueryClientNetworkAddress (
  274. OUT RPC_CHAR ** NetworkAddress
  275. );
  276. void
  277. SetDictKey (
  278. IN int DictKey
  279. );
  280. int
  281. CheckConnectionKey (
  282. IN int ConnectionKey
  283. );
  284. int
  285. MarkReceiveAny (
  286. );
  287. void
  288. MakeReceiveSpecific (
  289. );
  290. RPC_TRANSPORT_CONNECTION
  291. InqRpcTransportConnection (
  292. );
  293. void
  294. SetReceiveDirectFlag (
  295. IN unsigned int ReceiveDirectFlag
  296. );
  297. #if defined(NTENV) || defined(WIN96)
  298. unsigned int
  299. TRANS_SCONNECTION::TransGetReceiveDirectFlag (
  300. );
  301. unsigned int
  302. TRANS_SCONNECTION::TransGetReceiveAnyFlag (
  303. );
  304. unsigned int
  305. TRANS_SCONNECTION::InqMigratePossibleToReceiveAny(
  306. ) ;
  307. void
  308. TRANS_SCONNECTION::SetReceiveAnyFlag(
  309. IN unsigned int Flag
  310. ) ;
  311. unsigned int
  312. TRANS_SCONNECTION::InqReceiveDirectFlag(
  313. ) ;
  314. unsigned int
  315. TRANS_SCONNECTION::InqReceiveAnyFlag(
  316. ) ;
  317. #endif
  318. void * operator new (
  319. unsigned int allocBlock,
  320. char chInit,
  321. unsigned int xtraBytes
  322. );
  323. void
  324. Delete (
  325. );
  326. };
  327. #if defined(NTENV) || defined(WIN96)
  328. inline unsigned int
  329. TRANS_SCONNECTION::InqMigratePossibleToReceiveAny(
  330. )
  331. {
  332. ASSERT(InvalidHandle(SCONNECTION_TYPE) == 0) ;
  333. return CanMigrateToReceiveAny ;
  334. }
  335. inline void
  336. TRANS_SCONNECTION::SetReceiveAnyFlag(
  337. IN unsigned int Flag
  338. )
  339. {
  340. ReceiveAnyFlag = Flag ;
  341. }
  342. inline unsigned int
  343. TRANS_SCONNECTION::InqReceiveDirectFlag(
  344. )
  345. {
  346. return ReceiveDirectFlag ;
  347. }
  348. inline unsigned int
  349. TRANS_SCONNECTION::InqReceiveAnyFlag(
  350. )
  351. {
  352. return ReceiveAnyFlag ;
  353. }
  354. #endif
  355. inline void
  356. TRANS_SCONNECTION::SetDictKey (
  357. IN int DictKey
  358. )
  359. /*++
  360. This routine will be used by TRANS_ADDRESS to set the dictionary key
  361. for this connection.
  362. --*/
  363. {
  364. this->DictKey = DictKey;
  365. }
  366. inline int
  367. TRANS_SCONNECTION::CheckConnectionKey (
  368. IN int ConnectionKey
  369. )
  370. /*++
  371. Routine Description:
  372. This routine is used to determine if this connection has the connection
  373. key specified; it also must not have been closed. A loadable transport
  374. module may reuse a connection key after the connection has closed, but
  375. before the runtime has a chance to delete the TRANS_SCONNECTION object
  376. corresponding to the transport level connection.
  377. Arguments:
  378. ConnectionKey - Supplies the connection key to check against the one
  379. in this connection.
  380. Return Value:
  381. Non-zero will be returned if the supplied connection key is the one for
  382. this connection and the connection is not closed; otherwise, zero will
  383. be returned.
  384. --*/
  385. {
  386. return((( (this->ConnectionKey == ConnectionKey)
  387. && (ConnectionClosedFlag == 0)) ? 1 : 0));
  388. }
  389. inline RPC_TRANSPORT_CONNECTION
  390. TRANS_SCONNECTION::InqRpcTransportConnection (
  391. )
  392. /*++
  393. Return Value:
  394. A pointer to the transport data for this connection will be returned.
  395. --*/
  396. {
  397. return((RPC_TRANSPORT_CONNECTION)
  398. (((char *) this) + sizeof(TRANS_SCONNECTION)));
  399. }
  400. inline void
  401. TRANS_SCONNECTION::MakeReceiveSpecific (
  402. )
  403. /*++
  404. Routine Description:
  405. We need to make this connection be in the receive specific state,
  406. which means that it is not in the receive any state.
  407. --*/
  408. {
  409. ASSERT(InvalidHandle(SCONNECTION_TYPE) == 0) ;
  410. ReceiveAnyFlag = 0;
  411. }
  412. inline void
  413. TRANS_SCONNECTION::SetReceiveDirectFlag (
  414. IN unsigned int ReceiveDirectFlag
  415. )
  416. /*++
  417. Routine Description:
  418. This indicates whether a connection is receive direct or receive any.
  419. --*/
  420. {
  421. ASSERT(InvalidHandle(SCONNECTION_TYPE) == 0) ;
  422. this->ReceiveDirectFlag = ReceiveDirectFlag;
  423. }
  424. #if defined(NTENV) || defined(WIN96)
  425. inline unsigned int
  426. TRANS_SCONNECTION::TransGetReceiveDirectFlag (
  427. )
  428. {
  429. ASSERT(InvalidHandle(SCONNECTION_TYPE) == 0) ;
  430. return ReceiveDirectFlag ;
  431. }
  432. inline unsigned int
  433. TRANS_SCONNECTION::TransGetReceiveAnyFlag (
  434. )
  435. {
  436. ASSERT(InvalidHandle(SCONNECTION_TYPE) == 0) ;
  437. return ReceiveAnyFlag ;
  438. }
  439. #endif
  440. inline void *
  441. TRANS_SCONNECTION::operator new (
  442. unsigned int allocBlock,
  443. char chInit,
  444. unsigned int xtraBytes
  445. )
  446. {
  447. void * pvTemp = RpcpFarAllocate(allocBlock + xtraBytes);
  448. if (pvTemp)
  449. {
  450. memset(pvTemp, chInit, allocBlock + xtraBytes);
  451. }
  452. return(pvTemp);
  453. }
  454. extern RPC_SERVER_TRANSPORT_INFO *
  455. LoadableTransportServerInfo (
  456. IN RPC_CHAR * DllName,
  457. IN RPC_CHAR * RpcProtocolSequence,
  458. OUT RPC_STATUS * Status
  459. );
  460. #endif // __TRANSVR_HXX__