• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Sockets.hpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 #ifndef GOSU_SOCKETS_HPP
00005 #define GOSU_SOCKETS_HPP
00006 
00007 #include <boost/cstdint.hpp>
00008 #include <boost/function.hpp>
00009 #include <boost/scoped_ptr.hpp>
00010 #include <cstddef>
00011 #include <string>
00012 
00013 namespace Gosu
00014 {
00016     typedef boost::uint32_t SocketAddress;
00017 
00019     typedef boost::uint16_t SocketPort;
00020     
00023     const SocketPort anyPort = 0;
00024     
00029     SocketAddress stringToAddress(const std::string& s);
00031     std::string addressToString(SocketAddress address);
00032 
00037     class MessageSocket
00038     {
00039         struct Impl;
00040         boost::scoped_ptr<Impl> pimpl;
00041 
00042     public:
00046         explicit MessageSocket(SocketPort port);
00047         ~MessageSocket();
00048 
00050         SocketAddress address() const;
00052         SocketPort port() const;
00055         std::size_t maxMessageSize() const;
00056 
00059         void update();
00060 
00063         void send(SocketAddress address, SocketPort port,
00064             const void* buffer, std::size_t size);
00065         /*void broadcast(SocketPort port, const void* buffer,
00066             std::size_t size);*/
00067 
00069         boost::function<void (SocketAddress, SocketPort, const void*,
00070             std::size_t)> onReceive;
00071     };
00072     
00075     enum CommMode
00076     {
00077         cmRaw,
00078         //cmLines,
00079         cmManaged
00080     };
00081     
00082     class Socket;
00083     
00086     class CommSocket
00087     {
00088         struct Impl;
00089         boost::scoped_ptr<Impl> pimpl;
00090 
00091     public:
00092         CommSocket(CommMode mode, SocketAddress targetAddress,
00093             SocketPort targetPort);
00094         CommSocket(CommMode mode, Socket& socket);
00095         ~CommSocket();
00096 
00097         SocketAddress address() const;
00098         SocketPort port() const;
00099         SocketAddress remoteAddress() const;
00100         SocketPort remotePort() const;
00101         CommMode mode() const;
00102 
00103         bool connected() const;
00104         void disconnect();
00105         bool keepAlive() const;
00106         void setKeepAlive(bool value);
00107 
00108         void update();
00109         void send(const void* buffer, std::size_t size);
00110         void sendPendingData();
00111         std::size_t pendingBytes() const;
00112 
00113         boost::function<void (const void*, std::size_t)> onReceive;
00114         boost::function<void ()> onDisconnection;
00115     };
00116     
00119     class ListenerSocket
00120     {
00121         struct Impl;
00122         boost::scoped_ptr<Impl> pimpl;
00123 
00124     public:
00125         ListenerSocket(SocketPort port);
00126         ~ListenerSocket();
00127 
00128         SocketAddress address() const;
00129         SocketPort port() const;
00130 
00131         void update();
00132 
00135         boost::function<void (Socket&)> onConnection;
00136     };
00137 }
00138 
00139 #endif

Documentation not clear enough? Please go to one of the places listed on http://www.libgosu.org/ and leave feedback. Thanks!