Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
90 lines (86 loc) · 3.34 KB

File metadata and controls

90 lines (86 loc) · 3.34 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/******************************************************************************/
/*! @addtogroup bfd service on c++ boost
@file bfdd_conn.hpp
@brief udp server - connection
******************************************************************************/
#ifndef PROJECT_BFDD_CONN_HPP
#define PROJECT_BFDD_CONN_HPP
#include "bfdd_cpp.h"
class Conn {
friend class Server;
friend class BfdSessionManager;
public:
virtual ~Conn(){
if (client_side_sock_ != NULL){
client_side_sock_->close();
delete client_side_sock_;
}
client_side_sock_ = NULL;
}
public:
//
BAIP::udp::endpoint& udpendp(void){ return(udpendp_); }
BAIP::udp::endpoint& udpendp_remote(void){ return(udpendp_remote_); }
char* rbuf(void){ return(readbuf_); }
size_t rsiz(void){ return(sizeof(readbuf_)); }
//
int write(void* bf, size_t size){
if (size <= sizeof(writebuf_)){
memcpy(writebuf_, bf, size);
sock_ref_->async_send_to(
boost::asio::buffer(writebuf_,size), udpendp_,
boost::bind(&Conn::handle_write, this, boost::asio::placeholders::error));
return(RET_OK);
}
fprintf(stderr, "write failed.(%zu : %lu)\n", size, sizeof(writebuf_));
return(RET_WARN);
}
void setudpendp_remote(BAIP::udp::endpoint udpendp){
udpendp_remote_ = udpendp;
}
private:
Conn(boost::asio::io_service& ios, BAIP::udp::socket* sock):
client_side_sock_(NULL),
sock_ref_(sock),
ioservice_(&ios){
memset(writebuf_,0,sizeof(writebuf_));
memset(readbuf_,0,sizeof(readbuf_));
}
Conn(){}
void handle_write(const boost::system::error_code& err){}
void handle_read(BAIP::udp::endpoint& endp, const boost::system::error_code& err, size_t size) { }
//
static Conn* create_server_side_connection(boost::asio::io_service& ios, BAIP::udp::socket* sock){
Conn* pcon = new Conn(ios, sock);
if (pcon){
pcon->sock_ref_ = sock;
}
return(pcon);
}
static Conn* create_client_side_connection(boost::asio::io_service& ios, BAIP::udp::endpoint& endp_l, BAIP::udp::endpoint& endp_r){
Conn* pcon = new Conn(ios, NULL);
if (pcon){
pcon->client_side_sock_ = new BAIP::udp::socket(ios);
if (pcon->client_side_sock_){
pcon->client_side_sock_->open(endp_l.protocol());
pcon->client_side_sock_->set_option(boost::asio::ip::udp::socket::send_buffer_size(SOCKET_SENDBUFFER_SIZE));
pcon->client_side_sock_->set_option(boost::asio::ip::udp::socket::reuse_address(true));
pcon->client_side_sock_->set_option(boost::asio::ip::unicast::hops(BFD_1HOPTTLVALUE));
pcon->client_side_sock_->bind(endp_l);
pcon->sock_ref_ = pcon->client_side_sock_;
pcon->udpendp_ = endp_r;
}
}
return(pcon);
}
private:
//
BAIP::udp::socket *client_side_sock_;
BAIP::udp::socket *sock_ref_;
boost::asio::io_service *ioservice_;
BAIP::udp::endpoint udpendp_;
BAIP::udp::endpoint udpendp_remote_;
char readbuf_[CONNECTION_BUFFER_SIZE];
char writebuf_[CONNECTION_BUFFER_SIZE];
}; // class Conn
#endif //PROJECT_BFDD_CONN_HPP
Morty Proxy This is a proxified and sanitized view of the page, visit original site.