-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path15.cpp
46 lines (38 loc) · 1 KB
/
15.cpp
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
#include <iostream>
#include <string>
#include <memory>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::make_shared;
using std::shared_ptr;
struct destination{
string ip;
int port;
destination(string ip_, int port_):ip(ip_), port(port_){};
};
struct connection{
string ip;
int port;
connection(string ip_, int port_):ip(ip_), port(port_){};
};
connection connect(destination *dest){
shared_ptr<connection> pConn(new connection(dest->ip, dest->port));
cout << "creating connection( " << pConn.use_count() << ")" << endl;
return *pConn;
}
// void disconnect(connection pConn){
// cout << "connection close " << pConn.ip << " : " << pConn.port << endl;
// }
// void end_connection(connection *pConn){
// disconnect(*pConn);
// }
void f(destination &d){
connection c = connect(&d);
shared_ptr<connection> p(&c, [](connection *pConn){cout << "connection close " << pConn->ip << " : " << pConn->port << endl;});
}
int main(){
destination dest("202.118.175.12", 8808);
f(dest);
}