]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/portability/udp_sockets.hpp
cleanup stlplus files
[chaz/yoink] / src / stlplus / portability / udp_sockets.hpp
index 5097d44c0f334becf7514edb9fa563b3d9c75dc6..b6be81a3e9fc62ee4c9b4be21d051d480921117f 100644 (file)
-#ifndef STLPLUS_UDP_SOCKET\r
-#define STLPLUS_UDP_SOCKET\r
-////////////////////////////////////////////////////////////////////////////////\r
-\r
-// Author:    Andy Rushton\r
-// Copyright: (c) Southampton University 1999-2004\r
-//            (c) Andy Rushton           2004-2009\r
-// License:   BSD License, see ../docs/license.html\r
-\r
-// A platform-independent (Unix and Windows anyway) interface to UDP sockets\r
-\r
-////////////////////////////////////////////////////////////////////////////////\r
-\r
-#include "portability_fixes.hpp"\r
-#include "ip_sockets.hpp"\r
-#include <string>\r
-\r
-namespace stlplus\r
-{\r
-\r
-  //////////////////////////////////////////////////////////////////////////////\r
-  // UDP client - creates a connectioned socket\r
-\r
-  class UDP_client : protected IP_socket\r
-  {\r
-  public:\r
-\r
-    // create an uninitialised socket\r
-    UDP_client(void);\r
-\r
-    // Send/Receive datagram packets to/from the given address/remote port on the local port.\r
-    // - remote_address: IP name or number of remote host\r
-    // - remote_port: port number of remote host\r
-    // - local_port: port number to receive on - 0 to get an ephemeral port.\r
-    UDP_client(const std::string& remote_address, unsigned short remote_port, unsigned short local_port=0);\r
-\r
-    // Send/Receive datagram packets to/from the given address/remote port on the given local port\r
-    // Enables default send to remote address/port\r
-    // - remote_address: IP address of remote host - pre-looked-up using ip_lookup\r
-    // - remote_port: port number of remote host\r
-    // - local_port: port number to receive on - 0 to get an ephemeral port.\r
-    UDP_client(unsigned long remote_address, unsigned short remote_port, unsigned short local_port=0);\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-    // initialisation, connection\r
-\r
-    // function for performing IP lookup (i.e. gethostbyname)\r
-    // could be standalone but making it a member means that it can use the socket's error handler\r
-    // i.e. if this fails, the sockets error code will be set - clear it to use the socket again\r
-    // - remote_address: IP name (stlplus.sourceforge.net) or dotted number (216.34.181.96)\r
-    // - returns the IP address as a long integer - zero if there's an error\r
-    // unsigned long ip_lookup(const std::string& remote_address);\r
-    using IP_socket::ip_lookup;\r
-\r
-    // Send/Receive datagram packets to/from the given address/remote port on the local port.\r
-    // Enables default send to remote address/port\r
-    // - remote_address: IP name or number of remote host\r
-    // - remote_port: port number of remote host\r
-    // - local_port: port number to receive on - 0 to get an ephemeral port.\r
-    // - returns a success flag\r
-    bool initialise(const std::string& remote_address, unsigned short remote_port, unsigned short local_port=0);\r
-\r
-    // Send/Receive datagram packets to/from the given address/remote port on the given local port\r
-    // Enables default send to remote address/port\r
-    // - remote_address: IP address of remote host - pre-looked-up using ip_lookup\r
-    // - remote_port: port number of remote host\r
-    // - local_port: port number to receive on - 0 to get an ephemeral port.\r
-    // - returns a success flag\r
-    bool initialise(unsigned long remote_address, unsigned short remote_port, unsigned short local_port=0);\r
-\r
-    // test whether this is an initialised socket\r
-    // - returns whether this is initialised\r
-    // bool initialised(void) const;\r
-    using IP_socket::initialised;\r
-\r
-    // close, i.e. disconnect the socket\r
-    // - returns a success flag\r
-    // bool close(void);\r
-    using IP_socket::close;\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-    // sending/receiving\r
-\r
-    // test whether a socket is connected and ready to send data, returns if ready or on timeout\r
-    // - timeout: how long to wait in microseconds if not connected yet (blocking)\r
-    // - returns status\r
-    // bool send_ready(unsigned timeout = 0);\r
-    using IP_socket::send_ready;\r
-\r
-    // send to the remote address/port setup in initialise, from the local port also setup in initialise.\r
-    // send data through the socket as a single datagram\r
-    // - packet: string containing data to be sent - if data is successfully sent it is removed\r
-    // - returns success flag\r
-    bool send(std::string& packet);\r
-\r
-    // test whether a socket is connected and ready to receive data, returns if ready or on timeout\r
-    // - timeout: how long to wait in microseconds if not connected yet (blocking)\r
-    // - returns status\r
-    // bool receive_ready(unsigned timeout = 0);\r
-    using IP_socket::receive_ready;\r
-\r
-    // datagram receive\r
-    // - packet: string to receive data from datagram - if data is successfully sent it is appended\r
-    // - returns success flag - i.e. packet successfully received\r
-    bool receive(std::string& packet);\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-    // informational\r
-\r
-    // the local port number of the connection\r
-    // returns the port number, 0 if not bound to a port\r
-    // unsigned short local_port(void) const;\r
-    using IP_socket::local_port;\r
-\r
-    // the remote address of the connection\r
-    // returns the address, 0 if ANY address\r
-    // unsigned long remote_address(void) const;\r
-    using IP_socket::remote_address;\r
-\r
-    // the remote port number of the connection\r
-    // returns the port number, 0 if not bound to a port\r
-    // unsigned short remote_port(void) const;\r
-    using IP_socket::remote_port;\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-    // error handling\r
-    // errors are set internally\r
-    // an error code of 0 is the test for no error, don't rely on the message being an empty string\r
-    // an error code != 0 means an error, then there will be a message explaining the error\r
-\r
-    // if an error is set it stays set - so you must clear it before further operations\r
-    // void clear_error (void);\r
-    using IP_socket::clear_error ;\r
-\r
-    // get the error code of the last error\r
-    // int error(void) const;\r
-    using IP_socket::error;\r
-\r
-    // get the explanatory message of the last error\r
-    // std::string message(void) const;\r
-    using IP_socket::message;\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-\r
-  private:\r
-    IP_socket m_socket;\r
-  };\r
-\r
-  ////////////////////////////////////////////////////////////////////////////////\r
-  // UDP server - creates a connectionless (multicast) listener socket\r
-\r
-  class UDP_server : protected IP_socket\r
-  {\r
-  public:\r
-\r
-    // create an uninitialised socket\r
-    UDP_server(void);\r
-\r
-    // Initialise socket.\r
-    // Receive datagram packets from any address on provided local receiving port.\r
-    // - local_port: port number to receive on - 0 to get an ephemeral port.\r
-    UDP_server(unsigned short local_port);\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-    // initialisation, connection\r
-\r
-    // function for performing IP lookup (i.e. gethostbyname)\r
-    // could be standalone but making it a member means that it can use the socket's error handler\r
-    // i.e. if this fails, the sockets error code will be set - clear it to use the socket again\r
-    // - remote_address: IP name (stlplus.sourceforge.net) or dotted number (216.34.181.96)\r
-    // - returns the IP address as a long integer - zero if there's an error\r
-    // unsigned long ip_lookup(const std::string& remote_address);\r
-    using IP_socket::ip_lookup;\r
-\r
-    // Initialise socket.\r
-    // Receive datagram packets from any address on provided local receiving port.\r
-    // - local_port: port number to receive on - 0 to get an ephemeral port.\r
-    // - returns a success flag\r
-    bool initialise(unsigned short local_port);\r
-\r
-    // test whether this is an initialised socket\r
-    // - returns whether this is initialised\r
-    // bool initialised(void) const;\r
-    using IP_socket::initialised;\r
-\r
-    // close, i.e. disconnect the socket\r
-    // - returns a success flag\r
-    // bool close(void);\r
-    using IP_socket::close;\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-    // sending/receiving\r
-\r
-    // test whether a socket is connected and ready to send data, returns if ready or on timeout\r
-    // - timeout: how long to wait in microseconds if not connected yet (blocking)\r
-    // - returns status\r
-    // bool send_ready(unsigned timeout = 0);\r
-    using IP_socket::send_ready;\r
-\r
-    // send to the address/port given here, from the local port setup in initialise.\r
-    // send data through the socket as a single datagram\r
-    // - packet: string containing data to be sent - if data is successfully sent it is removed\r
-    // - remote_address: IP name (stlplus.sourceforge.net) or dotted number (216.34.181.96)\r
-    // - remote_port: port number of remote host\r
-    // - returns success flag\r
-    bool send(std::string& packet, const std::string& remote_address, unsigned short remote_port);\r
-\r
-    // send to the address/port given here, from the local port setup in initialise.\r
-    // send data through the socket as a single datagram\r
-    // - packet: string containing data to be sent - if data is successfully sent it is removed\r
-    // - remote_address: pre-looked-up IP address of remote host\r
-    // - remote_port: port number of remote host\r
-    // - returns success flag\r
-    bool send(std::string& packet, unsigned long remote_address, unsigned short remote_port);\r
-\r
-    // test whether a socket is connected and ready to receive data, returns if ready or on timeout\r
-    // - timeout: how long to wait in microseconds if not connected yet (blocking)\r
-    // - returns status\r
-    // bool receive_ready(unsigned timeout = 0);\r
-    using IP_socket::receive_ready;\r
-\r
-    // datagram receive\r
-    // - packet: string to receive data from datagram - if data is successfully sent it is appended\r
-    // - remote_address: the address of the client that sent the packet, can then be used to reply\r
-    // - remote_port: the port of the client that sent the packet, can then be used to reply\r
-    // - returns success flag - i.e. packet successfully received\r
-    bool receive(std::string& packet, unsigned long& remote_address, unsigned short& remote_port);\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-    // informational\r
-\r
-    // the local port number of the connection\r
-    // returns the port number, 0 if not bound to a port\r
-    // unsigned short local_port(void) const;\r
-    using IP_socket::local_port;\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-    // error handling\r
-    // errors are set internally\r
-    // an error code of 0 is the test for no error, don't rely on the message being an empty string\r
-    // an error code != 0 means an error, then there will be a message explaining the error\r
-\r
-    // if an error is set it stays set - so you must clear it before further operations\r
-    // void clear_error(void);\r
-    using IP_socket::clear_error;\r
-\r
-    // get the error code of the last error\r
-    // int error(void) const;\r
-    using IP_socket::error;\r
-\r
-    // get the explanatory message of the last error\r
-    // std::string message(void) const;\r
-    using IP_socket::message;\r
-\r
-    ////////////////////////////////////////////////////////////////////////////\r
-  };\r
-\r
-  /////////////////////////////////////////////////////////////////////////////\r
-  // fire and forget UDP client packet send function\r
-\r
-  bool UDP_send(const std::string& packet,\r
-                const std::string& remote_address, unsigned short remote_port, unsigned short local_port = 0);\r
-\r
-  ////////////////////////////////////////////////////////////////////////////////\r
-\r
-} // end namespace stlplus\r
-\r
-#endif\r
+#ifndef STLPLUS_UDP_SOCKET
+#define STLPLUS_UDP_SOCKET
+////////////////////////////////////////////////////////////////////////////////
+
+// Author:    Andy Rushton
+// Copyright: (c) Southampton University 1999-2004
+//            (c) Andy Rushton           2004-2009
+// License:   BSD License, see ../docs/license.html
+
+// A platform-independent (Unix and Windows anyway) interface to UDP sockets
+
+////////////////////////////////////////////////////////////////////////////////
+
+#include "portability_fixes.hpp"
+#include "ip_sockets.hpp"
+#include <string>
+
+namespace stlplus
+{
+
+  //////////////////////////////////////////////////////////////////////////////
+  // UDP client - creates a connectioned socket
+
+  class UDP_client : protected IP_socket
+  {
+  public:
+
+    // create an uninitialised socket
+    UDP_client(void);
+
+    // Send/Receive datagram packets to/from the given address/remote port on the local port.
+    // - remote_address: IP name or number of remote host
+    // - remote_port: port number of remote host
+    // - local_port: port number to receive on - 0 to get an ephemeral port.
+    UDP_client(const std::string& remote_address, unsigned short remote_port, unsigned short local_port=0);
+
+    // Send/Receive datagram packets to/from the given address/remote port on the given local port
+    // Enables default send to remote address/port
+    // - remote_address: IP address of remote host - pre-looked-up using ip_lookup
+    // - remote_port: port number of remote host
+    // - local_port: port number to receive on - 0 to get an ephemeral port.
+    UDP_client(unsigned long remote_address, unsigned short remote_port, unsigned short local_port=0);
+
+    ////////////////////////////////////////////////////////////////////////////
+    // initialisation, connection
+
+    // function for performing IP lookup (i.e. gethostbyname)
+    // could be standalone but making it a member means that it can use the socket's error handler
+    // i.e. if this fails, the sockets error code will be set - clear it to use the socket again
+    // - remote_address: IP name (stlplus.sourceforge.net) or dotted number (216.34.181.96)
+    // - returns the IP address as a long integer - zero if there's an error
+    // unsigned long ip_lookup(const std::string& remote_address);
+    using IP_socket::ip_lookup;
+
+    // Send/Receive datagram packets to/from the given address/remote port on the local port.
+    // Enables default send to remote address/port
+    // - remote_address: IP name or number of remote host
+    // - remote_port: port number of remote host
+    // - local_port: port number to receive on - 0 to get an ephemeral port.
+    // - returns a success flag
+    bool initialise(const std::string& remote_address, unsigned short remote_port, unsigned short local_port=0);
+
+    // Send/Receive datagram packets to/from the given address/remote port on the given local port
+    // Enables default send to remote address/port
+    // - remote_address: IP address of remote host - pre-looked-up using ip_lookup
+    // - remote_port: port number of remote host
+    // - local_port: port number to receive on - 0 to get an ephemeral port.
+    // - returns a success flag
+    bool initialise(unsigned long remote_address, unsigned short remote_port, unsigned short local_port=0);
+
+    // test whether this is an initialised socket
+    // - returns whether this is initialised
+    // bool initialised(void) const;
+    using IP_socket::initialised;
+
+    // close, i.e. disconnect the socket
+    // - returns a success flag
+    // bool close(void);
+    using IP_socket::close;
+
+    ////////////////////////////////////////////////////////////////////////////
+    // sending/receiving
+
+    // test whether a socket is connected and ready to send data, returns if ready or on timeout
+    // - timeout: how long to wait in microseconds if not connected yet (blocking)
+    // - returns status
+    // bool send_ready(unsigned timeout = 0);
+    using IP_socket::send_ready;
+
+    // send to the remote address/port setup in initialise, from the local port also setup in initialise.
+    // send data through the socket as a single datagram
+    // - packet: string containing data to be sent - if data is successfully sent it is removed
+    // - returns success flag
+    bool send(std::string& packet);
+
+    // test whether a socket is connected and ready to receive data, returns if ready or on timeout
+    // - timeout: how long to wait in microseconds if not connected yet (blocking)
+    // - returns status
+    // bool receive_ready(unsigned timeout = 0);
+    using IP_socket::receive_ready;
+
+    // datagram receive
+    // - packet: string to receive data from datagram - if data is successfully sent it is appended
+    // - returns success flag - i.e. packet successfully received
+    bool receive(std::string& packet);
+
+    ////////////////////////////////////////////////////////////////////////////
+    // informational
+
+    // the local port number of the connection
+    // returns the port number, 0 if not bound to a port
+    // unsigned short local_port(void) const;
+    using IP_socket::local_port;
+
+    // the remote address of the connection
+    // returns the address, 0 if ANY address
+    // unsigned long remote_address(void) const;
+    using IP_socket::remote_address;
+
+    // the remote port number of the connection
+    // returns the port number, 0 if not bound to a port
+    // unsigned short remote_port(void) const;
+    using IP_socket::remote_port;
+
+    ////////////////////////////////////////////////////////////////////////////
+    // error handling
+    // errors are set internally
+    // an error code of 0 is the test for no error, don't rely on the message being an empty string
+    // an error code != 0 means an error, then there will be a message explaining the error
+
+    // if an error is set it stays set - so you must clear it before further operations
+    // void clear_error (void);
+    using IP_socket::clear_error ;
+
+    // get the error code of the last error
+    // int error(void) const;
+    using IP_socket::error;
+
+    // get the explanatory message of the last error
+    // std::string message(void) const;
+    using IP_socket::message;
+
+    ////////////////////////////////////////////////////////////////////////////
+
+  private:
+    IP_socket m_socket;
+  };
+
+  ////////////////////////////////////////////////////////////////////////////////
+  // UDP server - creates a connectionless (multicast) listener socket
+
+  class UDP_server : protected IP_socket
+  {
+  public:
+
+    // create an uninitialised socket
+    UDP_server(void);
+
+    // Initialise socket.
+    // Receive datagram packets from any address on provided local receiving port.
+    // - local_port: port number to receive on - 0 to get an ephemeral port.
+    UDP_server(unsigned short local_port);
+
+    ////////////////////////////////////////////////////////////////////////////
+    // initialisation, connection
+
+    // function for performing IP lookup (i.e. gethostbyname)
+    // could be standalone but making it a member means that it can use the socket's error handler
+    // i.e. if this fails, the sockets error code will be set - clear it to use the socket again
+    // - remote_address: IP name (stlplus.sourceforge.net) or dotted number (216.34.181.96)
+    // - returns the IP address as a long integer - zero if there's an error
+    // unsigned long ip_lookup(const std::string& remote_address);
+    using IP_socket::ip_lookup;
+
+    // Initialise socket.
+    // Receive datagram packets from any address on provided local receiving port.
+    // - local_port: port number to receive on - 0 to get an ephemeral port.
+    // - returns a success flag
+    bool initialise(unsigned short local_port);
+
+    // test whether this is an initialised socket
+    // - returns whether this is initialised
+    // bool initialised(void) const;
+    using IP_socket::initialised;
+
+    // close, i.e. disconnect the socket
+    // - returns a success flag
+    // bool close(void);
+    using IP_socket::close;
+
+    ////////////////////////////////////////////////////////////////////////////
+    // sending/receiving
+
+    // test whether a socket is connected and ready to send data, returns if ready or on timeout
+    // - timeout: how long to wait in microseconds if not connected yet (blocking)
+    // - returns status
+    // bool send_ready(unsigned timeout = 0);
+    using IP_socket::send_ready;
+
+    // send to the address/port given here, from the local port setup in initialise.
+    // send data through the socket as a single datagram
+    // - packet: string containing data to be sent - if data is successfully sent it is removed
+    // - remote_address: IP name (stlplus.sourceforge.net) or dotted number (216.34.181.96)
+    // - remote_port: port number of remote host
+    // - returns success flag
+    bool send(std::string& packet, const std::string& remote_address, unsigned short remote_port);
+
+    // send to the address/port given here, from the local port setup in initialise.
+    // send data through the socket as a single datagram
+    // - packet: string containing data to be sent - if data is successfully sent it is removed
+    // - remote_address: pre-looked-up IP address of remote host
+    // - remote_port: port number of remote host
+    // - returns success flag
+    bool send(std::string& packet, unsigned long remote_address, unsigned short remote_port);
+
+    // test whether a socket is connected and ready to receive data, returns if ready or on timeout
+    // - timeout: how long to wait in microseconds if not connected yet (blocking)
+    // - returns status
+    // bool receive_ready(unsigned timeout = 0);
+    using IP_socket::receive_ready;
+
+    // datagram receive
+    // - packet: string to receive data from datagram - if data is successfully sent it is appended
+    // - remote_address: the address of the client that sent the packet, can then be used to reply
+    // - remote_port: the port of the client that sent the packet, can then be used to reply
+    // - returns success flag - i.e. packet successfully received
+    bool receive(std::string& packet, unsigned long& remote_address, unsigned short& remote_port);
+
+    ////////////////////////////////////////////////////////////////////////////
+    // informational
+
+    // the local port number of the connection
+    // returns the port number, 0 if not bound to a port
+    // unsigned short local_port(void) const;
+    using IP_socket::local_port;
+
+    ////////////////////////////////////////////////////////////////////////////
+    // error handling
+    // errors are set internally
+    // an error code of 0 is the test for no error, don't rely on the message being an empty string
+    // an error code != 0 means an error, then there will be a message explaining the error
+
+    // if an error is set it stays set - so you must clear it before further operations
+    // void clear_error(void);
+    using IP_socket::clear_error;
+
+    // get the error code of the last error
+    // int error(void) const;
+    using IP_socket::error;
+
+    // get the explanatory message of the last error
+    // std::string message(void) const;
+    using IP_socket::message;
+
+    ////////////////////////////////////////////////////////////////////////////
+  };
+
+  /////////////////////////////////////////////////////////////////////////////
+  // fire and forget UDP client packet send function
+
+  bool UDP_send(const std::string& packet,
+                const std::string& remote_address, unsigned short remote_port, unsigned short local_port = 0);
+
+  ////////////////////////////////////////////////////////////////////////////////
+
+} // end namespace stlplus
+
+#endif
This page took 0.043381 seconds and 4 git commands to generate.