forked from solidoss/solidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaiosocket.hpp
More file actions
95 lines (77 loc) · 2 KB
/
Copy pathaiosocket.hpp
File metadata and controls
95 lines (77 loc) · 2 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// solid/frame/aio/aiosocket.hpp
//
// Copyright (c) 2015 Valentin Palade (vipalade @ gmail . com)
//
// This file is part of SolidFrame framework.
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.
//
#ifndef SOLID_FRAME_AIO_SOCKET_HPP
#define SOLID_FRAME_AIO_SOCKET_HPP
#include "solid/frame/aio/aiocommon.hpp"
#include "solid/system/socketdevice.hpp"
#include <cerrno>
namespace solid{
namespace frame{
namespace aio{
class Socket{
public:
Socket(SocketDevice &&_rsd):sd(std::move(_rsd)){
if(sd.ok()){
sd.makeNonBlocking();
}
}
Socket(){
}
SocketDevice reset(SocketDevice &&_rsd){
SocketDevice tmpsd = std::move(sd);
sd = std::move(_rsd);
return tmpsd;
}
void shutdown(){
if(sd.ok()){
sd.shutdownReadWrite();
}
}
bool create(SocketAddressStub const &_rsas, ErrorCodeT &_rerr){
_rerr = sd.create(_rsas.family());
if(!_rerr){
_rerr = sd.makeNonBlocking();
}
return !_rerr;
}
bool connect(SocketAddressStub const &_rsas, bool &_can_retry, ErrorCodeT &_rerr){
_rerr = sd.connect(_rsas, _can_retry);
return !_rerr;
}
ReactorEventsE filterReactorEvents(
const ReactorEventsE _evt
) const {
return _evt;
}
int recv(char *_pb, size_t _bl, bool &_can_retry, ErrorCodeT &_rerr){
return sd.recv(_pb, _bl, _can_retry, _rerr);
}
int send(const char *_pb, size_t _bl, bool &_can_retry, ErrorCodeT &_rerr){
return sd.send(_pb, _bl, _can_retry, _rerr);
}
SocketDevice const& device()const{
return sd;
}
SocketDevice& device(){
return sd;
}
int recvFrom(char *_pb, size_t _bl, SocketAddress &_addr, bool &_can_retry, ErrorCodeT &_rerr){
return sd.recv(_pb, _bl, _addr, _can_retry, _rerr);
}
int sendTo(const char *_pb, size_t _bl, SocketAddressStub const &_rsas, bool &_can_retry, ErrorCodeT &_rerr){
return sd.send(_pb, _bl, _rsas, _can_retry, _rerr);
}
private:
SocketDevice sd;
};
}//namespace aio
}//namespace frame
}//namespace solid
#endif