blob: 313a87ae81da3771d149b12d5a043c4db40f9e34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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__*/
|