summaryrefslogtreecommitdiff
path: root/server/src/tcpsocket.h
diff options
context:
space:
mode:
authordeva <deva>2007-09-03 09:11:33 +0000
committerdeva <deva>2007-09-03 09:11:33 +0000
commita34402b79b38624a29ed8ea4e059af817266e6b8 (patch)
tree4df1d9a5756e37c304ddd8b58ed3e12c4a3894c1 /server/src/tcpsocket.h
parent27bc1afc3aa6e0b4465946aa870573499b85ae5d (diff)
Implemented the first version of the XML request. Fixed eXpat incompatability with XML_Get/SetUserData and the void* in the handler functions.
Diffstat (limited to 'server/src/tcpsocket.h')
-rw-r--r--server/src/tcpsocket.h253
1 files changed, 125 insertions, 128 deletions
diff --git a/server/src/tcpsocket.h b/server/src/tcpsocket.h
index f392a2c..45d94ee 100644
--- a/server/src/tcpsocket.h
+++ b/server/src/tcpsocket.h
@@ -31,153 +31,150 @@
#include "exception.h"
-namespace Pentominos {
-
- /**
- * This exception is thrown by TCPSocket when the socket creation fails.
- */
- class TCPSocketException: public Pentominos::Exception {
- public:
- TCPSocketException(std::string reason) :
- Pentominos::Exception("Could not create socket: " + reason) {}
- };
+/**
+ * This exception is thrown by TCPSocket when the socket creation fails.
+ */
+class TCPSocketException: public Exception {
+public:
+ TCPSocketException(std::string reason) :
+ Exception("Could not create socket: " + reason) {}
+};
- /**
- * This exception is thrown by TCPSocket when listen fails.
- */
- class TCPListenException: public Pentominos::Exception {
- public:
- TCPListenException(std::string reason) :
- Pentominos::Exception("Listen failed: " + reason) {}
- };
+/**
+ * This exception is thrown by TCPSocket when listen fails.
+ */
+class TCPListenException: public Exception {
+public:
+ TCPListenException(std::string reason) :
+ Exception("Listen failed: " + reason) {}
+};
- /**
- * This exception is thrown by TCPSocket when accept fails.
- */
- class TCPAcceptException: public Pentominos::Exception {
- public:
- TCPAcceptException(std::string reason) :
- Pentominos::Exception("Accept failed: " + reason) {}
- };
+/**
+ * This exception is thrown by TCPSocket when accept fails.
+ */
+class TCPAcceptException: public Exception {
+public:
+ TCPAcceptException(std::string reason) :
+ Exception("Accept failed: " + reason) {}
+};
- /**
- * This exception is thrown by TCPSocket when connection fails.
- */
- class TCPConnectException: public Pentominos::Exception {
- public:
- TCPConnectException(std::string host, std::string port, std::string reason) :
- Pentominos::Exception("Could not connect to " + host + ":" + port + ": " + reason) {}
- };
+/**
+ * This exception is thrown by TCPSocket when connection fails.
+ */
+class TCPConnectException: public Exception {
+public:
+ TCPConnectException(std::string host, std::string port, std::string reason) :
+ Exception("Could not connect to " + host + ":" + port + ": " + reason) {}
+};
- /**
- * This exception is thrown by TCPSocket when reading fails.
- */
- class TCPReadException: public Pentominos::Exception {
- public:
- TCPReadException(std::string reason) :
- Pentominos::Exception("TCPSocket could not read data: " + reason) {}
- };
+/**
+ * This exception is thrown by TCPSocket when reading fails.
+ */
+class TCPReadException: public Exception {
+public:
+ TCPReadException(std::string reason) :
+ Exception("TCPSocket could not read data: " + reason) {}
+};
- /**
- * This exception is thrown by TCPSocket when writing fails.
- */
- class TCPWriteException: public Pentominos::Exception {
- public:
- TCPWriteException(std::string reason) :
- Pentominos::Exception("TCPSocket could not write data: " + reason) {}
- };
+/**
+ * This exception is thrown by TCPSocket when writing fails.
+ */
+class TCPWriteException: public Exception {
+public:
+ TCPWriteException(std::string reason) :
+ Exception("TCPSocket could not write data: " + reason) {}
+};
+/**
+ * This exception is thrown by TCPSocket when there is an error in name lookup.
+ */
+class TCPNameException: public Exception {
+public:
+ TCPNameException(std::string reason) :
+ Exception("TCPSocket could not get name: " + reason) {}
+};
+
+/**
+ * This class is used to commumicate through a TCP/IP connection, wether it
+ * is a server (listening) or a client (transmitting).
+ */
+class TCPSocket {
+public:
/**
- * This exception is thrown by TCPSocket when there is an error in name lookup.
+ * Constructor. Creates a new tcp socket.
*/
- class TCPNameException: public Pentominos::Exception {
- public:
- TCPNameException(std::string reason) :
- Pentominos::Exception("TCPSocket could not get name: " + reason) {}
- };
+ TCPSocket() throw(TCPSocketException);
/**
- * This class is used to commumicate through a TCP/IP connection, wether it
- * is a server (listening) or a client (transmitting).
+ * Destructor. Closes the tcp socket.
*/
- class TCPSocket {
- public:
- /**
- * Constructor. Creates a new tcp socket.
- */
- TCPSocket() throw(TCPSocketException);
-
- /**
- * Destructor. Closes the tcp socket.
- */
- ~TCPSocket();
+ ~TCPSocket();
- /**
- * Sets the socket in listen mode.\n
- * @param port The port number on which to listen.
- */
- void listen(unsigned short int port) throw(TCPListenException);
+ /**
+ * Sets the socket in listen mode.\n
+ * @param port The port number on which to listen.
+ */
+ void listen(unsigned short int port) throw(TCPListenException);
- /**
- * Accept an incoming connection.\n
- * The call is blocking and returns only when an incoming connection is received.\n
- * The socket must be in listen mode in order for this call to work.\n
- * Multiple accepts can be made on the same listening socket.
- * @return A connected TCPSocket ready to communicate.
- */
- TCPSocket accept() throw(TCPAcceptException);
+ /**
+ * Accept an incoming connection.\n
+ * The call is blocking and returns only when an incoming connection is received.\n
+ * The socket must be in listen mode in order for this call to work.\n
+ * Multiple accepts can be made on the same listening socket.
+ * @return A connected TCPSocket ready to communicate.
+ */
+ TCPSocket accept() throw(TCPAcceptException);
- /**
- * Connects to a host for data transmission.
- * @param addr The address of the host to connect to.
- * @param port The portnumber of the host to connect to.
- */
- void connect(std::string addr, unsigned short int port) throw(TCPConnectException);
+ /**
+ * Connects to a host for data transmission.
+ * @param addr The address of the host to connect to.
+ * @param port The portnumber of the host to connect to.
+ */
+ void connect(std::string addr, unsigned short int port) throw(TCPConnectException);
- /**
- * Disconnect the socket.
- */
- void disconnect();
+ /**
+ * Disconnect the socket.
+ */
+ void disconnect();
- /**
- * Tells whether the socket is connected or not.
- * @return true if the socket is connected, false if not.
- */
- bool connected();
+ /**
+ * Tells whether the socket is connected or not.
+ * @return true if the socket is connected, false if not.
+ */
+ bool connected();
- /**
- * Reads bytes from the socket into a buffer.
- * @param buf The buffer into which the data will be written.
- * @param size The maximum number of bytes to read in (the size of the buffer).
- * @return The actual number of bytes read.
- */
- int read(char *buf, int size) throw(TCPReadException);
+ /**
+ * Reads bytes from the socket into a buffer.
+ * @param buf The buffer into which the data will be written.
+ * @param size The maximum number of bytes to read in (the size of the buffer).
+ * @return The actual number of bytes read.
+ */
+ int read(char *buf, int size) throw(TCPReadException);
- /**
- * Writes bytes from a buffer to the socket.
- * @param data The buffer from which the data will be read.
- * @param size The number of bytes to write.
- * @return The actual number of bytes written.
- */
- int write(char *data, int size) throw(TCPWriteException);
+ /**
+ * Writes bytes from a buffer to the socket.
+ * @param data The buffer from which the data will be read.
+ * @param size The number of bytes to write.
+ * @return The actual number of bytes written.
+ */
+ int write(char *data, int size) throw(TCPWriteException);
- /**
- * Get the source address of the socket (IP address not DNS name).
- * @return An STL string containing the source address.
- */
- std::string srcaddr() throw(TCPNameException);
-
- /**
- * Get the destination address of the socket (IP address not DNS name).
- * @return An STL string containing the destination address.
- */
- std::string dstaddr() throw(TCPNameException);
-
- private:
- bool isconnected;
- int sock;
- };
-
+ /**
+ * Get the source address of the socket (IP address not DNS name).
+ * @return An STL string containing the source address.
+ */
+ std::string srcaddr() throw(TCPNameException);
+
+ /**
+ * Get the destination address of the socket (IP address not DNS name).
+ * @return An STL string containing the destination address.
+ */
+ std::string dstaddr() throw(TCPNameException);
+
+private:
+ bool isconnected;
+ int sock;
};
+
#endif/*__ARTEFACT_TCPSOCKET_H__*/