summaryrefslogtreecommitdiff
path: root/src/socket.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/socket.h')
-rw-r--r--src/socket.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/socket.h b/src/socket.h
new file mode 100644
index 0000000..313a87a
--- /dev/null
+++ b/src/socket.h
@@ -0,0 +1,62 @@
+/* -*- mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * File: socket.h
+ * This file belongs to the Bifrost project.
+ * Socket wrapper class header file.
+ * Date: Wed Sep 2 09:02:38 CEST 2009
+ * Author: Bent Bisballe Nyeng
+ * Copyright: 2009
+ * Email: deva@aasimon.org
+ ****************************************************************************/
+#ifndef __BIFROST_SOCKET_H__
+#define __BIFROST_SOCKET_H__
+
+#include <string>
+#include <exception>
+
+typedef unsigned short int port_t;
+
+#ifdef WIN32
+typedef SOCKET socket_t;
+#define _throw(...)
+#else
+typedef int socket_t;
+#define _throw(fmt...) throw(fmt)
+#endif
+
+struct socket_private_t;
+
+class Socket {
+public:
+ class BindException : public std::exception {};
+ class MulticastTTLException : public std::exception {};
+ class MulticastGroupJoinException : public std::exception {};
+ class ReceiveException : public std::exception {};
+ class SendException : public std::exception {};
+ class WSAException : public std::exception {};
+ class AddressParseException : public std::exception {};
+ class OpenException : public std::exception {};
+
+ Socket() _throw(WSAException);
+ ~Socket();
+
+ void open(std::string address, port_t port)
+ _throw(AddressParseException, OpenException);
+
+ void setSocketFiledescriptor(socket_t sock, std::string address, port_t port)
+ _throw(AddressParseException);
+
+ void setSend(unsigned char ttl)
+ _throw(MulticastTTLException, MulticastGroupJoinException);
+ void setRecv() _throw(BindException);
+
+ virtual size_t sendTo(void *data, size_t size)
+ _throw(SendException);
+ virtual size_t recvFrom(void *data, size_t size)
+ _throw(ReceiveException);
+
+private:
+ struct socket_private_t *prv;
+};
+
+#endif/*__BIFROST_SOCKET_H__*/