/dep/acelite/ace/SSL/SSL_SOCK_Connector.h

https://gitlab.com/mohsencs/SunWellCore · C Header · 316 lines · 70 code · 31 blank · 215 comment · 0 complexity · 4833a06cd3067ab62af818c728b725ac MD5 · raw file

  1. // -*- C++ -*-
  2. //=============================================================================
  3. /**
  4. * @file SSL_SOCK_Connector.h
  5. *
  6. * @author Ossama Othman <ossama@uci.edu>
  7. * @author Carlos O'Ryan <coryan@uci.edu>
  8. * @author John Heitmann
  9. * @author Chris Zimman
  10. */
  11. //=============================================================================
  12. #ifndef ACE_SSL_SOCK_CONNECTOR_H
  13. #define ACE_SSL_SOCK_CONNECTOR_H
  14. #include /**/ "ace/pre.h"
  15. #include "SSL_Export.h"
  16. #if !defined (ACE_LACKS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif /* ACE_LACKS_PRAGMA_ONCE */
  19. #include "SSL_SOCK_Stream.h"
  20. #include "ace/SOCK_Connector.h"
  21. #include "ace/OS_QoS.h"
  22. ACE_BEGIN_VERSIONED_NAMESPACE_DECL
  23. /**
  24. * @class ACE_SSL_SOCK_Connector
  25. *
  26. * @brief Defines a factory that creates new <ACE_SSL_SOCK_Stream>s
  27. * actively.
  28. *
  29. * The ACE_SSL_SOCK_Connector doesn't have a socket of its own,
  30. * i.e., it simply "borrows" the one from the ACE_SSL_SOCK_Stream
  31. * that's being connected. The reason for this is that the
  32. * underlying socket API doesn't use a "factory" socket to connect
  33. * "data-mode" sockets. Therefore, there's no need to inherit
  34. * ACE_SSL_SOCK_Connector from ACE_SSL_SOCK.
  35. *
  36. * Since SSL is record-oriented, some additional work is done after
  37. * the plain socket is connected.
  38. *
  39. * @note The user must currently ensure that only one thread services
  40. * a given SSL session at any given time since some underlying
  41. * SSL implementations, such as OpenSSL, are not entirely
  42. * thread-safe or reentrant.
  43. */
  44. class ACE_SSL_Export ACE_SSL_SOCK_Connector
  45. {
  46. public:
  47. /// Default constructor.
  48. ACE_SSL_SOCK_Connector (void);
  49. /**
  50. * Actively connect to a peer, producing a connected @c ACE_SSL_SOCK_Stream
  51. * object if the connection succeeds. This method performs both the
  52. * initial socket connect and the SSL handshake.
  53. *
  54. * @param new_stream The @c ACE_SSL_SOCK_Stream object that will be
  55. * connected to the peer.
  56. * @param remote_sap The address that we are trying to connect to.
  57. * The protocol family of @c remote_sap is used for
  58. * the connected socket. That is, if @c remote_sap
  59. * contains an IPv6 address, a socket with family
  60. * PF_INET6 will be used, else it will be PF_INET.
  61. * @param timeout Pointer to an @c ACE_Time_Value object with amount
  62. * of time to wait to connect. If the pointer is 0
  63. * then the call blocks until the connection attempt
  64. * is complete, whether it succeeds or fails. If
  65. * *timeout == {0, 0} then the connection is done
  66. * using nonblocking mode. In this case, if the
  67. * connection can't be made immediately, this method
  68. * returns -1 and errno == EWOULDBLOCK.
  69. * If *timeout > {0, 0} then this is the maximum amount
  70. * of time to wait before timing out; if the specified
  71. * amount of time passes before the connection is made,
  72. * this method returns -1 and errno == ETIME. Note
  73. * the difference between this case and when a blocking
  74. * connect is attempted that TCP times out - in the latter
  75. * case, errno will be ETIMEDOUT.
  76. * @param local_sap (optional) The local address to bind to. If it's
  77. * the default value of @c ACE_Addr::sap_any then the
  78. * OS will choose an unused port.
  79. * @param reuse_addr (optional) If the value is 1, the local address
  80. * (@c local_sap) is reused, even if it hasn't been
  81. * cleaned up yet.
  82. * @param flags Ignored.
  83. * @param perms Ignored.
  84. *
  85. * @return Returns 0 if the connection succeeds. If it fails,
  86. * -1 is returned and errno contains a specific error
  87. * code.
  88. */
  89. ACE_SSL_SOCK_Connector (ACE_SSL_SOCK_Stream &new_stream,
  90. const ACE_Addr &remote_sap,
  91. const ACE_Time_Value *timeout = 0,
  92. const ACE_Addr &local_sap = ACE_Addr::sap_any,
  93. int reuse_addr = 0,
  94. int flags = 0,
  95. int perms = 0);
  96. /**
  97. * Actively connect to a peer, producing a connected @c ACE_SSL_SOCK_Stream
  98. * object if the connection succeeds. This method performs both the
  99. * initial socket connect and the SSL handshake.
  100. *
  101. * @param new_stream The @c ACE_SSL_SOCK_Stream object that will be
  102. * connected to the peer.
  103. * @param remote_sap The address that we are trying to connect to.
  104. * The protocol family of @c remote_sap is used for
  105. * the connected socket. That is, if @c remote_sap
  106. * contains an IPv6 address, a socket with family
  107. * PF_INET6 will be used, else it will be PF_INET.
  108. * @param qos_params Contains QoS parameters that are passed to the
  109. * IntServ (RSVP) and DiffServ protocols.
  110. * @see ACE_QoS_Params.
  111. * @param timeout Pointer to an @c ACE_Time_Value object with amount
  112. * of time to wait to connect. If the pointer is 0
  113. * then the call blocks until the connection attempt
  114. * is complete, whether it succeeds or fails. If
  115. * *timeout == {0, 0} then the connection is done
  116. * using nonblocking mode. In this case, if the
  117. * connection can't be made immediately, this method
  118. * returns -1 and errno == EWOULDBLOCK.
  119. * If *timeout > {0, 0} then this is the maximum amount
  120. * of time to wait before timing out; if the specified
  121. * amount of time passes before the connection is made,
  122. * this method returns -1 and errno == ETIME. Note
  123. * the difference between this case and when a blocking
  124. * connect is attempted that TCP times out - in the latter
  125. * case, errno will be ETIMEDOUT.
  126. * @param local_sap (optional) The local address to bind to. If it's
  127. * the default value of @c ACE_Addr::sap_any then the
  128. * OS will choose an unused port.
  129. * @param reuse_addr (optional) If the value is 1, the local address
  130. * (@c local_sap) is reused, even if it hasn't been
  131. * cleaned up yet.
  132. * @param flags Ignored.
  133. * @param perms Ignored.
  134. *
  135. * @return Returns 0 if the connection succeeds. If it fails,
  136. * -1 is returned and errno contains a specific error
  137. * code.
  138. */
  139. ACE_SSL_SOCK_Connector (ACE_SSL_SOCK_Stream &new_stream,
  140. const ACE_Addr &remote_sap,
  141. ACE_QoS_Params qos_params,
  142. const ACE_Time_Value *timeout = 0,
  143. const ACE_Addr &local_sap = ACE_Addr::sap_any,
  144. ACE_Protocol_Info *protocolinfo = 0,
  145. ACE_SOCK_GROUP g = 0,
  146. u_long flags = 0,
  147. int reuse_addr = 0,
  148. int perms = 0);
  149. /// Default dtor.
  150. ~ACE_SSL_SOCK_Connector (void);
  151. /**
  152. * Actively connect to a peer, producing a connected @c ACE_SSL_SOCK_Stream
  153. * object if the connection succeeds. This method performs both the
  154. * initial socket connect and the SSL handshake.
  155. *
  156. * @param new_stream The @c ACE_SSL_SOCK_Stream object that will be
  157. * connected to the peer.
  158. * @param remote_sap The address that we are trying to connect to.
  159. * The protocol family of @c remote_sap is used for
  160. * the connected socket. That is, if @c remote_sap
  161. * contains an IPv6 address, a socket with family
  162. * PF_INET6 will be used, else it will be PF_INET.
  163. * @param timeout Pointer to an @c ACE_Time_Value object with amount
  164. * of time to wait to connect. If the pointer is 0
  165. * then the call blocks until the connection attempt
  166. * is complete, whether it succeeds or fails. If
  167. * *timeout == {0, 0} then the connection is done
  168. * using nonblocking mode. In this case, if the
  169. * connection can't be made immediately, this method
  170. * returns -1 and errno == EWOULDBLOCK.
  171. * If *timeout > {0, 0} then this is the maximum amount
  172. * of time to wait before timing out; if the specified
  173. * amount of time passes before the connection is made,
  174. * this method returns -1 and errno == ETIME. Note
  175. * the difference between this case and when a blocking
  176. * connect is attempted that TCP times out - in the latter
  177. * case, errno will be ETIMEDOUT.
  178. * @param local_sap (optional) The local address to bind to. If it's
  179. * the default value of @c ACE_Addr::sap_any then the
  180. * OS will choose an unused port.
  181. * @param reuse_addr (optional) If the value is 1, the local address
  182. * (@c local_sap) is reused, even if it hasn't been
  183. * cleaned up yet.
  184. * @param flags Ignored.
  185. * @param perms Ignored.
  186. *
  187. * @return Returns 0 if the connection succeeds. If it fails,
  188. * -1 is returned and errno contains a specific error
  189. * code.
  190. */
  191. int connect (ACE_SSL_SOCK_Stream &new_stream,
  192. const ACE_Addr &remote_sap,
  193. const ACE_Time_Value *timeout = 0,
  194. const ACE_Addr &local_sap = ACE_Addr::sap_any,
  195. int reuse_addr = 0,
  196. int flags = 0,
  197. int perms = 0);
  198. /**
  199. * Actively connect to a peer, producing a connected @c ACE_SSL_SOCK_Stream
  200. * object if the connection succeeds. This method performs both the
  201. * initial socket connect and the SSL handshake.
  202. *
  203. * @param new_stream The @c ACE_SSL_SOCK_Stream object that will be
  204. * connected to the peer.
  205. * @param remote_sap The address that we are trying to connect to.
  206. * The protocol family of @c remote_sap is used for
  207. * the connected socket. That is, if @c remote_sap
  208. * contains an IPv6 address, a socket with family
  209. * PF_INET6 will be used, else it will be PF_INET.
  210. * @param qos_params Contains QoS parameters that are passed to the
  211. * IntServ (RSVP) and DiffServ protocols.
  212. * @see ACE_QoS_Params.
  213. * @param timeout Pointer to an @c ACE_Time_Value object with amount
  214. * of time to wait to connect. If the pointer is 0
  215. * then the call blocks until the connection attempt
  216. * is complete, whether it succeeds or fails. If
  217. * *timeout == {0, 0} then the connection is done
  218. * using nonblocking mode. In this case, if the
  219. * connection can't be made immediately, this method
  220. * returns -1 and errno == EWOULDBLOCK.
  221. * If *timeout > {0, 0} then this is the maximum amount
  222. * of time to wait before timing out; if the specified
  223. * amount of time passes before the connection is made,
  224. * this method returns -1 and errno == ETIME. Note
  225. * the difference between this case and when a blocking
  226. * connect is attempted that TCP times out - in the latter
  227. * case, errno will be ETIMEDOUT.
  228. * @param local_sap (optional) The local address to bind to. If it's
  229. * the default value of @c ACE_Addr::sap_any then the
  230. * OS will choose an unused port.
  231. * @param reuse_addr (optional) If the value is 1, the local address
  232. * (@c local_sap) is reused, even if it hasn't been
  233. * cleaned up yet.
  234. * @param flags Ignored.
  235. * @param perms Ignored.
  236. *
  237. * @return Returns 0 if the connection succeeds. If it fails,
  238. * -1 is returned and errno contains a specific error
  239. * code.
  240. */
  241. int connect (ACE_SSL_SOCK_Stream &new_stream,
  242. const ACE_Addr &remote_sap,
  243. ACE_QoS_Params qos_params,
  244. const ACE_Time_Value *timeout = 0,
  245. const ACE_Addr &local_sap = ACE_Addr::sap_any,
  246. ACE_Protocol_Info *protocolinfo = 0,
  247. ACE_SOCK_GROUP g = 0,
  248. u_long flags = 0,
  249. int reuse_addr = 0,
  250. int perms = 0);
  251. /**
  252. * Try to complete a non-blocking connection.
  253. * If connection completion is successful then <new_stream> contains
  254. * the connected ACE_SSL_SOCK_Stream. If <remote_sap> is non-NULL
  255. * then it will contain the address of the connected peer.
  256. */
  257. int complete (ACE_SSL_SOCK_Stream &new_stream,
  258. ACE_Addr *remote_sap = 0,
  259. const ACE_Time_Value *timeout = 0);
  260. /// Resets any event associations on this handle
  261. bool reset_new_handle (ACE_HANDLE handle);
  262. /// Meta-type info
  263. //@{
  264. typedef ACE_INET_Addr PEER_ADDR;
  265. typedef ACE_SSL_SOCK_Stream PEER_STREAM;
  266. //@}
  267. /// Dump the state of an object.
  268. void dump (void) const;
  269. /// Declare the dynamic allocation hooks.
  270. ACE_ALLOC_HOOK_DECLARE;
  271. protected:
  272. /// Complete non-blocking SSL active connection.
  273. int ssl_connect (ACE_SSL_SOCK_Stream &new_stream,
  274. const ACE_Time_Value *timeout);
  275. private:
  276. /// The class that does all of the non-secure socket connection.
  277. /// It is default contructed, and subsequently used by connect().
  278. ACE_SOCK_Connector connector_;
  279. };
  280. ACE_END_VERSIONED_NAMESPACE_DECL
  281. #if defined (__ACE_INLINE__)
  282. #include "SSL_SOCK_Connector.inl"
  283. #endif /* __ACE_INLINE__ */
  284. #include /**/ "ace/post.h"
  285. #endif /* ACE_SSL_SOCK_CONNECTOR_H */