Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

socket.h

Go to the documentation of this file.
00001 
00002 #ifndef header_socket
00003 #define header_socket
00004 
00006 
00007 #include "../signals.h"
00008 #include "ip_address.h"
00009 
00010 class CL_EventTrigger;
00011 
00012 class CL_Socket
00013 //: This is the lowlevel raw socket interface in clanlib.
00014 // Its main purpose is to write the C sockets API, providing error handling 
00015 // via exceptions, and socket waiting (select) via the clanlib event waiting 
00016 // system (CL_EventListener, CL_EventTrigger).
00017 {
00018 public:
00019         enum Type
00020         {
00021                 tcp,
00022                 udp
00023         };
00024 
00025         enum ShutdownHow
00026         {
00027                 shutdown_receive,
00028                 shutdown_send
00029         };
00030 
00032 public:
00033         CL_Socket(int socket);
00035         // Constructs an attached socket.
00036 
00037         CL_Socket(Type type);
00039         // Constructs a new socket using the specified protocol type.
00040 
00041         CL_Socket(const CL_Socket &copy);
00043         // Copy constructor.
00044 
00045         virtual ~CL_Socket();
00046 
00048 public:
00049         int get_socket() const;
00051         // Returns the raw socket handle (for use with the lowlevel socket functions).
00052 
00053         CL_EventTrigger *get_read_trigger() const;
00055         // Returns an event trigger that triggers when socket has data ready to be read.
00056 
00057         CL_EventTrigger *get_write_trigger() const;
00059         // Returns an event trigger that triggers when socket is ready for additional data.
00060 
00061         CL_EventTrigger *get_exception_trigger() const;
00063         // Returns an event trigger that triggers when an exception occours on the socket.
00064 
00065         CL_IPAddress get_source_address() const;
00067         // Returns the socket name.
00068 
00069         CL_IPAddress get_dest_address() const;
00071         // Returns the name of the destination socket we are connected to.
00072 
00073         CL_Signal_v0 &sig_read_triggered();
00075         // This signal is invoked when the socket has data ready to be read.
00076 
00077         CL_Signal_v0 &sig_write_triggered();
00079         // This signal is invoked when the socket has data ready to be written.
00080 
00081         CL_Signal_v0 &sig_exception_triggered();
00083         // This signal is invoked when an exception occoured on the socket.
00084 
00086 public:
00087         void set_nonblocking(bool nonblocking = true);
00089         // Sets the socket blocking mode.
00090 
00091         void set_nodelay(bool nodelay = true);
00093         // If enabled, don't delay send to coalesce packets.
00094 
00095         int send(const void *data, int size);
00097         // Writes data to socket. Returns the amount that was written.
00098 
00099         int send(const void *data, int size, const CL_IPAddress &dest);
00101         // Writes data to socket, using the specified destination host.
00102 
00103         int recv(void *data, int size);
00105         // Reads data from the socket. Returns the amount that was read.
00106 
00107         int recv(void *data, int size, CL_IPAddress &from);
00109         // Reads data from the socket, storing the from address in the passed parameter.
00110 
00111         void connect(const CL_IPAddress &address);
00113         // Initiate a connection on the socket.
00114 
00115         void shutdown(ShutdownHow how);
00117         // Shut down part of full-duplex connection.
00118 
00119         void bind(const CL_IPAddress &address);
00121         // Bind the socket to the specified address.
00122 
00123         void listen(int backlog);
00125         // Listen for connections on the socket.
00126 
00127         CL_Socket accept();
00129         // Accept a connection on the socket.
00130 
00132 public:
00133         CL_Socket(class CL_Socket_Generic *impl);
00134         class CL_Socket_Generic *impl;
00135 };
00136 
00137 #endif

Generated at Wed Apr 4 19:54:03 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001