From f83b395168155d0421dbc093a37bd075dc51ed53 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 1 Aug 2012 20:30:37 +0200 Subject: Added socket class and made simple test app using fork. --- src/socket.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/socket.h (limited to 'src/socket.h') 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 +#include + +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__*/ -- cgit v1.2.3