socket.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // s.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 08/04/97 BRH Started the socket over again with plugin protocols
  23. //
  24. // 08/12/97 MJR Added mac protocols.
  25. //
  26. // 08/20/97 MJR Added support for setting whether socket blocks or not.
  27. //
  28. ////////////////////////////////////////////////////////////////////////////////
  29. #ifndef SOCKET_H
  30. #define SOCKET_H
  31. #include "RSPiX.h"
  32. ////////////////////////////////////////////////////////////////////////////////
  33. //
  34. // NOTE: There's more #include's at the end of this file!
  35. //
  36. // This was necessary because all the "plugin" protocols needed the definition
  37. // of the RSocket class, but at the same time, we didn't want make everyone
  38. // that uses RSocket to #include the invidual protocol header files. No big
  39. // deal -- it just seemed worth explaining why the #include's are at the end.
  40. //
  41. ////////////////////////////////////////////////////////////////////////////////
  42. // Use this to enable APPLETALK protocol when support for it has been added
  43. #define ENABLE_APPLETALK 0
  44. class RSocket
  45. {
  46. //------------------------------------------------------------------------------
  47. // Types, enums, etc.
  48. //------------------------------------------------------------------------------
  49. public:
  50. // Blocking callback
  51. typedef short (*BLOCK_CALLBACK) (void);
  52. // Supported protocols
  53. typedef enum
  54. {
  55. NO_PROTOCOL = 0, // No protocol (MUST BE 0!!!)
  56. FirstProtocol = 1, // First protocol (used when iterating protocol types)
  57. TCPIP = 1, // WinSock or BSD Sockets TCP/IP
  58. NumProtocols // Number of protocol types
  59. } ProtoType;
  60. // Miscellaneous stuff
  61. enum
  62. {
  63. // Socket types
  64. typStream = 0, // Stream-oriented connection
  65. typDatagram = 1, // Datagram-oriented connection
  66. // Available socket options
  67. optDontBlock = 0x0001, // Don't block
  68. optDontWaitOnClose = 0x0002, // Don't wait on Close() (applies to typStream only)
  69. optDontCoalesce = 0x0004, // Dont coalesce data (applies to typStream only)
  70. // Special error return values
  71. errWouldBlock = 1000, // Function would have blocked, but "optDontBlock" was set
  72. errNotSupported = 1001, // Protocol is not supported
  73. // This is the maximum size of any protocol's address
  74. MaxAddressSize = 16
  75. };
  76. // This is a generic address
  77. typedef struct tAddress
  78. {
  79. public:
  80. ProtoType prototype; // Type of protocol
  81. long lAddressLen; // Actual address length (depends on protocol, always <= MaxAddressSize)
  82. char address[MaxAddressSize]; // Raw address (interpretation depends on protocol type)
  83. // Note: operator== is defined at global scope, outside this class definition,
  84. // because it needs access to each protocol's specific address type, which isn't
  85. // defined until after this class.
  86. void Reset(void)
  87. {
  88. prototype = NO_PROTOCOL;
  89. lAddressLen = 0;
  90. memset(address, 0, sizeof(address));
  91. }
  92. } Address;
  93. // Value indicating which socket function, if any, is currenly being executed.
  94. // This allows a callback to determine which function is being executed, which
  95. // may help it decide what to do. Under WinSock, aborting certain functions
  96. // causes the socket to become unstable. See WinSock docs for details.
  97. typedef enum
  98. {
  99. NoFunc, // none
  100. SelectFunc, // select()
  101. AcceptFunc, // accept()
  102. OtherFunc // all other functions
  103. } FuncNum;
  104. //------------------------------------------------------------------------------
  105. // Protocol class, which is the basis of the "plug-in" architecture
  106. //------------------------------------------------------------------------------
  107. public:
  108. class RProtocol
  109. {
  110. //------------------------------------------------------------------------------
  111. // Types, enums, etc.
  112. //------------------------------------------------------------------------------
  113. public:
  114. //------------------------------------------------------------------------------
  115. // Variables
  116. //------------------------------------------------------------------------------
  117. public:
  118. bool m_bListening; // Whether socket is listening (true) or not (false)
  119. bool m_bConnecting; // Whether socket is trying to connect (true) or not (false)
  120. bool m_bConnected; // Whether socket is connected (true) or not (false)
  121. BLOCK_CALLBACK m_callback; // Callback (defaults to 0, which means none)
  122. //------------------------------------------------------------------------------
  123. // Static Variables
  124. //------------------------------------------------------------------------------
  125. public:
  126. static ProtoType ms_prototype; // Current protocol type (there can be only one "current" type)
  127. //------------------------------------------------------------------------------
  128. // Functions
  129. //------------------------------------------------------------------------------
  130. public:
  131. // Constructor
  132. RProtocol()
  133. {
  134. Init();
  135. }
  136. // Destructor
  137. virtual ~RProtocol()
  138. {
  139. }
  140. // Restart the object without deleting it.
  141. // NOTE: Derived classes MUST call base class implimentation!
  142. virtual void Reset(void)
  143. {
  144. Init();
  145. }
  146. // Open a new connection.
  147. // A return value of RSocket::errNotSupported means this protocol is
  148. // not supported.
  149. virtual short Open( // Returns 0 if connection was opened
  150. unsigned short usPort, // In: Port number on which to make a connection
  151. short sType, // In: Any one RSocket::typ* enum
  152. short sOptionFlags, // In: Any combo of RSocket::opt* enums
  153. BLOCK_CALLBACK callback = NULL) // In: Blocking callback (or NULL to keep current callback)
  154. = 0;
  155. // Close a connection
  156. virtual short Close( // Returns 0 if successfull, non-zero otherwise
  157. bool bForceNow = true) // In: 'true' means do it now, false follows normal rules
  158. = 0;
  159. // Set socket to broadcast mode
  160. virtual short Broadcast(void) // Returns 0 if successfull, non-zero otherwise
  161. = 0;
  162. // Listen for connection requests
  163. virtual short Listen( // Returns 0 if listen port established
  164. short sMaxQueued) // In: Maximum number of queueued connection requests
  165. = 0;
  166. // Accept request for connection
  167. virtual short Accept( // Returns 0 if accepted
  168. RProtocol* pProtocol, // Out: Client's protocol
  169. Address* paddress) // Out: Client's address returned here
  170. = 0;
  171. // Connect to address.
  172. // If the RSocket::optDontBlock option was set on this socket, then this
  173. // function may return RSocket::errWouldBlock, which indicates that it is
  174. // still trying to connect, but has not yet managed to do so. In that case,
  175. // this function should be called repeatedly (polled) until it returns either
  176. // an actual error message other than RSocket::errWouldBlock, which would
  177. // indicate that the connection attempt has failed, or 0, which indicates
  178. // that it has actually connected successfully.
  179. virtual short Connect( // Returns 0 if connected
  180. Address* paddress) // In: Remote address to connect to
  181. = 0;
  182. // Send data - only valid with connected sockets
  183. virtual short Send( // Returns 0 if data was sent
  184. void * pBuf, // In: Pointer to data buffer
  185. long lNumBytes, // In: Number of bytes to send
  186. long *plActualBytes) // Out: Acutal number of bytes sent
  187. = 0;
  188. // SendTo - send data to specified address - for unconnected sockets
  189. virtual short SendTo( // Returns 0 if data was sent
  190. void* pBuf, // In: Pointer to data buffer
  191. long lNumBytes, // In: Number of bytes to send
  192. long* plActualBytes, // Out: Actual number of bytes sent
  193. Address* paddress) // In: Address to send to
  194. = 0;
  195. // Receive data - only valid for connected sockets
  196. virtual short Receive( // Returns 0 if data was received
  197. void* pBuf, // In: Pointer to data buffer
  198. long lMaxBytes, // In: Maximum number of bytes that fit in the buffer
  199. long* plActualBytes) // Out: Actual number of bytes received into buffer
  200. = 0;
  201. // RecieveFrom - receive data from given address
  202. virtual short ReceiveFrom( // Returns 0 if data was received
  203. void* pBuf, // In: Pointer to data buffer
  204. long lMaxBytes, // In: Maximum bytes that can fit in buffer
  205. long* plActualBytes, // Out: Actual number of bytes received into buffer
  206. Address* paddress) // Out: Source address returned here
  207. = 0;
  208. // Status functions
  209. virtual bool IsError(void) = 0;
  210. virtual bool CanAcceptWithoutBlocking(void) = 0;
  211. virtual bool CanSendWithoutBlocking(void) = 0;
  212. virtual bool CanReceiveWithoutBlocking(void) = 0;
  213. virtual long CheckReceivableBytes(void) = 0;
  214. // Set callback function
  215. virtual void SetCallback(BLOCK_CALLBACK callback) = 0;
  216. // Get callback function
  217. virtual BLOCK_CALLBACK GetCallback(void) = 0;
  218. protected:
  219. // Init
  220. // NOTE: Derived classes MUST call base class implimentation!
  221. virtual void Init(void)
  222. {
  223. m_bListening = false;
  224. m_bConnected = false;
  225. m_callback = 0;
  226. }
  227. };
  228. //------------------------------------------------------------------------------
  229. // Variables
  230. //------------------------------------------------------------------------------
  231. public:
  232. RProtocol* m_pProtocol; // Pointer to protocol object
  233. //------------------------------------------------------------------------------
  234. // Static Variables
  235. //------------------------------------------------------------------------------
  236. protected:
  237. static bool ms_bDidStartup; // Whether Startup() was called successfully
  238. static bool ms_bAutoShutdown; // Whether to call Shutdown() automatically
  239. static short ms_sNumSockets; // Number of sockets in existance
  240. static RSocket::ProtoType ms_prototype; // Current protocol (can only be one "current" protocol)
  241. static char* ms_apszProtoNames[]; // String names corresponding to RSocket::ProtoType values
  242. //------------------------------------------------------------------------------
  243. // Functions
  244. //------------------------------------------------------------------------------
  245. public:
  246. ////////////////////////////////////////////////////////////////////////////////
  247. // Constructor
  248. ////////////////////////////////////////////////////////////////////////////////
  249. RSocket();
  250. ////////////////////////////////////////////////////////////////////////////////
  251. // Destructor
  252. ////////////////////////////////////////////////////////////////////////////////
  253. ~RSocket();
  254. ////////////////////////////////////////////////////////////////////////////////
  255. // Reset socket to its post-construction state
  256. ////////////////////////////////////////////////////////////////////////////////
  257. void Reset(void);
  258. ////////////////////////////////////////////////////////////////////////////////
  259. // Open socket in datagram or stream mode.
  260. //
  261. // If the current protocol is not supported, this function returns the value
  262. // RSocket::errNotSupported.
  263. ////////////////////////////////////////////////////////////////////////////////
  264. short Open( // Returns 0 if successfull, non-zero otherwise
  265. unsigned short usPort, // In: Port number or 0 for any port
  266. short sType, // In: Any one RSocket::typ* enum
  267. short sOptionFlags, // In: Any combo of RSocket::opt* enums
  268. BLOCK_CALLBACK callback = NULL); // In: Blocking callback (or NULL to keep current callback)
  269. ////////////////////////////////////////////////////////////////////////////////
  270. // Close socket
  271. ////////////////////////////////////////////////////////////////////////////////
  272. short Close( // Returns 0 if successfull, non-zero otherwise
  273. bool bForceNow = false); // In: 'true' means do it now, false follows normal rules
  274. ////////////////////////////////////////////////////////////////////////////////
  275. // Set socket to broadcast mode
  276. //
  277. // Most protocols only allow broadcasting on a datagram-style socket.
  278. ////////////////////////////////////////////////////////////////////////////////
  279. short Broadcast(void); // Returns 0 if successfull, non-zero otherwise
  280. ////////////////////////////////////////////////////////////////////////////////
  281. // Set socket to listen for connection requests
  282. //
  283. // Some protocols are limited to some maximum number of queued connections.
  284. // For instance, WinSock only allows for 5. Requesting more than 5 queued
  285. // connections will cause this function to return an error.
  286. ////////////////////////////////////////////////////////////////////////////////
  287. short Listen( // Returns 0 if successfull, non-zero otherwise
  288. short sMaxQueued = 5); // In: Maximum number of queued connection requests
  289. ////////////////////////////////////////////////////////////////////////////////
  290. // Accept request for connection.
  291. //
  292. // If this function fails, the specified client socket and address may have
  293. // been modified, but any such changes must not be relied upon!!! What can be
  294. // relied upon is that the client socket will be in a "closed" state.
  295. ////////////////////////////////////////////////////////////////////////////////
  296. short Accept( // Returns 0 if successfull, non-zero otherwise
  297. RSocket* psocketClient, // Out: Client socket returned here
  298. Address* paddressClient) // Out: Client's address returned here (unless this is NULL)
  299. const;
  300. ////////////////////////////////////////////////////////////////////////////////
  301. // Connect to address.
  302. //
  303. // If the RSocket::optDontBlock option was set on this socket, then this
  304. // function may return RSocket::errWouldBlock, which indicates that it is
  305. // still trying to connect, but has not yet managed to do so. In that case,
  306. // this function should be called repeatedly (polled) until it returns either
  307. // an actual error message other than RSocket::errWouldBlock, which would
  308. // indicate that the connection attempt has failed, or 0, which indicates
  309. // that it has actually connected successfully.
  310. ////////////////////////////////////////////////////////////////////////////////
  311. short Connect( // Returns 0 if successfull, non-zero otherwise
  312. Address* paddress); // In: Remote address to connect to
  313. ////////////////////////////////////////////////////////////////////////////////
  314. // Send data (only valid for connected sockets -- see also SendTo())
  315. //
  316. // For datagram (UDP) sockets, there is a one-to-one correspondence between
  317. // sends and receives. Each send implies a matching receive. The amount of
  318. // data sent must fit into a single block, whose size can be determined by
  319. // calling GetMaxDatagramSize().
  320. //
  321. // For stream (TCP) sockets, there is no direct correspondence between sends
  322. // and receive. One send can be broken up and require multiple receives, and
  323. // and multiple sends can be coalesced into a single recieve. There is no
  324. // limitation on the amount of data being sent.
  325. ////////////////////////////////////////////////////////////////////////////////
  326. short Send( // Return 0 if successfull, non-zero otherwise
  327. void* pBuf, // In: Pointer to data buffer
  328. long lNumBytes, // In: Number of bytes to send
  329. long* plActualBytes); // Out: Actual number of bytes sent
  330. ////////////////////////////////////////////////////////////////////////////////
  331. // Send data to specified address. For connected sockets, address is ignored.
  332. // See Send() for more information.
  333. ////////////////////////////////////////////////////////////////////////////////
  334. short SendTo( // Return 0 if successfull, non-zero otherwise
  335. void* pBuf, // In: Pointer to data buffer
  336. long lNumBytes, // In: Number of bytes to send
  337. long* plActualBytes, // Out: Actual number of bytes sent
  338. Address* paddress); // In: Address to send to
  339. ////////////////////////////////////////////////////////////////////////////////
  340. // Receive data (only valid for connected sockets -- see also ReceiveFrom())
  341. //
  342. // For datagram (UDP) sockets, there is a one-to-one correspondence between
  343. // sends and receives. Each send implies a matching receive. The specified
  344. // buffer must at least as large as the amount of data that was sent, or the
  345. // data will be truncated and an error will be returned.
  346. //
  347. // For stream (TCP) sockets, there is no direct correspondence between sends
  348. // and receive. One send can be broken up and require multiple receives, and
  349. // and multiple sends can be coalesced into a single recieve. There is no
  350. // limitation on the amount of data being received.
  351. //
  352. // For stream (TCP) sockets, if the actual number of bytes received is 0, it
  353. // means the other end disconnected gracefully.
  354. //
  355. // In all cases, if the connection was abortively disconnected, an error will
  356. // be returned.
  357. ////////////////////////////////////////////////////////////////////////////////
  358. short Receive( // Returns 0 if successfull, non-zero otherwise
  359. void* pBuf, // In: Pointer to data buffer
  360. long lMaxBytes, // In: Maximum bytes that can fit in buffer
  361. long* plActualBytes); // Out: Actual number of bytes received into buffer
  362. ////////////////////////////////////////////////////////////////////////////////
  363. // Receive data and get source address. See Receive() for more information.
  364. ////////////////////////////////////////////////////////////////////////////////
  365. short ReceiveFrom( // Returns 0 if successfull, non-zero otherwise
  366. void* pBuf, // In: Pointer to data buffer
  367. long lMaxBytes, // In: Maximum bytes that can fit in buffer
  368. long* plActualBytes, // Out: Actual number of bytes received into buffer
  369. Address* paddress); // Out: Source address returned here (unless this is NULL)
  370. ////////////////////////////////////////////////////////////////////////////////
  371. // Status functions
  372. ////////////////////////////////////////////////////////////////////////////////
  373. bool IsError(void); // Returns true if there's an error (no error if not open)
  374. bool IsOpen(void) // Returns true if socket is open
  375. { return m_pProtocol ? true : false; }
  376. bool IsListening(void) // Returns true if socket is listening
  377. { return m_pProtocol ? m_pProtocol->m_bListening : false; }
  378. bool IsConnecting(void) // Returns true if socket is trying to connect
  379. { return m_pProtocol ? m_pProtocol->m_bConnecting : false; }
  380. bool IsConnected(void) // Returns true if socket is connected
  381. { return m_pProtocol ? m_pProtocol->m_bConnected: false; }
  382. bool CanAcceptWithoutBlocking(void);
  383. bool CanSendWithoutBlocking(void);
  384. bool CanReceiveWithoutBlocking(void);
  385. long CheckReceivableBytes(void);
  386. ////////////////////////////////////////////////////////////////////////////////
  387. // Set callback function. Setting callback to 0 disables the callback function.
  388. ////////////////////////////////////////////////////////////////////////////////
  389. void SetCallback( // Returns 0 if successfull, non-zero otherwise
  390. RSocket::BLOCK_CALLBACK callback) // In: New callback function (0 disables callback)
  391. {
  392. if (m_pProtocol)
  393. m_pProtocol->SetCallback(callback);
  394. }
  395. ////////////////////////////////////////////////////////////////////////////////
  396. // Get callback function
  397. ////////////////////////////////////////////////////////////////////////////////
  398. RSocket::BLOCK_CALLBACK GetCallback(void) // Returns 0 if successfull, non-zero otherwise
  399. {
  400. if (m_pProtocol)
  401. return m_pProtocol->GetCallback();
  402. else
  403. return NULL;
  404. }
  405. ////////////////////////////////////////////////////////////////////////////////
  406. // Startup socket API. This is normally called automatically when the first
  407. // RSocket is constructed, but can also be called "manually" so that other
  408. // static member functions may be called.
  409. ////////////////////////////////////////////////////////////////////////////////
  410. static
  411. short Startup( // Returns 0 if successfull, non-zero otherwise
  412. RSocket::ProtoType prototype, // In: Protocol type
  413. bool bAutoShutdown); // In: Whether to perform auto Shutdown()
  414. ////////////////////////////////////////////////////////////////////////////////
  415. // Shutdown socket API. This is normally called automatically when the last
  416. // RSocket is destroyed. It is highly recommended that this NOT be called
  417. // manually, because any existing RSocket's will be invalidated.
  418. ////////////////////////////////////////////////////////////////////////////////
  419. static
  420. void Shutdown(void);
  421. ////////////////////////////////////////////////////////////////////////////////
  422. // Get maximum datagram size (applies to UDP only). The minimum value is
  423. // supposed to be 512 bytes, but it is probably worth checking to be sure.
  424. // A value of 0 indicates that there is no limitation on size.
  425. ////////////////////////////////////////////////////////////////////////////////
  426. static
  427. short GetMaxDatagramSize( // Returns 0 if successfull, non-zero otherwise
  428. long* plSize); // Out: Maximum datagram size (in bytes)
  429. ////////////////////////////////////////////////////////////////////////////////
  430. // Get maximum number of sockets. This may be a system "global" value, which
  431. // means that if other applications are using sockets, then the number available
  432. // to this application may be lower than the returned value.
  433. ////////////////////////////////////////////////////////////////////////////////
  434. static
  435. short GetMaxSockets( // Returns 0 if successfull, non-zero otherwise
  436. long* plNum); // Out: Maximum number of sockets
  437. ////////////////////////////////////////////////////////////////////////////////
  438. // Get address of specified host
  439. ////////////////////////////////////////////////////////////////////////////////
  440. static
  441. short GetAddress( // Returns 0 if successfull, non-zero otherwise
  442. char* pszName, // In: Host's name or dotted address (x.x.x.x)
  443. USHORT usPort, // In: Host's port number
  444. Address* paddress); // Out: Address
  445. ////////////////////////////////////////////////////////////////////////////////
  446. // Create broadcast address using specified port
  447. ////////////////////////////////////////////////////////////////////////////////
  448. static void CreateBroadcastAddress(
  449. unsigned short usPort, // In: Port to broadcast to
  450. RSocket::Address* paddress); // Out: Broadcast address returned here
  451. ////////////////////////////////////////////////////////////////////////////////
  452. // Get the port of an existing (valid) address
  453. ////////////////////////////////////////////////////////////////////////////////
  454. static
  455. unsigned short GetAddressPort( // Returns port number
  456. Address* paddress); // In: Address to get port from
  457. ////////////////////////////////////////////////////////////////////////////////
  458. // Set the port of an existing (valid) address
  459. ////////////////////////////////////////////////////////////////////////////////
  460. static
  461. void SetAddressPort(
  462. USHORT usPort, // In: New port number
  463. Address* paddress); // I/O: Address whose port is to be set
  464. ////////////////////////////////////////////////////////////////////////////////
  465. // Get the name of the specified protocol. This will always return a valid
  466. // pointer to a text string, even if the specified protocol is not valid. In
  467. // such cases, the returned pointer will refer to an empty string.
  468. ////////////////////////////////////////////////////////////////////////////////
  469. static
  470. const char* GetProtoName( // Returns pointer to protocol's name
  471. ProtoType prototype) // In: Protocol type
  472. {
  473. if (prototype >= NumProtocols)
  474. prototype = NO_PROTOCOL;
  475. return ms_apszProtoNames[prototype];
  476. }
  477. ////////////////////////////////////////////////////////////////////////////////
  478. // Get the name of the current protocol
  479. ////////////////////////////////////////////////////////////////////////////////
  480. static
  481. const char* GetProtoName(void) // Returns pointer to protocol's name
  482. {
  483. return GetProtoName(ms_prototype);
  484. }
  485. ////////////////////////////////////////////////////////////////////////////////
  486. // Get the current protocol type
  487. ////////////////////////////////////////////////////////////////////////////////
  488. static
  489. RSocket::ProtoType GetProtoType(void)
  490. {
  491. return ms_prototype;
  492. }
  493. protected:
  494. ////////////////////////////////////////////////////////////////////////////////
  495. // Create specified protocol object
  496. ////////////////////////////////////////////////////////////////////////////////
  497. static
  498. RProtocol* ConstructProtocol( // Returns pointer to prototype if successfull, 0 otherwise
  499. ProtoType prototype); // In: Protocol type to create
  500. };
  501. #include "ProtoBSDIP.h"
  502. // operator== cannot be defined until after all the protocol address types have been defined.
  503. inline bool operator==(const RSocket::Address& lhs, const RSocket::Address& rhs)
  504. {
  505. switch (lhs.prototype)
  506. {
  507. case RSocket::TCPIP:
  508. return (*((const RProtocolBSDIP::AddressIP*)&lhs) == *((const RProtocolBSDIP::AddressIP*)&rhs));
  509. break;
  510. }
  511. TRACE("RSocket::Address::operator==(): Unknown protocol!\n");
  512. return false;
  513. }
  514. #endif //SOCKET_H
  515. ////////////////////////////////////////////////////////////////////////////////
  516. // EOF
  517. ////////////////////////////////////////////////////////////////////////////////